重新启动后,postgresql-12.service无法在CentOS 8上启动

问题描述

我有一个在CentOS 8上运行的Postgresql 12数据库,直到今天一切都很好。

重新启动数据库服务器后,我的postgresql-12.service不再启动,我已经尝试使用systemctl start postgresql-12.service之类的systemctl来获取此信息:

[postgres@perseus ~]$ sudo systemctl start postgresql-12.service
[sudo] password for postgres:
Job for postgresql-12.service Failed because the control process exited with error code.
See "systemctl status postgresql-12.service" and "journalctl -xe" for details.
[postgres@perseus ~]$ sudo systemctl status postgresql-12.service
● postgresql-12.service - Postgresql 12 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)
   Active: Failed (Result: exit-code) since Tue 2020-08-11 08:57:51 -03; 11s ago
     Docs: https://www.postgresql.org/docs/12/static/
  Process: 2822 ExecStart=/usr/pgsql-12/bin/postmaster -D ${PGDATA} (code=exited,status=1/FAILURE)
  Process: 2816 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited,status=0/SUCCESS)
 Main PID: 2822 (code=exited,status=1/FAILURE)

Aug 11 08:57:49 perseus postmaster[2822]: 2020-08-11 08:57:49.040 -03 [2822] LOG:  listening on IPv4 address "0.0.0.0",port 5432
Aug 11 08:57:49 perseus postmaster[2822]: 2020-08-11 08:57:49.040 -03 [2822] LOG:  listening on IPv6 address "::",port 5432
Aug 11 08:57:49 perseus postmaster[2822]: 2020-08-11 08:57:49.041 -03 [2822] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGsql.5432"
Aug 11 08:57:49 perseus postmaster[2822]: 2020-08-11 08:57:49.042 -03 [2822] LOG:  listening on Unix socket "/tmp/.s.PGsql.5432"
Aug 11 08:57:49 perseus postmaster[2822]: 2020-08-11 08:57:49.068 -03 [2822] LOG:  redirecting log output to logging collector process
Aug 11 08:57:49 perseus postmaster[2822]: 2020-08-11 08:57:49.068 -03 [2822] HINT:  Future log output will appear in directory "log".
Aug 11 08:57:51 perseus systemd[1]: postgresql-12.service: Main process exited,code=exited,status=1/FAILURE
Aug 11 08:57:51 perseus systemd[1]: postgresql-12.service: Killing process 2824 (postmaster) with signal SIGKILL.
Aug 11 08:57:51 perseus systemd[1]: postgresql-12.service: Failed with result 'exit-code'.
Aug 11 08:57:51 perseus systemd[1]: Failed to start Postgresql 12 database server.

然后,使用谷歌搜索错误,我尝试了一些解决方法,例如使用pg_ctlinitdb命令,但是它也失败了,像这样:

[postgres@perseus ~]$ /usr/pgsql-12/bin/pg_ctl start -D /var/lib/pgsql/12/data
waiting for server to start....2020-08-11 09:04:44.197 -03 [2897] LOG:  starting Postgresql 12.3 on x86_64-pc-linux-gnu,compiled by gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5),64-bit
2020-08-11 09:04:44.197 -03 [2897] LOG:  listening on IPv4 address "0.0.0.0",port 5432
2020-08-11 09:04:44.197 -03 [2897] LOG:  listening on IPv6 address "::",port 5432
2020-08-11 09:04:44.197 -03 [2897] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGsql.5432"
2020-08-11 09:04:44.198 -03 [2897] LOG:  listening on Unix socket "/tmp/.s.PGsql.5432"
2020-08-11 09:04:44.222 -03 [2897] LOG:  redirecting log output to logging collector process
2020-08-11 09:04:44.222 -03 [2897] HINT:  Future log output will appear in directory "log".
.. stopped waiting
pg_ctl: Could not start server
examine the log output.

[postgres@perseus ~]$ /usr/pgsql-12/bin/initdb -D '/var/lib/pgsql/12/data'
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

initdb: error: directory "/var/lib/pgsql/12/data" exists but is not empty
If you want to create a new database system,either remove or empty
the directory "/var/lib/pgsql/12/data" or run initdb
with an argument other than "/var/lib/pgsql/12/data".

journalctl -xe结果:

    [postgres@perseus ~]$ sudo systemctl start postgresql-12.service
[sudo] password for postgres:
Job for postgresql-12.service Failed because the control process exited with error code.
See "systemctl status postgresql-12.service" and "journalctl -xe" for details.
[postgres@perseus ~]$ sudo journalctl -xe
Aug 11 11:16:49 perseus sudo[3022]: pam_systemd(sudo:session): Cannot create session: Already running in a session or user slice
Aug 11 11:16:49 perseus sudo[3022]: pam_unix(sudo:session): session opened for user root by root(uid=0)
Aug 11 11:16:49 perseus sudo[3022]: pam_unix(sudo:session): session closed for user root
Aug 11 11:20:01 perseus systemd[1]: Starting system activity accounting tool...
-- Subject: Unit sysstat-collect.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit sysstat-collect.service has begun starting up.
Aug 11 11:20:01 perseus systemd[1]: Started system activity accounting tool.
-- Subject: Unit sysstat-collect.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit sysstat-collect.service has finished starting up.
--
-- The start-up result is RESULT.
Aug 11 11:26:10 perseus sudo[3095]: postgres : TTY=pts/0 ; PWD=/var/lib/pgsql ; USER=root ; COMMAND=/bin/journalctl -xe
Aug 11 11:26:10 perseus sudo[3095]: pam_systemd(sudo:session): Cannot create session: Already running in a session or user slice
Aug 11 11:26:10 perseus sudo[3095]: pam_unix(sudo:session): session opened for user root by root(uid=0)
Aug 11 11:26:49 perseus sudo[3095]: pam_unix(sudo:session): session closed for user root
Aug 11 11:26:52 perseus sudo[3107]: postgres : TTY=pts/0 ; PWD=/var/lib/pgsql ; USER=root ; COMMAND=/bin/journalctl -xe
Aug 11 11:26:52 perseus sudo[3107]: pam_systemd(sudo:session): Cannot create session: Already running in a session or user slice
Aug 11 11:26:52 perseus sudo[3107]: pam_unix(sudo:session): session opened for user root by root(uid=0)
Aug 11 11:27:48 perseus sudo[3107]: pam_unix(sudo:session): session closed for user root
Aug 11 11:30:01 perseus systemd[1]: Starting system activity accounting tool...
-- Subject: Unit sysstat-collect.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit sysstat-collect.service has begun starting up.
Aug 11 11:30:01 perseus systemd[1]: Started system activity accounting tool.
-- Subject: Unit sysstat-collect.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit sysstat-collect.service has finished starting up.
--
-- The start-up result is RESULT.
Aug 11 11:34:13 perseus sudo[3167]: postgres : TTY=pts/0 ; PWD=/var/lib/pgsql ; USER=root ; COMMAND=/bin/systemctl start postgresql-12.service
Aug 11 11:34:13 perseus sudo[3167]: pam_systemd(sudo:session): Cannot create session: Already running in a session or user slice
Aug 11 11:34:13 perseus sudo[3167]: pam_unix(sudo:session): session opened for user root by root(uid=0)
Aug 11 11:34:13 perseus systemd[1]: Starting Postgresql 12 database server...
-- Subject: Unit postgresql-12.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit postgresql-12.service has begun starting up.
Aug 11 11:34:13 perseus postmaster[3176]: 2020-08-11 11:34:13.373 -03 [3176] LOG:  starting Postgresql 12.3 on x86_64-pc-linux-gnu,64-bit
Aug 11 11:34:13 perseus postmaster[3176]: 2020-08-11 11:34:13.373 -03 [3176] LOG:  listening on IPv4 address "0.0.0.0",port 5432
Aug 11 11:34:13 perseus postmaster[3176]: 2020-08-11 11:34:13.373 -03 [3176] LOG:  listening on IPv6 address "::",port 5432
Aug 11 11:34:13 perseus postmaster[3176]: 2020-08-11 11:34:13.375 -03 [3176] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGsql.5432"
Aug 11 11:34:13 perseus postmaster[3176]: 2020-08-11 11:34:13.380 -03 [3176] LOG:  listening on Unix socket "/tmp/.s.PGsql.5432"
Aug 11 11:34:13 perseus postmaster[3176]: 2020-08-11 11:34:13.399 -03 [3176] LOG:  redirecting log output to logging collector process
Aug 11 11:34:13 perseus postmaster[3176]: 2020-08-11 11:34:13.399 -03 [3176] HINT:  Future log output will appear in directory "log".
Aug 11 11:34:17 perseus systemd[1]: postgresql-12.service: Main process exited,status=1/FAILURE
Aug 11 11:34:17 perseus systemd[1]: postgresql-12.service: Killing process 3177 (postmaster) with signal SIGKILL.
Aug 11 11:34:17 perseus systemd[1]: postgresql-12.service: Failed with result 'exit-code'.
Aug 11 11:34:17 perseus systemd[1]: Failed to start Postgresql 12 database server.
-- Subject: Unit postgresql-12.service has Failed
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit postgresql-12.service has Failed.
--
-- The result is RESULT.
Aug 11 11:34:17 perseus sudo[3167]: pam_unix(sudo:session): session closed for user root
Aug 11 11:34:38 perseus sudo[3188]: postgres : TTY=pts/0 ; PWD=/var/lib/pgsql ; USER=root ; COMMAND=/bin/journalctl -xe
Aug 11 11:34:38 perseus sudo[3188]: pam_systemd(sudo:session): Cannot create session: Already running in a session or user slice
Aug 11 11:34:38 perseus sudo[3188]: pam_unix(sudo:session): session opened for user root by root(uid=0)

具有详细模式的数据库日志:

    2020-08-11 15:23:01.400 -03 [7405] LOG:  00000: database system was interrupted; last kNown up at 2020-08-07 11:37:10 -03
2020-08-11 15:23:01.400 -03 [7405] LOCATION:  StartupXLOG,xlog.c:6305
2020-08-11 15:23:05.160 -03 [7405] FATAL:  58P01: Could not open directory "": No such file or directory
2020-08-11 15:23:05.160 -03 [7405] LOCATION:  ReadDirExtended,fd.c:2563
2020-08-11 15:23:05.161 -03 [7403] LOG:  00000: startup process (PID 7405) exited with exit code 1
2020-08-11 15:23:05.161 -03 [7403] LOCATION:  LogChildExit,postmaster.c:3675
2020-08-11 15:23:05.161 -03 [7403] LOG:  00000: aborting startup due to startup process failure
2020-08-11 15:23:05.161 -03 [7403] LOCATION:  reaper,postmaster.c:2945
2020-08-11 15:23:05.163 -03 [7403] LOG:  00000: database system is shut down
2020-08-11 15:23:05.163 -03 [7403] LOCATION:  UnlinkLockFiles,miscinit.c:860

PGDATA目录:

[postgres@perseus ~]$ ll -la /var/lib/pgsql/12/data/
total 88
drwx------. 20 postgres postgres  4096 Aug 11 15:49 .
drwx------.  4 postgres postgres    66 Aug 11 14:55 ..
drwx------. 26 postgres postgres  4096 Jul 28 09:29 base
-rw-------   1 postgres postgres    30 Aug 11 15:49 current_logfiles
drwx------.  2 postgres postgres  4096 Aug 11 09:34 global
-rw-r--r--   1 root     root       560 May 29 10:05 global.sql
drwx------.  2 postgres postgres   188 Aug 11 15:50 log
drwx------.  2 postgres postgres     6 May 22 09:16 pg_commit_ts
drwx------.  2 postgres postgres     6 May 22 09:16 pg_dynshmem
-rw-------   1 postgres postgres  4329 May 28 09:07 pg_hba.conf
-rw-------.  1 postgres postgres  1636 May 22 09:16 pg_ident.conf
drwx------.  4 postgres postgres    68 Aug  7 11:37 pg_logical
drwx------.  4 postgres postgres    36 May 22 09:16 pg_multixact
drwx------.  2 postgres postgres    18 Aug 11 15:49 pg_notify
drwx------.  2 postgres postgres     6 May 22 09:16 pg_replslot
drwx------.  2 postgres postgres     6 May 22 09:16 pg_serial
drwx------.  2 postgres postgres     6 May 22 09:16 pg_snapshots
drwx------.  2 postgres postgres     6 Jul 24 14:45 pg_stat
drwx------.  2 postgres postgres  4096 Aug 11 15:49 pg_stat_tmp
drwx------.  2 postgres postgres    18 Jul 28 09:36 pg_subtrans
drwx------.  2 postgres postgres     6 May 22 09:16 pg_tblspc
drwx------.  2 postgres postgres     6 May 22 09:16 pg_twophase
-rw-------.  1 postgres postgres     3 May 22 09:16 PG_VERSION
drwx------.  3 postgres postgres  4096 Jul 31 17:16 pg_wal
drwx------.  2 postgres postgres  4096 Jun  3 11:51 pg_xact
-rw-------.  1 postgres postgres    88 May 22 09:16 postgresql.auto.conf
-rw-------   1 postgres postgres 26808 Aug 11 15:22 postgresql.conf
-rw-------   1 postgres postgres    58 Aug 11 15:49 postmaster.opts
-rw-r--r--   1 root     root      1160 May 29 09:08 teste.backup

使用更多数据进行编辑。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)