1

我正在尝试使用要下载到服务器的 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配置问题吗?

4

1 回答 1

1

如果您想将数据从客户端的CSV复制到服务器,那么应​​该没有问题。您可以使用psql客户端及其命令来执行此操作(如果您愿意,可以完全在Ruby之外,或者您可以从Ruby中退出)。由于它使用本地文件系统运行,因此只要您可以访问本地文件路径,您就不会遇到任何问题。\copy

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

根据这个答案,似乎postgres用户被配置为Engineyard中的超级用户,所以如果你使用那个用户,你应该没问题。

这需要与Rails中的普通应用程序连接建立单独的连接,因为这可能不会使用postgres用户,而是您为应用程序创建的任何用户(因为由于各种原因,您的应用程序通常不应以超级用户权限运行) .

除非这是某种必须是服务器端的自动化工作流程的一部分,否则建议您只使用您的盒子中的psql\copy和.

于 2015-02-02T23:07:27.487 回答