KingbaseES V8R6 集群运维系列--archive_cleanup_command参数应用


案例说明:
参数archive_cleanup_command可以配置在kingbase.conf文件中,用于备库清理不在需要的归档日志,参数详细说明见下图:
https://postgresqlco.nf/doc/zh/param/archive_cleanup_command/

适用环境:
KingbaseES V8R/R6

集群节点状态:

[kingbase@node2 bin]$ ./repmgr  cluster show
 ID | Name    | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                                                                                
----+---------+---------+-----------+----------+----------+----------+----------+---------------------------------------------------------------------------------------------------------------------------------------------------
 1  | node200 | primary | * running |          | default  | 100      | 17       | host=192.168.8.200 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3
 2  | node201 | standby |   running | node200  | default  | 100      | 17       | host=192.168.8.201 user=esrep dbname=esrep port=54321 connect_timeout=10 keepalives=1 keepalives_idle=10 keepalives_interval=1 keepalives_count=3

1、备库节点配置归档

2、查看当前备库归档信息

[kingbase@node2 bin]$ ls -lh /db/kingbase/arch_ha/
total 401M
-rw------- 1 kingbase kingbase 474 Dec  2 11:21 0000000C.history
-rw------- 1 kingbase kingbase 562 Dec  2 11:21 0000000E.history
-rw------- 1 kingbase kingbase 650 Dec  2 11:21 00000010.history
-rw------- 1 kingbase kingbase 16M Dec  2 11:36 000000110000000200000015
-rw------- 1 kingbase kingbase 16M Dec  2 11:36 000000110000000200000016
-rw------- 1 kingbase kingbase 16M Dec  2 11:36 000000110000000200000017
-rw------- 1 kingbase kingbase 16M Dec  2 11:37 000000110000000200000018
-rw------- 1 kingbase kingbase 16M Dec  2 11:37 000000110000000200000019
-rw------- 1 kingbase kingbase 16M Dec  2 11:37 00000011000000020000001A
-rw------- 1 kingbase kingbase 16M Dec  2 11:38 00000011000000020000001B
-rw------- 1 kingbase kingbase 16M Dec  2 11:38 00000011000000020000001C
-rw------- 1 kingbase kingbase 16M Dec  2 11:38 00000011000000020000001D
-rw------- 1 kingbase kingbase 16M Dec  2 11:39 00000011000000020000001E
-rw------- 1 kingbase kingbase 16M Dec  2 11:39 00000011000000020000001F
-rw------- 1 kingbase kingbase 16M Dec  2 11:39 000000110000000200000020
-rw------- 1 kingbase kingbase 16M Dec  2 11:39 000000110000000200000021
-rw------- 1 kingbase kingbase 16M Dec  2 11:40 000000110000000200000022
-rw------- 1 kingbase kingbase 16M Dec  2 11:40 000000110000000200000023
-rw------- 1 kingbase kingbase 16M Dec  2 11:40 000000110000000200000024
-rw------- 1 kingbase kingbase 16M Dec  2 11:40 000000110000000200000025
-rw------- 1 kingbase kingbase 16M Dec  2 11:41 000000110000000200000026
-rw------- 1 kingbase kingbase 16M Dec  2 11:44 000000110000000200000027
-rw------- 1 kingbase kingbase 16M Dec  2 11:44 000000110000000200000028
-rw------- 1 kingbase kingbase 16M Dec  2 11:44 000000110000000200000029
-rw------- 1 kingbase kingbase 16M Dec  2 11:44 00000011000000020000002A
-rw------- 1 kingbase kingbase 16M Dec  2 11:44 00000011000000020000002B
-rw------- 1 kingbase kingbase 16M Dec  2 11:44 00000011000000020000002C
-rw------- 1 kingbase kingbase 16M Dec  2 11:44 00000011000000020000002D

3、备库执行 checkpoint

test=# checkpoint;
CHECKPOINT

如下sys_log所示:备库在执行checkpoint时,生成了“restart point”,备库在运行期间,也将自动产生“restart point”。

[kingbase@node2 sys_log]$ cat kingbase-2022-12-02_115106.csv|grep point
2022-12-02 11:51:06.873 CST,,,6616,,6389762a.19d8,3,,2022-12-02 11:51:06 CST,,0,DEBUG,00000,"checkpoint record is at 2/2E660E60",,,,,,,,,""
2022-12-02 11:51:06.879 CST,,,6617,,6389762a.19d9,1,,2022-12-02 11:51:06 CST,,0,DEBUG,00000,"checkpointer updated shared memory configuration values",,,,,,,,,""
2022-12-02 11:56:06.979 CST,,,6617,,6389762a.19d9,2,,2022-12-02 11:51:06 CST,,0,LOG,00000,"restartpoint starting: time",,,,,,,,,""
2022-12-02 11:56:07.021 CST,,,6617,,6389762a.19d9,3,,2022-12-02 11:51:06 CST,,0,DEBUG,00000,"updated min recovery point to 2/2E663E28 on timeline 17",,,,,,,,,""
2022-12-02 11:56:07.288 CST,,,6617,,6389762a.19d9,4,,2022-12-02 11:51:06 CST,,0,DEBUG,00000,"performing replication slot checkpoint",,,,,,,,,""
2022-12-02 11:56:07.508 CST,,,6617,,6389762a.19d9,5,,2022-12-02 11:51:06 CST,,0,DEBUG,00000,"checkpoint sync: number=1 file=base/16385/16405 time=13.982 msec",,,,,,,,,""
2022-12-02 11:56:07.509 CST,,,6617,,6389762a.19d9,6,,2022-12-02 11:51:06 CST,,0,DEBUG,00000,"checkpoint sync: number=2 file=base/16385/16388 time=0.681 msec",,,,,,,,,""
2022-12-02 11:56:07.515 CST,,,6617,,6389762a.19d9,12,,2022-12-02 11:51:06 CST,,0,LOG,00000,"restartpoint complete: wrote 2 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.205 s, sync=0.014 s, total=0.535 s; sync files=2, longest=0.013 s, average=0.007 s; distance=11 kB, estimate=11 kB",,,,,,,,,""
2022-12-02 11:56:07.515 CST,,,6617,,6389762a.19d9,13,,2022-12-02 11:51:06 CST,,0,LOG,00000,"recovery restart point at 2/2E663D50","Last completed transaction was at log time 2022-12-02 11:50:54.157512+08.",,,,,,,,""
2022-12-02 11:58:07.840 CST,,,6617,,6389762a.19d9,16,,2022-12-02 11:51:06 CST,,0,DEBUG,00000,"skipping restartpoint, already performed at 2/2E663D50",,,,,,,,,""

4、查看归档日志信息

如下所示:备库将判断哪些归档不在需要,并对这些归档执行清理。

[kingbase@node2 bin]$ ls -lh /db/kingbase/arch_ha/
total 12K
-rw------- 1 kingbase kingbase 474 Dec  2 11:21 0000000C.history
-rw------- 1 kingbase kingbase 562 Dec  2 11:21 0000000E.history
-rw------- 1 kingbase kingbase 650 Dec  2 11:21 00000010.history

Tips:
对于同样的归档配置,在主库,此参数不生效,不会执行归档清理。对于归档日志的清理,可以通过脚本调用sys_archivecleanup工具清理。

单实例环境测试:

1、配置kingbase.conf

2、执行wal日志切换

prod=# insert into t1 values (generate_series(1,10000));
INSERT 0 10000
prod=# select sys_switch_wal();
 sys_switch_wal
----------------
 0/1A582518
(1 row)

3、查看当前归档日志

如下所示,在执行checkpoint后没有实现归档日志的自动清理。

[kingbase@node102 data]$ ls -l ../arch
total 49152
-rw------- 1 kingbase kingbase 16777216 Dec 12 14:14 000000010000000000000018
-rw------- 1 kingbase kingbase 16777216 Dec 12 14:14 000000010000000000000019
-rw------- 1 kingbase kingbase 16777216 Dec 12 14:16 00000001000000000000001A
posted @ 2023-03-02 16:15  KINGBASE研究院  阅读(210)  评论(0编辑  收藏  举报