postgresql 由于锁定文件的权限被拒绝,无法启动 Postgres 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33942967/
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
Unable to start Postgres Server because of permission denied on lock file
提问by Sarthak Saxena
I restarted my Postgres server but now. I checked my "pgstartup.log" log file. This says:
我重新启动了我的 Postgres 服务器,但现在。我检查了我的“pgstartup.log”日志文件。这说:
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
Success. You can now start the database server using:
/usr/bin/postgres -D /var/lib/pgsql/data
/usr/bin/pg_ctl -D /var/lib/pgsql/data -l logfile start
FATAL: could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
FATAL: could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
Do you think deleting /tmp/.s.PGSQL.5432.lock
would work ?
你认为删除/tmp/.s.PGSQL.5432.lock
会起作用吗?
回答by mnencia
PostgreSQL normally deletes the lock file when terminates correctly.
PostgreSQL 通常在正确终止时删除锁定文件。
It is probably due to another PostgreSQL instance running with a different user that has been terminated abnormally (a kill -9 to postmaster).
这可能是由于另一个 PostgreSQL 实例与已异常终止的不同用户一起运行(一个 kill -9 到 postmaster)。
So, if you are sure no Postgres processes are running, you can probably delete that file without any issue. You should also check with the ipcs
command if there is any stale shared memory segment, and in that case delete it with ipcrm
.
因此,如果您确定没有 Postgres 进程正在运行,您可以毫无问题地删除该文件。您还应该使用该ipcs
命令检查是否有任何陈旧的共享内存段,在这种情况下,使用ipcrm
.
Probably the be best way to address all these things at once is rebooting the server.
一次解决所有这些问题的最好方法可能是重新启动服务器。
P.S.: never kill -9
any PostgreSQL process.
PS:从来没有kill -9
任何 PostgreSQL 进程。
回答by Luca Perico
Postgres cannot write a file to /tmp because of permissions set on /tmp directory. As root user execute in terminal:
由于在 /tmp 目录上设置了权限,Postgres 无法将文件写入 /tmp。作为 root 用户在终端中执行:
chmod 1777 /tmp
回答by Craig Ringer
It looks like you probably have another PostgreSQL instance running on the same port as a different user, or you previously started this PostgreSQL instance as a different user then stopped it uncleanly.
看起来您可能有另一个 PostgreSQL 实例以不同的用户身份在同一端口上运行,或者您之前以不同的用户身份启动了这个 PostgreSQL 实例,然后不正常地停止了它。
Check the ownership of /tmp/.s.PGSQL.5432.lock
:
检查所有权/tmp/.s.PGSQL.5432.lock
:
ls -l /tmp/.s.PGSQL.5432.lock
Does it match the user you're running PostgreSQL as?
它与您运行 PostgreSQL 的用户匹配吗?
It's relatively harmless to delete the lock files in /tmp/
. (Never, everdelete the postmaster.pid
lock file though). If the other PostgreSQL instance is still running you'll lose the ability to connect to it over a unix socket, or you might get an error about being unable to bind to port 5432 on tcp.
删除 .lock 中的锁定文件相对无害/tmp/
。(但是,永远不要删除postmaster.pid
锁定文件)。如果另一个 PostgreSQL 实例仍在运行,您将无法通过 unix 套接字连接到它,或者您可能会收到关于无法绑定到 tcp 上的端口 5432 的错误。
I agree with @mnencia that a server reboot is the best option if it's easy and practical.
我同意@mnencia 的观点,即如果简单实用,服务器重启是最好的选择。
回答by Sarthak Saxena
Thanks for the suggestions. First I tried changing the permission of the lock file but it didn't work Later I deleted the lock file which resolved my issue.
感谢您的建议。首先,我尝试更改锁定文件的权限,但它不起作用后来我删除了解决我问题的锁定文件。
Thanks
谢谢