Postgresql

啟動時Postgres 10副本服務錯誤

  • October 25, 2018

我已經在容量更大的伺服器中遷移了一個促進只讀副本的數據庫,這個過程執行得很順利。但是我現在正在嘗試從這個提升的伺服器創建一個只讀副本,以具有與以前類似的設置。問題是當我嘗試啟動 Postgres 伺服器時會發生這種情況。

● postgresql-10.service - PostgreSQL 10 database server
  Loaded: loaded (/usr/lib/systemd/system/postgresql-10.service; disabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since mar 2018-10-16 07:07:42 UTC; 10s ago
  Docs: https://www.postgresql.org/docs/10/static/
  Process: 22746 ExecStart=/usr/pgsql-10/bin/postmaster -D ${PGDATA} 
  (code=exited, status=2)
  Process: 22740 ExecStartPre=/usr/pgsql-10/bin/postgresql-10-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
  Main PID: 22746 (code=exited, status=2)

我將盡可能準確地描述我的過程,我在 CentOS RHEL 7 上執行。

首先我安裝 Postgres 10:

rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install postgresql10-server postgresql10
yum install postgresql10-contrib
su - postgres
/usr/pgsql-10/bin/initdb
systemctl start postgresql-10.service

這行得通,伺服器正在執行,所以安裝工作正常,讓我們從複製開始。我停止服務並繼續:

rm -r /var/lib/pgsql/10/data
su - postgres
/usr/pgsql-10/bin/pg_basebackup -h <database host ip> -D /var/lib/pgsql/10/data/ -P -U replicate

replicate是在主數據庫中具有複製權限的使用者。

pg_basebackup正確完成,然後我將其重命名recovery.donerecovery.conf.

drwx------. 6 postgres postgres   54 oct 16 06:45 base
-rw-------. 1 postgres postgres   30 oct 16 06:55 current_logfiles
drwx------. 2 postgres postgres 4,0K oct 16 06:45 global
drwx------. 2 postgres postgres  188 oct 16 06:53 log
drwx------. 2 postgres postgres    6 oct 16 06:45 pg_commit_ts
drwx------. 2 postgres postgres    6 oct 16 06:45 pg_dynshmem
-rw-------. 1 postgres postgres 4,5K oct 16 06:55 pg_hba.conf
-rw-------. 1 postgres postgres 1,6K oct 16 06:55 pg_ident.conf
drwx------. 4 postgres postgres   68 oct 16 06:53 pg_logical
drwx------. 4 postgres postgres   36 oct 16 06:45 pg_multixact
drwx------. 2 postgres postgres   18 oct 16 06:45 pg_notify
drwx------. 2 postgres postgres    6 oct 16 06:53 pg_replslot
drwx------. 2 postgres postgres    6 oct 16 06:45 pg_serial
drwx------. 2 postgres postgres    6 oct 16 06:45 pg_snapshots
drwx------. 2 postgres postgres    6 oct 16 06:53 pg_stat
drwx------. 2 postgres postgres    6 oct 16 06:53 pg_stat_tmp
drwx------. 2 postgres postgres    6 oct 16 06:45 pg_subtrans
drwx------. 2 postgres postgres    6 oct 16 06:53 pg_tblspc
drwx------. 2 postgres postgres    6 oct 16 06:45 pg_twophase
-rw-------. 1 postgres postgres    3 oct 16 06:55 PG_VERSION
drwx------. 3 postgres postgres 4,0K oct 16 06:45 pg_wal
drwx------. 2 postgres postgres 4,0K oct 16 06:53 pg_xact
-rw-------. 1 postgres postgres   88 oct 16 06:55 postgresql.auto.conf
-rw-------. 1 postgres postgres  23K oct 16 06:55 postgresql.conf
-rw-------. 1 postgres postgres   58 oct 16 06:55 postmaster.opts
-rw-r--r--. 1 postgres postgres  154 oct 16 06:53 recovery.conf

但是在跑步時systemctl start postgresql-10.service,我得到

postgresql-10.service 的作業失敗,因為控制程序以錯誤程式碼退出。有關詳細資訊,請參閱“systemctl status postgresql-10.service”和“journalctl -xe”。

我找不到比這條消息更多的線索:

postgresql-10.service: main process exited, code=exited, status=1/FAILURE

我錯過了什麼?我嘗試使用預設執行postgres.confpg_hba.conf避免配置錯誤,但這也不起作用。

完整journalctl輸出:

oct 17 09:15:11 database-replica systemd[1]: Starting PostgreSQL 10 database server...
-- Subject: Unit postgresql-10.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql-10.service has begun starting up.
oct 17 09:15:11 database-replica postmaster[19514]: 2018-10-17 09:15:11.834 UTC [19514] LOG:  listening on IPv6 address "::1", port 5432
oct 17 09:15:11 database-replica postmaster[19514]: 2018-10-17 09:15:11.834 UTC [19514] LOG:  listening on IPv4 address "127.0.0.1", port 5432
oct 17 09:15:11 database-replica postmaster[19514]: 2018-10-17 09:15:11.836 UTC [19514] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
oct 17 09:15:11 database-replica postmaster[19514]: 2018-10-17 09:15:11.840 UTC [19514] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
oct 17 09:15:11 database-replica postmaster[19514]: 2018-10-17 09:15:11.865 UTC [19514] LOG:  redirecting log output to logging collector process
oct 17 09:15:11 database-replica postmaster[19514]: 2018-10-17 09:15:11.865 UTC [19514] HINT:  Future log output will appear in directory "log".
oct 17 09:15:11 database-replica systemd[1]: postgresql-10.service: main process exited, code=exited, status=1/FAILURE
oct 17 09:15:11 database-replica systemd[1]: Failed to start PostgreSQL 10 database server.
-- Subject: Unit postgresql-10.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql-10.service has failed.
--
-- The result is failed.
oct 17 09:15:11 database-replica systemd[1]: Unit postgresql-10.service entered failed state.
oct 17 09:15:11 database-replica systemd[1]: postgresql-10.service failed.
oct 17 09:15:11 database-replica polkitd[676]: Unregistered Authentication Agent for unix-process:19502:16930756 (system bus name :1.160, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale es_ES.UTF-8) (disconnected from bus)

最後,我注意到問題出在哪裡。pg_basebackup複製了一個recovery.conf最初來自源數據庫的文件,這導致了中斷。recovery.conf從頭開始刪除和創建它解決了這個問題。

伺服器現在正在執行。

引用自:https://dba.stackexchange.com/questions/220197