使用\i命令从文件读取时拒绝postgreSQL权限 [英] postgreSQL permission denied when reading from file with \i command

查看:710
本文介绍了使用\i命令从文件读取时拒绝postgreSQL权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:


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


即使文件在桌面上,我也有此问题。
,当我复制create.sql的文本并将其粘贴到那里时可以正常工作。

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.

使用UBUNTU 12.10,postgresql 9.1

using UBUNTU 12.10, postgresql 9.1

谢谢您的帮助。

推荐答案

问题是您已经以用户身份启动 psql postgres ,并且您尚未授予 postgres 用户读取SQL文件的权限。您需要授予它权限。最简单的方法是授予世界读取权限:

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:

chmod a+r create.sql

您可以通过更改 umask 来更改分配给文件的默认权限;搜索更多信息。某些程序非常讨厌地忽略 umask 并设置限制性文件权限,因此您始终需要知道如何授予权限。参见 man chmod man chown

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.

BTW,您正在使用非常复杂的方法以 postgres 用户身份启动 psql 。这样就可以了:

BTW, you're using a very convoluted method for launching psql as the postgres user. This'll do just fine:

sudo -u postgres psql template1






请注意, /create.sql 指定一个名为文件系统根目录( / )中的 create.sql 。我怀疑这是您的意图。


Note that /create.sql specifies a file named create.sql in root of the file system (/). I doubt this is what you intended.

您可能希望将其指定为相对路径(没有前导 / ),如果它位于您的主目录中,例如:

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

或者如果它在桌面上并且您已经在您的计算机中启动了 psql 主目录:

or if it's on the desktop and you've started psql in your home directory:

template1=# \i Desktop/create.sql

这篇关于使用\i命令从文件读取时拒绝postgreSQL权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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