psql错误:无法打开文件"address.csv";阅读:没有这样的文件或目录 [英] psql ERROR: could not open file "address.csv" for reading: No such file or directory

查看:257
本文介绍了psql错误:无法打开文件"address.csv";阅读:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux的新手.

我正在尝试将.csv复制到PostgreSQL数据库中,

I am trying to copy a .csv into a PostgreSQL database,

copy address from 'address.csv' delimiter ',' csv header;

我使用cd到psql提示符下的\ cd [目录]命令来cd到文件的位置.操作失败.

I have cd to location of file, using the \cd [directory] command at the psql prompt. An unsuccessful action.

我已经关闭了该终端窗口,并在另一个终端窗口cd中关闭了数据文件夹,然后从那里打开了psql命令.

I have closed that terminal window and in another terminal window cd to the data folder and from there there I have opened the psql command.

\! pwd显示文件存储文件夹的名称/路径. /home/tommy/virtualenv_folder/code_data/postgresql_csv_files

\! pwd displays the name/path of folder where the file is stored. /home/tommy/virtualenv_folder/code_data/postgresql_csv_files

\! ls会显示文件名,即使使用通配符\! add*也会显示文件名.

\! ls displays the file name, even using the wildcard \! add* displays the file name.

stackoverflow.com/questions/16618299/postgres-copy-from-csv-file-no-such-file-or-directory 建议重设 search_path .肯定没有必要在数据文件夹中.是吗?

stackoverflow.com/questions/16618299/postgres-copy-from-csv-file-no-such-file-or-directory suggests to reset the search_path. Being in the data folder surely this is not necessary. Or is it?

无论如何,任何指针都将不胜感激.

Anyway, any pointers would be appreciated, please.

推荐答案

您应在copy语句中使用实际路径,例如

You should use the actual path in the copy statement, eg,

copy address from '/home/tommy/virtualenv_folder/code_data/postgresql_csv_files/address.csv'. 

还请确保postgres用户具有对该文件和目录的读取访问权限,或将所有权更改为postgres,即chown postgres:postgres address.csv.我倾向于创建一个目录并授予所有用户对该目录的读/写访问权限,因此我可以轻松地将数据加载到postgres中,然后以我本人或postgres用户的身份再次将其转出,例如

Also make sure that the postgres user has read access to that file and directory or change the ownership to postgres, ie, chown postgres:postgres address.csv. I tend to create a directory and give all users read/write access to it, so I can easily load data into postgres and dump it back out again, either as myself or as a postgres user, eg,

chmod a+rw /var/import/postgresfiles

search_path与通过数据库内部而不是外部文件系统中的架构进行Postgres搜索有关.

The search_path relates to postgres searching through schemas within the database not in the external filesystem.

这篇关于psql错误:无法打开文件"address.csv";阅读:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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