PostgreSQL COPY命令给出权限被拒绝错误 [英] Postgresql COPY command giving Permissions denied error

查看:4211
本文介绍了PostgreSQL COPY命令给出权限被拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 COPY 文件插入PostgreSQL中的表。表所有者是 postgres ,文件所有者是 postgres

I am trying to COPY a file into a table in PostgreSQL. The table owner is postgres and the file owner is postgres.

档案位于 / tmp

仍然收到错误讯息:


无法打开文件/ tmp / file进行阅读:权限被拒绝

could not open file "/tmp/file" for reading: Permission denied

我不明白我做错了,因为我发现的所有帖子说,如果我有 / tmp 中的文件,并且所有者是 postgres ,那么 COPY 命令应该工作。

I don't understand what I am doing wrong as all the posts I've found say that if I have the file in /tmp and owner is postgres then the COPY command should work.

推荐答案

猜测:您使用的是Fedora,Red Hat Enterprise Linux,CentOS,Scientific Linux或其他发行版默认情况下启用 SELinux

A guess: You are using Fedora, Red Hat Enterprise Linux, CentOS, Scientific Linux, or one of the other distros that enable SELinux by default.

在您的特定操作系统/版本上,PostgreSQL的SELinux策略不允许服务器读取PostgreSQL数据目录之外的文件,或者文件是由服务涵盖的目标政策,所以它有一个标签,PostgreSQL不允许从中读取。

Either and on your particular OS/version the SELinux policies for PostgreSQL do not permit the server to read files outside the PostgreSQL data directory, or the file was created by a service covered by a targeted policy so it has a label that PostgreSQL isn't allowed to read from.

您可以确认这是否是运行的问题,作为根:

You can confirm whether or not this is the problem by running, as root:

setenforce 0


b $ b

然后重新测试。执行:

then re-testing. Run:

setenforce 1

在测试后重新启用SELinux。 setenforce 不是永久性的; SELinux将在重新启动时自动重新启用。永久禁用SELinux通常不是解决这类问题的好办法;如果您确认问题是SELinux,它可以进一步探索。

to re-enable SELinux after testing. setenforce isn't permanent; SELinux will be automatically re-enabled on reboot anyway. Disabling SELinux permanently is not usually a good solution for issues like this; if you confirm the issue is SELinux it can be explored further.

由于您没有指定操作系统或版本使用,PostgreSQL版本,您运行的确切命令, ls -al 上的文件, \d + 在桌子上,等等,很难给任何更多的细节,或知道这是否是一个猜测。尝试更新您的答案以包括所有的和 ls --lcontext 的文件。

Since you have not specified the OS or version you are using, the PostgreSQL version, the exact command you're running, ls -al on the file, \d+ on the table, etc, it's hard to give any more detail, or to know if this is more than a guess. Try updating your answer to include all that and an ls --lcontext of the file too.

这篇关于PostgreSQL COPY命令给出权限被拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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