PostgreSQL:权限被拒绝 + 拥有错误的所有权循环?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17457693/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:59:45  来源:igfitidea点击:

PostgreSQL: Permission denied + has wrong ownership loop?

postgresql

提问by bigpotato

I'm trying to run postgresql on my local machine like I usually do, however it's putting me in a situation where I can't fix. I installed postgresql91 with macports.

我试图像往常一样在我的本地机器上运行 postgresql,但是这让我处于无法修复的境地。我用 macports 安装了 postgresql91。

These are the three commands I usually have to run to get it running:

这些是我通常必须运行的三个命令才能使其运行:

    sudo sysctl -w kern.sysv.shmall=4096
    sudo sysctl -w kern.sysv.shmmax=16777216
    sudo su postgres -c "/opt/local/lib/postgresql91/bin/postgres -D /opt/local/var/db/postgresql91/defaultdb -p 55432"

However, it's giving me this error today:

但是,它今天给了我这个错误:

    Nets-Mac-Pro:~ emai$ sudo sysctl -w kern.sysv.shmall=4096
    Password:
    kern.sysv.shmall: 4096 -> 4096
    Nets-Mac-Pro:~ emai$ sudo sysctl -w kern.sysv.shmmax=16777216
    kern.sysv.shmmax: 16777216 -> 16777216
    Nets-Mac-Pro:~ emai$ sudo su postgres -c "/opt/local/lib/postgresql91/bin/postgres -D /opt/local/var/db/postgresql91/defaultdb -p 55432"
    postgres cannot access the server configuration file "/opt/local/var/db/postgresql91/defaultdb/postgresql.conf": Permission denied

When I go to /opt/local/var/db/postgresql91/and do an ls -lthis is what comes up:

当我/opt/local/var/db/postgresql91/去做一个ls -l事情时,会出现这样的情况:

drwx------  18 root  wheel  612 Jun 28 12:44 defaultdb

So I decided to add the postgres user to the wheel group, and then chmod defaultdb to 770.

所以我决定将postgres用户加入wheel组,然后chmod defaultdb为770。

drwxrwx---  18 root  wheel  612 Jun 28 12:44 defaultdb

I still get the error:

我仍然收到错误:

FATAL:  could not open configuration file "/opt/local/var/db/postgresql91/defaultdb/postgresql.conf": Permission denied

And so I change the file rights from:

所以我改变了文件权限:

-rw-------   1 root  wheel  19170 Jan  7 11:52 postgresql.conf

to:

到:

-rw-rw----   1 root  wheel  19170 Jan  7 11:52 postgresql.conf

And now it complains that when I run the command again:

现在它抱怨当我再次运行命令时:

    Nets-Mac-Pro:~ emai$ sudo su postgres -c "/opt/local/lib/postgresql91/bin/postgres -D /opt/local/var/db/postgresql91/defaultdb -p 55432"
    FATAL:  data directory "/opt/local/var/db/postgresql91/defaultdb" has wrong ownership
    HINT:  The server must be started by the user that owns the data directory.

I have no clue how I used to run the postgres server considering the file permissions of the files. Where do I find the datafolder that it is hinting me about? Is there a better way to fix this?

考虑到文件的文件权限,我不知道我过去是如何运行 postgres 服务器的。我在哪里可以找到data它提示我的文件夹?有没有更好的方法来解决这个问题?

回答by

Postgres should be owner, and the only user capable of writing to, data directory.

Postgres 应该是所有者,并且是唯一能够写入数据目录的用户。

So, do:

所以,做:

sudo chown -Rf postgres:postgres /opt/local/var/db/postgresql91/defaultdb
sudo chmod 700 /opt/local/var/db/postgresql91/defaultdb

and it should be fine.

应该没问题。