无法在CentOS 7上启动postgresql服务。

33

在CentOS 7上无法启动postgresql-9.5。

我按照这个页面 - https://wiki.postgresql.org/wiki/YUM_Installation - 安装了CentOS上的数据库服务器。

我尝试了在运行setenforce 0之后再次安装,但是依旧无法解决问题。

我使用root进行所有操作。

systemctl start postgresql-9.5.service
Job for postgresql-9.5.service failed because the control process exited with error 
code. See "systemctl status postgresql-9.5.service" and "journalctl -xe" for details.

这是我获取的状态:

Redirecting to /bin/systemctl status  postgresql-9.5.service
● postgresql-9.5.service - PostgreSQL 9.5 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2016-02-18 15:20:30 EST; 2min 28s ago
  Process: 15041 ExecStartPre=/usr/pgsql-9.5/bin/postgresql95-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE)

Feb 18 15:20:30 myserver systemd[1]: Starting PostgreSQL 9.5 database server...
Feb 18 15:20:30 myserver systemd[1]: postgresql-9.5.service: control process exited, code=exited status=1
Feb 18 15:20:30 myserver systemd[1]: Failed to start PostgreSQL 9.5 database server.
Feb 18 15:20:30 myserver systemd[1]: Unit postgresql-9.5.service entered failed state.
Feb 18 15:20:30 myserver systemd[1]: postgresql-9.5.service failed.

不同的配置文件内容如下 -

[root@myserver /]# cat /etc/ld.so.conf.d/postgresql-pgdg-libs.conf
/usr/pgsql-9.5/lib/

[root@myserver /]# cat /usr/lib/tmpfiles.d/postgresql-9.5.conf
d /var/run/postgresql 0755 postgres postgres -

[root@myserver /]# cat /usr/pgsql-9.5/share/postgresql-9.5-libs.conf
/usr/pgsql-9.5/lib/

[root@myserver /]# cat /etc/alternatives/pgsql-ld-conf
/usr/pgsql-9.5/lib/

[root@myserver /]# cat /var/lib/alternatives/pgsql-ld-conf
auto
/etc/ld.so.conf.d/postgresql-pgdg-libs.conf

/usr/pgsql-9.5/share/postgresql-9.5-libs.conf
950

我在谷歌上搜索了出现的错误。 许多人都遇到了同样的错误,而每种原因都不尽相同。阅读这些帖子时,我并没有看到已经报道过的任何一个导致我出现此错误的原因。

3个回答

52

请确保您已正确安装所有软件包,并在安装之前更新了yum存储库部分[base][updates],如指南所述。我们使用CentOS 7和PostgreSQL 9.5,以下步骤可以完美运行:

vi /etc/yum.repos.d/CentOS-Base.repo
yum localinstall http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
yum list postgres*
yum install -y postgresql95-server.x86_64 postgresql95-contrib.x86_64 postgresql95-libs.x86_64 
/usr/pgsql-9.5/bin/postgresql95-setup initdb
systemctl enable postgresql-9.5.service
systemctl start postgresql-9.5.service 

最后,systemctl status postgresql-9.5.service 应该显示类似于以下内容:
postgresql-9.5.service - PostgreSQL 9.5 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-9.5.service; enabled)
   Active: active (running) since Fri 2016-02-19 00:01:13 UTC; 6min ago
  Process: 10809 ExecStart=/usr/pgsql-9.5/bin/pg_ctl start -D ${PGDATA} -s -w -t 300 (code=exited, status=0/SUCCESS)
  Process: 10802 ExecStartPre=/usr/pgsql-9.5/bin/postgresql95-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 10811 (postgres)
   CGroup: /system.slice/postgresql-9.5.service
           ├─10811 /usr/pgsql-9.5/bin/postgres -D /var/lib/pgsql/9.5/data
           ├─10812 postgres: logger process   
           ├─10814 postgres: checkpointer process   
           ├─10815 postgres: writer process   
           ├─10816 postgres: wal writer process   
           ├─10817 postgres: autovacuum launcher process   
           └─10818 postgres: stats collector process 

18
这个神奇的命令是这样的- #/usr/pgsql-9.5/bin/postgresql95-setup initdb。 指南提到了上述命令作为备选项,如果“service <name> initdb”无法运行。然而,如果“service <name> initdb”命令可以正常运行,指南没有提供关于输出是什么样子的指导。在我自己的情况中,我使用了“service <name> initdb”命令,但它只是返回了命令提示符。最终我发现,它并没有起作用。 - Muthu Palanisamy
完美..正是我想要的 - Sabarish
对我来说,这些神奇的命令是-[ /usr/pgsql-9.5/bin/postgresql95-setup initdb] 和 [systemctl enable postgresql-9.5.service]。 - Anurag Singh
在我的情况下,initdb脚本是由非root用户(postgresql用户)执行的。该脚本将在退出之前在$PGDATA文件夹中创建一个名为“pg_log”的文件夹,然后不做任何其他操作。在我删除数据文件夹中的所有内容后,我能够以root身份执行initdb,并且一切正常。(仅从data/中删除将只有在您可以恢复数据或者您的设置相当新时才有意义;)) - Lama

17

最常见的问题是数据库群集未初始化。您可以通过运行带有initdb命令的postgresql-XX-setup脚本轻松初始化它,例如:

最常见的问题是数据库群集未初始化。您可以通过运行带有initdb命令的postgresql-XX-setup脚本轻松初始化它,例如:

sudo /usr/pgsql-11/bin/postgresql-11-setup initdb

然后启动Postgres服务,例如:

sudo systemctl start postgresql-11

-1

这些步骤在我们的测试服务器上对我很有帮助。

通过SSH连接您的服务器。

然后切换用户:

sudo su - postgres

检查Postgres状态:

pg_ctl status

停止数据库:

pg_ctl stop 

检查是否存在服务器进程:

ps axf | grep postg

启动Postgres服务:
sudo systemctl start postgresql.service 

或者

sudo systemctl start postgresql

然后检查状态:

systemctl status postgresql.service ИЛИ systemctl status postgresql

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接