gpt4 book ai didi

ruby - 从服务器上的 CSV 复制到 PostgreSQL 数据库

转载 作者:搜寻专家 更新时间:2023-10-30 23:46:06 27 4
gpt4 key购买 nike

我正在尝试使用下载到服务器的 CSV 文件更新 PostgreSQL 数据库。我已经尝试了很多小时,它在本地完美运行,但无法在服务器上运行。这是我的命令:

path = "/data/reporting/releases/20150202181737/data/storyboards.csv"

sql = "COPY storyboards (id, name, category, service_line, account_id, account_name, account_salesforce_id, banner_image) FROM \'#{path}\' DELIMITER ',' CSV;"

ActiveRecord::Base.connection.execute(sql)

这是错误信息:

COPY storyboards (id, name, category, service_line, account_id, account_name, account_salesforce_id, banner_image) FROM '/data/reporting/releases/20150202181737/data/storyboards.csv' DELIMITER ',' CSV;
PG::InsufficientPrivilege: ERROR: must be superuser to COPY to or from a file
HINT: Anyone can COPY to stdout or from stdin. psql's \copy command also works for anyone.
: COPY storyboards (id, name, category, service_line, account_id, account_name, account_salesforce_id, banner_image) FROM '/data/reporting/releases/20150202181737/data/storyboards.csv' DELIMITER ',' CSV;
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: must be superuser to COPY to or from a file
HINT: Anyone can COPY to stdout or from stdin. psql's \copy command also works for anyone.
: COPY storyboards (id, name, category, service_line, account_id, account_name, account_salesforce_id, banner_image) FROM '/data/reporting/releases/20150202181737/data/storyboards.csv' DELIMITER ',' CSV;

您能否针对此问题推荐一个解决方案,因为我确信我不是唯一尝试这样做的人。我在 Engineyard 上托管我的应用程序。这是 Engineyard 配置问题吗?

最佳答案

如果您想将数据从客户端的 CSV 复制到服务器,那么应​​该没有问题。您可以使用 psql 客户端及其 \复制命令。由于它在本地文件系统之外运行,因此只要您可以访问本地文件路径,就不会有任何问题。

如错误所示,要在服务器上复制 CSV,您必须是 super 用户

基于 this answer ,看起来 postgres 用户在 Engineyard 中被配置为一个 super 用户,所以如果你使用那个用户,你应该没问题。

这将需要一个与您在 Rails 中的正常应用程序连接不同的连接,因为这可能不会使用 postgres 用户,而是您为您的应用程序创建的任何用户(因为出于各种原因,您的应用通常不应以 super 用户权限运行)。

除非这是某种必须在服务器端运行的自动化工作流的一部分,否则我建议您使用\copy 中的psql

关于ruby - 从服务器上的 CSV 复制到 PostgreSQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28287505/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com