PostgreSQL数据文件权限不对导致开机启动失败

时光毁灭记忆、已成空白 提交于 2019-12-02 22:53:43
上午开发告知机子重启后DB连接不了了,登进去一开,确实,进程啥的都没有起来。


手工启动:
[postgres@develop ~]$ pg_start
server starting
[postgres@develop ~]$ps -ef|grep postgres

发现还是没起来,查看日志,里面有如此报错信息:

[postgres@develop ~]$ tail -f pg_log
FATAL:  data directory "/home/postgres/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/home/postgres/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/home/postgres/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.
FATAL:  data directory "/home/postgres/data" has group or world access
DETAIL:  Permissions should be u=rwx (0700).

信息给得很详细,postgresql的数据文件权限被改了,起码现在不是0700(只有用户权限)。返回去一看, 现在果然是777权限了。而且用户的所属也被改了,改成其他用户了。
[postgres@develop ~]$ ll /home/postgres
drwxrwxrwx 14 tomcat ddd     4096 10-29 09:41 data

改回去:
[postgres@develop ~]$chown -R postgres:postgres  /home/postgres/data
[postgres@develop ~]$chmod 0700 /home/postgres/data

查看:
drwx------ 14 postgres postgres     4096 10-29 09:41 data


再启动
[postgres@develop ~]$ pg_start
server starting

正常了。后来了解到是开发的一个误操作,改其他文件的权限的时候把DB文件的用户组权限也改了  

总结:
默认情况下,PostgreSQL启动时,启动DB用户必须拥有数据文件的所属权限(user权限),且权限不能过大,否则就会报上述错误。其实这是一个安全的保护措施,防止DB文件因为权限开设太大而被其他非允许的用户访问。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!