Postgresql 转储权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8835835/
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 dump permission denied
提问by Feanor
I get this error while trying to dump database, i entered
尝试转储数据库时出现此错误,我输入了
linuxuser $ sudo su postgres
linuxuser $ [sudo] password for linuxuser:...
$ pg_dump -h localhost mydb >tempfile
$ sh: cannot create tempfile: Permission denied
What the problem? i've just installed fresh postgresql.
什么问题?我刚刚安装了新的 postgresql。
回答by Michael Krelin - hacker
Write into directory where postgres user has write access. For instance /tmp
.
写入 postgres 用户具有写入权限的目录。例如/tmp
。
$ pg_dump -h localhost mydb >/tmp/tempfile
In your attempt postgres user tries to create a file in some random directory belonging to the other user.
在您的尝试中,postgres 用户尝试在属于其他用户的某个随机目录中创建一个文件。
回答by Daniel Vérité
sudo su postgres doesn't change the current directory so you're still in linuxuser's home directory and postgres has no permission to write into it. Change to a different directory
sudo su postgres 不会更改当前目录,因此您仍在 linuxuser 的主目录中,并且 postgres 没有写入权限。切换到其他目录
回答by shoshinsha
backup and restore can be done by any unpriviledged user that knows the postgres superuser password by changing permissions on the working directory:
任何知道 postgres 超级用户密码的非特权用户都可以通过更改工作目录的权限来完成备份和恢复:
% mkdir backup
% chmod 0777 backup
% su postgres
[enter password]
$ cd backup
$ pg_dump mydb >tempfile
$ exit
"tempfile" will be owned by postgres and same group as the user
“tempfile”将由 postgres 拥有,并且与用户属于同一组
回答by Basil Bourque
postgres
User
postgres
用户
As the other correct answers said, the folder in which you are trying save the backup does not have permissions assigned to the postgres
user (operating system user account). The postgres
user is the one running the backup utility. This user account was created during the Postgres installation process. You may have used a different name, but the default is postgres
.
正如其他正确答案所说,您尝试保存备份的文件夹没有分配给postgres
用户(操作系统用户帐户)的权限。该postgres
用户正在运行的备份工具之一。此用户帐户是在 Postgres 安装过程中创建的。您可能使用了不同的名称,但默认为postgres
.
Folder With Permissions
有权限的文件夹
The solution is to either find or create a folderwhere the postgres
user has read-write permissions.
解决的办法是要么找到或创建一个文件夹,其中postgres
用户读写权限。
Mac OS X
Mac OS X
In Mac OS X (Mountain Lion), I am able to create such a folder in the Finder.
在 Mac OS X (Mountain Lion) 中,我可以在 Finder 中创建这样一个文件夹。
- In the Finder, create a new folder. Select it.
In this example, I created a folder namedpostgres_backups
. - Choose
File
>Get Info
. - Open the disclosure triangle for the
Sharing & Permissions
section. - Click the Plus button to add another item to the list of users.
A list of users appears in a "sheet" dialog. - Select the
postgres
user from the list. - In the
Privilege
column, for the newpostgres
row, change the popup menu toRead & Write
. - Close the
Get Info
window. Done.
- 在 Finder 中,创建一个新文件夹。选择它。
在这个例子中,我创建了一个名为postgres_backups
. - 选择
File
>Get Info
。 - 打开该
Sharing & Permissions
部分的显示三角形。 - 单击加号按钮将另一个项目添加到用户列表中。
用户列表出现在“工作表”对话框中。 postgres
从列表中选择用户。- 在
Privilege
列中,对于新postgres
行,将弹出菜单更改为Read & Write
。 - 关闭
Get Info
窗口。完毕。
Now you can direct your Postgres backup files to that folder.
现在您可以将 Postgres 备份文件定向到该文件夹。
By the way, I use the pgAdmin app to do backups and restores. Control+click on the desired database and choose Backups…
. The pgAdmin app was probably bundled with your Postgres installation.
顺便说一下,我使用 pgAdmin 应用程序进行备份和恢复。Control+单击所需的数据库并选择Backups…
。pgAdmin 应用程序可能与您的 Postgres 安装捆绑在一起。
回答by john igneel
first thing you have to do is do not switch to user postgres. The use this command for backup:
您必须做的第一件事是不要切换到用户 postgres。使用此命令进行备份:
pg_dump -U username -h localhost dbname > /db.sql
回答by ewhite5
I wrestled with this "Permission Denied" issue while trying to backup my PSQL database on an Ubuntu machine for a long time, and tried user access rights, superuser status, folder properties--lots of stuff. Finally, something worked that was ridiculously simple. In the command:
我在尝试在 Ubuntu 机器上备份我的 PSQL 数据库很长时间时遇到了这个“权限被拒绝”问题,并尝试了用户访问权限、超级用户状态、文件夹属性——很多东西。最后,一些工作起来非常简单。在命令中:
pg_dump -U username -O dbname > 'filename.sql'
Make sure you have quotes (single or double quotes seem to work) around the filename which follows the greater than (">") sign. The examples above do not have quotes around the filename. Once I tried that, I no longer received Permission Denied errors.
确保在大于 (">") 符号之后的文件名周围有引号(单引号或双引号似乎有效)。上面的示例在文件名周围没有引号。一旦我尝试过,我就不再收到 Permission Denied 错误。