An important change in PostgreSQL 12 is that the parameters in the recovery.conf configuration file are merged into postgresql.conf and recovery.conf is no longer in use. Let's look at the instructions in the manual as follows:
Release Notes
Move recovery.conf settings into postgresql.conf (Fujii Masao, Simon Riggs, Abhijit Menon-Sen, Sergei Kornilov)
recovery.conf is no longer used, and the server will not start if the file exists. recovery.signal and standby.signal are now used to switch into non-primary mode. trigger_file has been renamed to promote_trigger_file. The standby_mode setting has been removed.
The Handbook mentions a lot of information about change, including the following points:
- Recovery.conf configuration file is no longer supported. The parameters in this file are merged into postgresql.conf. If recovery.conf exists, the database cannot be started.
- Add a recovery.signal identification file to indicate that the database is in recovery mode
- Add a new standby.signal identification file to indicate that the database is in standby mode
- The trigger_file parameter is renamed promote_trigger_file
- standby_mode parameter is no longer supported
What should be noted about the above changes for deploying PostgreSQL stream replication? This is a simple demonstration of the deployment of stream replication. PostgreSQL: Using pg_basebackup to build a stream replication environment.
pg_basebackup command difference
The effect of the - R parameter of the 12th version of the pg_basebackup command is different from that of the previous version, which is mainly reflected in:
- After the command is executed, create a standby.signal identification file in the $PGDATA directory with empty contents
- Add primary_conninfo parameter information to the postgresql.auto.conf file of the $PGDATA directory after the command is executed
After verification, the test environment information is as follows:
pghost1 192.168.2.11 master node pghost2 192.168.2.12 standby node
Execute the pg_basebackup command in pghost2, as follows:
[pg12@pghost2 pg12]$ pg_basebackup -R -D /pgdata/pg12/pg_root -Fp -Xs -v -P -h 192.168.2.11 -p 1921 -U repuser pg_basebackup: initiating base backup, waiting for checkpoint to complete pg_basebackup: checkpoint completed pg_basebackup: write-ahead log start point: 0/5B000028 on timeline 1 pg_basebackup: starting background WAL receiver pg_basebackup: created temporary replication slot "pg_basebackup_34159" 1144035/1144035 kB (100%), 2/2 tablespaces pg_basebackup: write-ahead log end point: 0/5B000138 pg_basebackup: waiting for background process to finish streaming ... pg_basebackup: syncing data to disk ... pg_basebackup: base backup completed
Verify the standby.signal file as follows:
[pg12@pghost2 pg_root]$ ll $PGDATA/standby.signal -rw-------. 1 pg12 pg12 0 Jul 18 10:30 /pgdata/pg12/pg_root/standby.signal
Verify the postgresql.auto.conf file as follows:
[pg12@pghost2 pg_root]$ cat $PGDATA/postgresql.auto.conf # Do not edit this file manually! # It will be overwritten by the ALTER SYSTEM command. primary_conninfo = 'user=repuser passfile=''/home/pg12/.pgpass'' host=192.168.2.11 port=1921 sslmode=disable sslcompression=0 gssencmode=disable target_session_attrs=any'
Sure enough, the standby.signa identification file is generated in the $PGDATA directory, and the postgresql.auto.conf configuration file adds primary_conninfo parameter information.
Then start the reserve, as follows:
[pg12@pghost2 pg_root]$ pg_ctl start
The primary and secondary roles are verified and the flow replication works properly.
recovery.conf is no longer supported
Previous versions of PostgreSQL's stream replication standby are identified by creating recovery.conf file in the $PGDATA directory, which is an important file for stream replication deployment. If this file does not exist in the $PGDATA directory, the database cannot be started as a stream replication standby role.
The recovery.conf file is no longer supported in version 12. If this file exists in the data directory, the database startup error will be reported.
summary
Although PostgreSQL 12 deployment stream replication is almost the same at the operational level as the previous version, there is a big difference between the 12 version and the previous version in processing mechanism, and the effect of the - R parameter of the pg_basebackup command is different from the previous version, which should be noted.
Reference resources
- Waiting for PostgreSQL 12 – Integrate recovery.conf into postgresql.conf
- HOT STANDBY Configuration after PostgreSQL 12 preview-recovery.conf merged into postgresql.conf
- Archive Recovery
- pg_basebackup
Source Link: https://postgres.fun/20190718155800.html
New Arrivals
Finally, PostgreSQL Actual Warfare, written by Zhang Wensheng, is recommended. This book is based on PostgreSQL 10 and consists of 18 chapters. It focuses on the advanced features of SQL, parallel query, partition table, physical replication, logical replication, backup recovery, high availability, performance optimization, PostGIS and so on. It covers a large number of practical cases.