2015-11-27 75 views
3

的Postgres 9.2在CentOS 7postmaster.pid权限被拒绝的CentOS 7

后 “苏 - Postgres的” 我用

PG-CTL在initdb -D在/ var/lib中/ pgsql的/数据

运行良好。

[[email protected] ~]# systemctl start postgresql 
Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details. 
[[email protected] ~]# systemctl status postgresql.service 
postgresql.service - PostgreSQL database server 
    Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled) 
    Active: failed (Result: exit-code) since Fri 2015-11-27 13:48:57 EST; 9s ago 
    Process: 3262 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE) 
    Process: 3256 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) 

Nov 27 13:48:57 server.company.network systemd[1]: Starting PostgreSQL database server... 
Nov 27 13:48:57 server.company.network pg_ctl[3262]: pg_ctl: could not open PID file "/var/lib/pgsql/data/postmaster.pid": Permission denied 
Nov 27 13:48:57 server.company.network systemd[1]: postgresql.service: control process exited, code=exited status=1 
Nov 27 13:48:57 server.company.network systemd[1]: Failed to start PostgreSQL database server. 
Nov 27 13:48:57 server.company.network systemd[1]: Unit postgresql.service entered failed state. 
[[email protected] ~]# journalctl -xn 
-- Logs begin at Fri 2015-11-27 13:29:37 EST, end at Fri 2015-11-27 13:48:57 EST. -- 
Nov 27 13:48:35 server.company.network sudo[3228]: pam_unix(sudo:auth): conversation failed 
Nov 27 13:48:35 server.company.network sudo[3228]: pam_unix(sudo:auth): auth could not identify password for [myuserid] 
Nov 27 13:48:46 server.company.network sudo[3230]: myuserid : TTY=pts/0 ; PWD=/home/myuserid ; USER=root ; COMMAND=/bin/su - 
Nov 27 13:48:46 server.company.network su[3234]: (to root) myuserid on pts/0 
Nov 27 13:48:46 server.company.network su[3234]: pam_unix(su-l:session): session opened for user root by myuserid(uid=0) 
Nov 27 13:48:57 server.company.network systemd[1]: Starting PostgreSQL database server... 
-- Subject: Unit postgresql.service has begun with start-up 
-- Defined-By: systemd 
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel 
-- 
-- Unit postgresql.service has begun starting up. 
Nov 27 13:48:57 server.company.network pg_ctl[3262]: pg_ctl: could not open PID file "/var/lib/pgsql/data/postmaster.pid": Permission denied 
Nov 27 13:48:57 server.company.network systemd[1]: postgresql.service: control process exited, code=exited status=1 
Nov 27 13:48:57 server.company.network systemd[1]: Failed to start PostgreSQL database server. 
-- Subject: Unit postgresql.service has failed 
-- Defined-By: systemd 
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel 
-- 
-- Unit postgresql.service has failed. 
-- 
-- The result is failed. 
Nov 27 13:48:57 server.company.network systemd[1]: Unit postgresql.service entered failed state. 

当我 “苏 - Postgres的” 我能 “碰” 的文件, “LS” 的文件, “RM” /var/lib/pgsql/data/postmaster.pid。数据权限为700个postgres:postgres。 pgsql是/ data0/postgres的一个符号链接,postgres是700个postgres:postgres。

ADDITIONS:

我忘了提及,有这个问题后,我取代为ExecStartPre和ExecStart的命令与写的用户,主组,PGDATA和PGPORT值到一个文件壳脚本。他们都是正确的。开始仍然在postmaster.pid上死亡。

的postgresql.service文件:

[[email protected] /]# cat /usr/lib/systemd/system/postgresql.service 
# It's not recommended to modify this file in-place, because it will be 
# overwritten during package upgrades. If you want to customize, the 
# best way is to create a file "/etc/systemd/system/postgresql.service", 
# containing 
#  .include /lib/systemd/system/postgresql.service 
#  ...make your changes here... 
# For more info about custom unit files, see 
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F 

# For example, if you want to change the server's port number to 5433, 
# create a file named "/etc/systemd/system/postgresql.service" containing: 
#  .include /lib/systemd/system/postgresql.service 
#  [Service] 
#  Environment=PGPORT=5433 
# This will override the setting appearing below. 

# Note: changing PGPORT or PGDATA will typically require adjusting SELinux 
# configuration as well; see /usr/share/doc/postgresql-*/README.rpm-dist. 

# Note: do not use a PGDATA pathname containing spaces, or you will 
# break postgresql-setup. 

# Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line 
# though /lib/... will still work. 

[Unit] 
Description=PostgreSQL database server 
After=network.target 

[Service] 
Type=forking 

User=postgres 
Group=postgres 

# Port number for server to listen on 
Environment=PGPORT=5432 

# Location of database directory 
Environment=PGDATA=/var/lib/pgsql/data 

# Where to send early-startup messages from the server (before the logging 
# options of postgresql.conf take effect) 
# This is normally controlled by the global default set by systemd 
# StandardOutput=syslog 

# Disable OOM kill on the postmaster 
OOMScoreAdjust=-1000 

ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} 
ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 
ExecStop=/usr/bin/pg_ctl stop -D ${PGDATA} -s -m fast 
ExecReload=/usr/bin/pg_ctl reload -D ${PGDATA} -s 

# Give a reasonable amount of time for the server to start up/shut down 
TimeoutSec=300 

[Install] 
WantedBy=multi-user.target 
+0

显示'postgresql.service'单元文件 –

+0

我忘了提及,在遇到这个问题后,我用用户,主组,PGDATA和PGPORT值写入文件的shell脚本替换了ExecStartPre和ExecStart的命令。他们都是正确的。开始仍然在postmaster.pid上死亡。 – Ludwig61

+0

尝试在'[service]'部分添加'PIDFile =/other/location/postmaster.pid'确保Yu可以完全访问'/ other/location /'目录 –

回答

3

我想通了。运行initdb后,我将数据目录复制到另一个驱动器。通过SELinux,FILETYPE切换到目标父目录FILETYPE。我试图semanage的目录,但这是行不通的。所以我重新开始并移动了数据目录,而保留了FILETYPE。