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

查看:62
本文介绍了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.

您可以通过以root身份运行来确认这是否是问题:

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

setenforce 0

然后重新测试.运行:

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天全站免登陆