其他分享
首页 > 其他分享> > pg14.3主备切换时报错

pg14.3主备切换时报错

作者:互联网

一、报错:

[postgres@dba01 archive]$ pg_ctl -D /data/pg14 start
waiting for server to start....2022-08-18 16:11:43.883 CST [45459] LOG: redirecting log output to logging collector process
2022-08-18 16:11:43.883 CST [45459] HINT: Future log output will appear in directory "/data/pg14/log".
stopped waiting
pg_ctl: could not start server
Examine the log output.

[postgres@dba01 log]$ cat pg_log_2022-08-18_160305.
pg_log_2022-08-18_160305.csv pg_log_2022-08-18_160305.log
[postgres@dba01 log]$ cat pg_log_2022-08-18_160305.csv
2022-08-18 16:03:05.244 CST,,,45400,,62fdf239.b158,1,,2022-08-18 16:03:05 CST,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log destination ""csvlog"".",,,,,,,"","postmaster",,0
2022-08-18 16:03:05.244 CST,,,45400,,62fdf239.b158,2,,2022-08-18 16:03:05 CST,,0,LOG,00000,"starting PostgreSQL 14.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit",,,,,,,,,"","postmaster",,0
2022-08-18 16:03:05.245 CST,,,45400,,62fdf239.b158,3,,2022-08-18 16:03:05 CST,,0,LOG,00000,"listening on IPv4 address ""0.0.0.0"", port 1921",,,,,,,,,"","postmaster",,0
2022-08-18 16:03:05.245 CST,,,45400,,62fdf239.b158,4,,2022-08-18 16:03:05 CST,,0,LOG,00000,"listening on IPv6 address ""::"", port 1921",,,,,,,,,"","postmaster",,0
2022-08-18 16:03:05.247 CST,,,45400,,62fdf239.b158,5,,2022-08-18 16:03:05 CST,,0,LOG,00000,"listening on Unix socket ""/tmp/.s.PGSQL.1921""",,,,,,,,,"","postmaster",,0
2022-08-18 16:03:05.249 CST,,,45402,,62fdf239.b15a,1,,2022-08-18 16:03:05 CST,,0,LOG,00000,"database system was shut down at 2022-08-18 15:55:59 CST",,,,,,,,,"","startup",,0
2022-08-18 16:03:05.249 CST,,,45402,,62fdf239.b15a,2,,2022-08-18 16:03:05 CST,,0,LOG,00000,"entering standby mode",,,,,,,,,"","startup",,0
2022-08-18 16:03:05.249 CST,,,45402,,62fdf239.b15a,3,,2022-08-18 16:03:05 CST,,0,FATAL,XX000,"requested timeline 2 is not a child of this server's history","Latest checkpoint is at 0/D000028 on timeline 1, but in the history of the requested timeline, the server forked off from that timeline at 0/7000148.",,,,,,,,"","startup",,0
2022-08-18 16:03:05.249 CST,,,45400,,62fdf239.b158,6,,2022-08-18 16:03:05 CST,,0,LOG,00000,"startup process (PID 45402) exited with exit code 1",,,,,,,,,"","postmaster",,0
2022-08-18 16:03:05.249 CST,,,45400,,62fdf239.b158,7,,2022-08-18 16:03:05 CST,,0,LOG,00000,"aborting startup due to startup process failure",,,,,,,,,"","postmaster",,0
2022-08-18 16:03:05.250 CST,,,45400,,62fdf239.b158,8,,2022-08-18 16:03:05 CST,,0,LOG,00000,"database system is shut down",,,,,,,,,"","postmaster",,0

二、原因:

新备库pg_wal目录下的00000002.history 这个跟新主库不一致。

 

三、新备库(主转)

[postgres@dba01 pg_wal]$ ls -la
总用量 49164
drwx------. 3 postgres postgres 196 8月 18 16:13 .
drwx------. 20 postgres postgres 4096 8月 18 16:14 ..
-rw-------. 1 postgres postgres 338 8月 18 14:55 00000001000000000000000B.00000028.backup
-rw-------. 1 postgres postgres 16777216 8月 18 15:55 00000001000000000000000C
-rw-------. 1 postgres postgres 16777216 8月 18 15:55 00000001000000000000000D
-rw-------. 1 postgres postgres 16777216 8月 18 14:55 00000001000000000000000E
-rw-------. 1 postgres postgres 41 8月 18 16:13 00000002.history
drwx------. 2 postgres postgres 125 8月 18 15:55 archive_status
[postgres@dba01 pg_wal]$ pwd
/data/pg14/pg_wal

将新备库的00000002.history备份,并删除,新主库上复制过来

 

-bash-4.2$ scp -rv 00000002.history postgres@192.168.159.133:/data/pg14/pg_wal/

[postgres@dba01 pg_wal]$ pg_ctl start 正常

 

[postgres@dba01 pg_wal]$ pg_controldata
pg_control version number: 1300
Catalog version number: 202107181
Database system identifier: 7133089316689948049
Database cluster state: in archive recovery   主成为了备库
pg_control last modified: 2022年08月18日 星期四 16时14分02秒
Latest checkpoint location: 0/D000028
Latest checkpoint's REDO location: 0/D000028
Latest checkpoint's REDO WAL file: 00000001000000000000000D
Latest checkpoint's TimeLineID: 1
Latest checkpoint's PrevTimeLineID: 1
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID: 0:739
Latest checkpoint's NextOID: 16389
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 727
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 0
Latest checkpoint's oldestMultiXid: 1
Latest checkpoint's oldestMulti's DB: 1
Latest checkpoint's oldestCommitTsXid:0
Latest checkpoint's newestCommitTsXid:0
Time of latest checkpoint: 2022年08月18日 星期四 15时55分59秒
Fake LSN counter for unlogged rels: 0/3E8
Minimum recovery ending location: 0/D0000A0
Min recovery ending loc's timeline: 1
Backup start location: 0/0
Backup end location: 0/0
End-of-backup record required: no
wal_level setting: replica
wal_log_hints setting: on
max_connections setting: 100
max_worker_processes setting: 8
max_wal_senders setting: 10
max_prepared_xacts setting: 0
max_locks_per_xact setting: 64
track_commit_timestamp setting: off
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 131072
WAL block size: 8192
Bytes per WAL segment: 16777216
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Size of a large-object chunk: 2048
Date/time type storage: 64-bit integers
Float8 argument passing: by value
Data page checksum version: 0
Mock authentication nonce: 218bf631b257b4b1ed58bb161a4aa34adae4dadf1e0526583be42419b640f18b

标签:03,时报,16,18,08,主备,pg14.3,CST,postgres
来源: https://www.cnblogs.com/chinaops/p/16599157.html