Warm tip: This article is reproduced from serverfault.com, please click

Cannot start Postgresql 12 after pg_basebackup (replication)

发布于 2020-12-02 09:09:01

I have two DB servers and I am trying to make a Master-Slave replication for my PostgreSQL with TimescaleDB extension.

I went through this process:

  1. [Both] Install PostgreSQL 12 on CentOS 7.

  2. [Both] Initialize DB and install TimescaleDB. (followed official website tutorial)

  3. [Both] Do all the firewall-cmd, postgresql.conf, and pg_hba.conf works.

  4. [Master] Create initial database.

  5. [Slave] stop PostgreSQL, remove everything in /var/lib/pgsql/12/data, and pg_basebackup from Master.

    (Command I used: pg_basebackup -h [MASTER_DB_IP] -D /var/lib/pgsql/12/data -U [REP_USER] -vP -W)

  6. [Slave] set hot_standby = on and create recovery.conf

  7. [Slave] start PostgreSQL to check replication works.

  8. [Slave] This error occurs and cannot start PostgreSQL.

-- Subject: Unit postgresql-12.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql-12.service has begun starting up.
Dec 02 17:53:40 localhost.localdomain postmaster[10439]: 2020-12-02 17:53:40.116 KST [10439] LOG:  starting PostgreSQL 12.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red
Dec 02 17:53:40 localhost.localdomain postmaster[10439]: 2020-12-02 17:53:40.116 KST [10439] LOG:  listening on IPv4 address "0.0.0.0", port 5432
Dec 02 17:53:40 localhost.localdomain postmaster[10439]: 2020-12-02 17:53:40.116 KST [10439] LOG:  listening on IPv6 address "::", port 5432
Dec 02 17:53:40 localhost.localdomain postmaster[10439]: 2020-12-02 17:53:40.122 KST [10439] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Dec 02 17:53:40 localhost.localdomain postmaster[10439]: 2020-12-02 17:53:40.130 KST [10439] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
Dec 02 17:53:40 localhost.localdomain postmaster[10439]: 2020-12-02 17:53:40.142 KST [10439] LOG:  redirecting log output to logging collector process
Dec 02 17:53:40 localhost.localdomain postmaster[10439]: 2020-12-02 17:53:40.142 KST [10439] HINT:  Future log output will appear in directory "log".
Dec 02 17:53:42 localhost.localdomain systemd[1]: postgresql-12.service: main process exited, code=exited, status=1/FAILURE
Dec 02 17:53:42 localhost.localdomain systemd[1]: Failed to start PostgreSQL 12 database server.

As far as I know, this is the last step for replication. But PostgreSQL is not starting after all configuration.

Please ask me any detailed questions.

Thank you in advance.

Questioner
David YK Han
Viewed
0
Laurenz Albe 2020-12-03 11:20:00

From version 12 on, PostgreSQL no longer uses recovery.conf for recovery configuration.

Instead, you have to add the recovery configuration parameters to postgresql.conf or postgresql.auto.conf (the latter is commendable for automated editing).

Then create a file standby.signal in the data directory, which tells PostgreSQL to start and remain in recovery mode.

Then start the standby server.

Note: the standby_mode parameter is gone. Instead, use standby.signal if you want standby mode and recovery.signal for recovery mode that ends.