我正尝试像往常一样在我的本地机器上运行 postgresql,但这让我陷入了无法修复的境地。我用 macports 安装了 postgresql91。
这些是我通常必须运行的三个命令才能让它运行:
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"
但是,今天它给了我这个错误:
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
当我转到 /opt/local/var/db/postgresql91/
并执行 ls -l
时,结果如下:
drwx------ 18 root wheel 612 Jun 28 12:44 defaultdb
所以我决定将postgres用户添加到wheel组,然后chmod defaultdb为770。
drwxrwx--- 18 root wheel 612 Jun 28 12:44 defaultdb
我仍然得到错误:
FATAL: could not open configuration file "/opt/local/var/db/postgresql91/defaultdb/postgresql.conf": Permission denied
因此我更改了文件权限:
-rw------- 1 root wheel 19170 Jan 7 11:52 postgresql.conf
到:
-rw-rw---- 1 root wheel 19170 Jan 7 11:52 postgresql.conf
现在它提示说当我再次运行命令时:
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.
考虑到文件的文件权限,我不知道我过去是如何运行 postgres 服务器的。我在哪里可以找到它提示我的 data
文件夹?有没有更好的方法来解决这个问题?
最佳答案
Postgres 应该是所有者,并且是唯一能够写入数据目录的用户。
那么,做:
sudo chown -Rf postgres:postgres /opt/local/var/db/postgresql91/defaultdb
sudo chmod 700 /opt/local/var/db/postgresql91/defaultdb
应该没问题。
关于PostgreSQL:权限被拒绝+拥有错误的所有权循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17457693/