Ruby 从服务器上的CSV复制到PostgreSQL数据库
我正在尝试使用下载到服务器的CSV文件更新PostgreSQL数据库。我已经尝试了好几个小时,它在本地运行得很好,但无法在服务器上运行。这是我的命令:Ruby 从服务器上的CSV复制到PostgreSQL数据库,ruby,database,postgresql,csv,engineyard,Ruby,Database,Postgresql,Csv,Engineyard,我正在尝试使用下载到服务器的CSV文件更新PostgreSQL数据库。我已经尝试了好几个小时,它在本地运行得很好,但无法在服务器上运行。这是我的命令: path = "/data/reporting/releases/20150202181737/data/storyboards.csv" sql = "COPY storyboards (id, name, category, service_line, account_id, account_name, account_salesforce
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客户机及其
\copy
命令来实现这一点(如果您愿意,可以完全在Ruby之外,也可以从Ruby内部剥离)。因为它是在本地文件系统之外运行的,所以只要您可以访问本地文件路径,就不会有任何问题
如错误所示,要在服务器上复制CSV,您必须是超级用户
基于,postgres用户似乎被配置为Engineyard中的超级用户,因此如果您使用该用户,就可以了
这需要与Rails中的普通应用程序连接分开,因为这可能不是使用postgres用户,而是使用为应用程序创建的任何用户(因为出于各种原因,应用程序通常不应以超级用户权限运行)
除非这是某种自动工作流程的一部分,必须是服务器端的,否则我建议您只使用带有\copy
的框中的psql