使用 \i 命令从文件读取时拒绝 postgreSQL 权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13682739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
postgreSQL permission denied when reading from file with \i command
提问by Euler's formula
this is my problem:
这是我的问题:
myname@ubuntu:~$ sudo su postgres -c "psql template1" Password: psql (9.1.6) Type "help" for help. template1=# \i /create.sql /create.sql: Permission denied
myname@ubuntu:~$ sudo su postgres -c "psql template1" Password: psql (9.1.6) Type "help" for help. template1=# \i /create.sql /create.sql: Permission denied
I have this problem even when the file is on the Desktop. when I copy the text of create.sql and paste it there it works.
即使文件在桌面上,我也有这个问题。当我复制 create.sql 的文本并将其粘贴到那里时,它可以工作。
using UBUNTU 12.10, postgresql 9.1
使用 UBUNTU 12.10,postgresql 9.1
Thank you for the help.
感谢您的帮助。
回答by Craig Ringer
The problem is that you've launched psql
as the user postgres
and you haven't granted the postgres
user permission to read the SQL file. You'll need to give it permission. The simplest way is to grant world read rights:
问题是您已经psql
以用户身份启动,postgres
并且您还没有授予postgres
用户读取 SQL 文件的权限。你需要给它许可。最简单的方法是授予全局读取权限:
chmod a+r create.sql
You can change the default permissions assigned to files by altering your umask
; search for more information. Some programs rather annoyingly ignore the umask
and set restrictive file permissions anyway, so you always need to know how to grant permissions. See man chmod
and man chown
.
您可以通过更改您的umask
;来更改分配给文件的默认权限。搜索更多信息。一些程序相当烦人地忽略umask
并设置限制性文件权限,因此您总是需要知道如何授予权限。见man chmod
和man chown
。
BTW, you're using a very convoluted method for launching psql
as the postgres
user. This'll do just fine:
顺便说一句,您正在使用一种非常复杂的方法psql
作为postgres
用户启动。这会做得很好:
sudo -u postgres psql template1
Note that /create.sql
specifies a file named create.sql
in root of the file system (/
). I doubt this is what you intended.
请注意,/create.sql
指定以create.sql
文件系统 ( /
) 的根目录命名的文件。我怀疑这就是你的意图。
You probably want to specify it as a relative path (without the leading /
) if it's in your home directory, like:
/
如果它在您的主目录中,您可能希望将其指定为相对路径(没有前导),例如:
template1=# \i create.sql
or if it's on the desktop and you've started psql
in your home directory:
或者如果它在桌面上并且您已经psql
在您的主目录中启动:
template1=# \i Desktop/create.sql