Postgres无法打开CSV文件以进行读取访问:权限被拒绝 [英] Postgres cannot open CSV file for read access: Permission denied

查看:304
本文介绍了Postgres无法打开CSV文件以进行读取访问:权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取位于postgres 8.4服务器文件系统上的CSV文件:

I am trying to read a CSV file located on a postgres 8.4 server filesystem:

COPY ip2location_db1 FROM '/pgsrc/IP2LOCATION-LITE-DB9.CSV' WITH CSV QUOTE AS '"';

我遇到了错误:

Cannot open file for read access: Permission denied

该文件的所有者为postgres,我尝试将其放在/var/lib/pgsql以及/pgsources文件夹中,我将所有权授予了postgres用户.

The file has owner postgres and I tried putting it on /var/lib/pgsql and also on /pgsources folder, to which I gave ownership to postgres user.

我在做什么错了?

推荐答案

我以前曾遇到过这个问题,而不是一直都在争夺权限,我只是从STDIN导入.

I have run into this issue before, and rather than jockey around with permissions all the time, I just import from STDIN.

这可以实现您想要的(尽管不完全是您想要的方式),但是我认为它不那么麻烦和容易出错.试试:

This would accomplish what you want (albeit not precisely the way you want to do it), but I think it's a lot less cumbersome and error-prone. Try:

cat /pgsrc/IP2LOCATION-LITE-DB9.CSV | psql -c "COPY ip2location_db1 FROM STDIN (FORMAT CSV);"

这确实意味着您正在从Shell脚本或其他内容运行查询,但是要以其他方式实现查询,您必须将权限更改与Shell脚本或其他内容合并.

This does imply that you're running the query from a shell script or something, but to implement it the other way, you'd have to incorporate the change of permissions with a shell script or something.

(此外,根据文档,默认quote是双引号,因此您无需指定引号.)

(Also, according to the docs, the default quote is the double quote, so you don't need to specify the quote.)

这篇关于Postgres无法打开CSV文件以进行读取访问:权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆