开启归档
archive_mode = on archive_command='test ! -f /home/archive_kb/%f && cp %p /home/archive_kb/%f'
注意:修改后需要重启,archive_command 这里设置的是 归档日志文件存储在 归档日志路径 /home/archive_kb
生成归档文件
手动切换
[kingbase@localhost archive_kb]$ ll 总用量 16388 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ ksql test system 输入 "help" 来获取帮助信息. test=# exit [kingbase@localhost archive_kb]$ ll 总用量 16388 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ ksql test system 输入 "help" 来获取帮助信息. test=# select sys_switch_wal(); ---手动去切换 sys_switch_wal ---------------- 0/170001C0 (1 行记录) test=# exit [kingbase@localhost archive_kb]$ ll ---生成新的归档文件 总用量 32772 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:15 000000050000000000000017 -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$
重启数据库
[kingbase@localhost home]$ cd /home/archive_kb/ [kingbase@localhost archive_kb]$ ll 总用量 32772 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:15 000000050000000000000017 -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ sys_ctl -D /home/data restart ---重启数据库 等待服务器进程关闭 .... 完成 服务器进程已经关闭 等待服务器进程启动 ....2024-03-25 16:19:40.669 CST [30834] 日志: sepapower扩展初始化完成 2024-03-25 16:19:40.676 CST [30834] 日志: 正在启动 KingbaseES V008R006C008B0014 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit 2024-03-25 16:19:40.676 CST [30834] 日志: 正在监听IPv4地址"0.0.0.0",端口 54321 2024-03-25 16:19:40.676 CST [30834] 日志: 正在监听IPv6地址"::",端口 54321 2024-03-25 16:19:40.694 CST [30834] 日志: 在Unix套接字 "/tmp/.s.KINGBASE.54321"上侦听 2024-03-25 16:19:40.734 CST [30834] 日志: 日志输出重定向到日志收集进程 2024-03-25 16:19:40.734 CST [30834] 提示: 后续的日志输出将出现在目录 "sys_log"中. 完成 服务器进程已经启动 [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ ll 总用量 49156 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:15 000000050000000000000017 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:19 000000050000000000000018 -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$
WAL日志写满 (segment file) 写满
[kingbase@localhost archive_kb]$ ll 总用量 49156 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:15 000000050000000000000017 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:19 000000050000000000000018 -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ ksql test system 输入 "help" 来获取帮助信息. test=# test=# test=# test=# create table t(id int); CREATE TABLE test=# test=# test=# test=# insert into t values(generate_series(1,999999)); --插入大量数据,模拟日志写满 INSERT 0 999999 test=# exit [kingbase@localhost archive_kb]$ ll 总用量 98308 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:15 000000050000000000000017 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:19 000000050000000000000018 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 000000050000000000000019 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 00000005000000000000001A -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 00000005000000000000001B -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$
超过 acrive_timeout 值(大于0情况)
[kingbase@localhost archive_kb]$ ll 总用量 98308 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:15 000000050000000000000017 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:19 000000050000000000000018 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 000000050000000000000019 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 00000005000000000000001A -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 00000005000000000000001B -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ [kingbase@localhost archive_kb]$ ksql test system 输入 "help" 来获取帮助信息. test=# alter system set archive_timeout=60; ---设置超时时间 ALTER SYSTEM test=# test=# test=# select sys_reload_conf(); ---重载配置 sys_reload_conf ----------------- t (1 行记录) test=# test=# select sys_sleep(60); sys_sleep ----------- (1 行记录) test=# exit [kingbase@localhost archive_kb]$ ll 总用量 114692 -rw-------. 1 kingbase kingbase 16777216 3月 25 15:10 000000050000000000000016 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:15 000000050000000000000017 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:19 000000050000000000000018 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 000000050000000000000019 -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 00000005000000000000001A -rw-------. 1 kingbase kingbase 16777216 3月 25 16:22 00000005000000000000001B -rw-------. 1 kingbase kingbase 16777216 3月 25 16:29 00000005000000000000001C -rw-------. 1 kingbase kingbase 169 3月 25 14:43 00000005.history
清理过期归档
查看当前使用的归档日志
[kingbase@localhost archive_kb]$ sys_controldata /home/data/ | grep -E '新检查点的重做日志文件|REDO WAL file' 最新检查点的重做日志文件: 000000050000000000000016
清理过期归档日志
[kingbase@localhost archive_kb]$ sys_archivecleanup -d /home/archive_kb/ 000000050000000000000016 sys_archivecleanup: keeping WAL file "/home/archive_kb//000000050000000000000016" and later sys_archivecleanup: removing file "/home/archive_kb//00000005000000000000000C" sys_archivecleanup: removing file "/home/archive_kb//00000005000000000000000D" sys_archivecleanup: removing file "/home/archive_kb//00000005000000000000000E" sys_archivecleanup: removing file "/home/archive_kb//00000005000000000000000F" sys_archivecleanup: removing file "/home/archive_kb//000000050000000000000010" sys_archivecleanup: removing file "/home/archive_kb//000000050000000000000011" sys_archivecleanup: removing file "/home/archive_kb//000000050000000000000012" sys_archivecleanup: removing file "/home/archive_kb//000000050000000000000013" sys_archivecleanup: removing file "/home/archive_kb//000000050000000000000014" sys_archivecleanup: removing file "/home/archive_kb//000000050000000000000015"