首页 > 解决方案 > postgresql pg_ctl 启动超时

问题描述

我的系统在 CentOS 7.4 上运行,我们使用 systemd 服务来启动 postgresql 9.2.21 服务器。postgresql 由以下命令启动:

ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA}
ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 -l /tmp/log

pg_ctl 返回的 start 间歇性超时。它因“postgresql.service 启动操作超时”而失败。错误。运行systemctl status postgresql显示如下:

â postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: failed (Result: timeout) since Thu 2020-02-13 15:57:02 PST; 52s ago
  Process: 1098 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 -l /tmp/log (code=killed, signal=TERM)
  Process: 1021 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)

Feb 13 23:52:02 server systemd[1]: Starting PostgreSQL database server...
Feb 13 23:52:03 server pg_ctl[1098]: pg_ctl: another server might be running; trying to start server anyway
Feb 13 15:57:02 server systemd[1]: postgresql.service start operation timed out. Terminating.
Feb 13 15:57:02 server systemd[1]: Failed to start PostgreSQL database server.
Feb 13 15:57:02 server systemd[1]: Unit postgresql.service entered failed state.
Feb 13 15:57:02 server systemd[1]: postgresql.service failed.

pg_ctl 的输出日志:

2020-02-13 23:52:05 UTC LOG:  database system was interrupted; last known up at 2020-02-13 23:49:55 UTC
2020-02-13 23:52:21 UTC LOG:  database system was not properly shut down; automatic recovery in progress
2020-02-13 23:52:21 UTC LOG:  record with zero length at 0/1CEDFD8
2020-02-13 23:52:21 UTC LOG:  redo is not required
2020-02-13 23:52:21 UTC LOG:  database system is ready to accept connections
2020-02-13 23:52:21 UTC LOG:  autovacuum launcher started
2020-02-13 23:57:02 UTC LOG:  received smart shutdown request
2020-02-13 23:57:02 UTC LOG:  autovacuum launcher shutting down
2020-02-13 23:57:02 UTC LOG:  shutting down
2020-02-13 23:57:03 UTC LOG:  database system is shut down

上面的日志显示数据库已成功启动,我实际上可以 sql 到数据库,直到数据库被 pg_ctl 关闭。根据 pg_ctl 手册页,它会反复尝试连接到服务器。我想知道为什么 pg_ctl 无法连接到服务器并退出,但我可以在启动期间手动执行此操作。

谢谢帕特里克

标签: postgresqlcentos7postgresql-9.2

解决方案


推荐阅读