PgSQL日常管理之WAL日志管理


一、防止WAL日志過早刪除

PostgreSQL提供管理checkpoint用途的WAL日志文件空間的相關配置

max_wal_size:用於設置允許WAL日志文件空間的最大增長上限

min_wal_size:用於設置需要保留的最小WAL日志文件空間

1、設置wal_keep_segments

wal_keep_segments指定在pg_wal目錄保留的過去WAL日志文件的最小個數,以防止某個備節點需要獲取WAL日志文件的流復制

2、開啟WAL日志歸檔

3、啟用復制槽

本例為1主2備庫(1個從庫sync模式,1個從庫異步模式)

postgres=# SELECT * FROM pg_create_physical_replication_slot('pg_slot_100');
slot_name | lsn
-------------+-----
pg_slot_100 |
(1 row)
postgres=# SELECT * FROM pg_create_physical_replication_slot('pg_slot_101');
slot_name | lsn
-------------+-----
pg_slot_101 |
(1 row)

postgres=# select * from pg_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn
-------------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------
pg_slot_100 | | physical | | | f | f | | | | |
pg_slot_101 | | physical | | | f | f | | | | |
(2 rows) 

postgres=# select * from pg_replication_slots;
slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn
-------------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+-------------+---------------------
pg_slot_100 | | physical | | | f | t | 7179 | | | 0/18000000 |
pg_slot_101 | | physical | | | f | t | 7405 | | | 0/18000000 |
(2 rows)

postgres=#

備庫的pg_log日志信息
2021-03-15 16:12:00.100 CST,,,11207,,604f16cf.2bc7,2,,2021-03-15 16:11:59 CST,,0,LOG,00000,"database system is ready to accept read only connections",,,,,,,,,""
2021-03-15 16:12:00.107 CST,,,11214,,604f16d0.2bce,1,,2021-03-15 16:12:00 CST,,0,LOG,00000,"started streaming WAL from primary at 0/17000000 on timeline 1",,,,,,,,,""

 

postgres=# select name,setting from pg_settings where name like 'max_wal_size';
name | setting
--------------+---------
max_wal_size | 1024
(1 row)

postgres=# select name,setting from pg_settings where name like 'min_wal_size';
name | setting
--------------+---------
min_wal_size | 80
(1 row)

postgres=# select name,setting from pg_settings where name like 'synchronous_commit';
name | setting
--------------------+--------------
synchronous_commit | remote_write
(1 row)

postgres=# select name,setting from pg_settings where name like 'synchronous_standby_names';
name | setting
---------------------------+---------
synchronous_standby_names |
(1 row)


postgres=# select client_addr,sync_state from pg_stat_replication;
client_addr | sync_state
----------------+------------
10.13.18.101 | sync
10.13.18.100 | potential
(2 rows)


關閉 10.13.18.101的PG,

postgres=# select client_addr,sync_state from pg_stat_replication;
client_addr | sync_state
----------------+------------
10.13.18.100 | sync
(1 row)

2021-03-15 16:48:07.849 CST,"repuser","",14530,"10.13.18.101:44116",604f1f47.38c2,2,"authentication",2021-03-15 16:48:07 CST,3/5,0,LOG,00000,"replication connection authorized: user=repuser application_name=walreceiver",,,,,,,,,""
2021-03-15 16:48:07.951 CST,"repuser","",14530,"10.13.18.101:44116",604f1f47.38c2,3,"idle",2021-03-15 16:48:07 CST,3/0,0,LOG,00000,"standby ""walreceiver"" is now a synchronous standby with priority 1",,,,,,,,,"walreceiver"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM