KingbaseES V8R3 由於修改系統時間導致sys_rman備份故障案例
阿新 • • 發佈:2022-05-19
案例說明:
此案例,為復現“current time may be rewound”錯誤。對於資料庫環境,在使用前必須保證系統時間的正確性。如果資料庫建立後,再將系統時間修改為建立資料庫之前的時間,在執行過程中將有可能導致新老事務判斷及事務一致性出現問題,比如Oracle資料庫事務的scn是和當前的timestamp有關聯的。
資料庫版本:
test=# select version(); version ---------------------------------------------------------------------------------------------------------- Kingbase V008R003C002B0290 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46), 64-bit (1 row)
1、當前系統時間
[kingbase@node1 bin]$ date
Fri May 13 10:23:31 CST 2022
2、初始化例項
[kingbase@node1 bin]$ ./initdb -U system -W 123456 --case-insensitive -D /data/kingbase/v8r3_290/data1 The files belonging to this database system will be owned by user "kingbase". This user must also own the server process. ....... Success. You can now start the database server using: ./sys_ctl -D /data/kingbase/v8r3_290/data1 -l logfile start
3、檢視資料庫建立時間
1)檢視controlfile中systemID
[kingbase@node1 bin]$ ./sys_controldata -D /data/kingbase/v8r3_290/data1 sys_control version number: 830 Catalog version number: 201608131 Database system identifier: 7097041251382751474 Database cluster state: shut down sys_control last modified: Fri 13 May 2022 10:24:52 AM CST Latest checkpoint location: 0/1B231E8 Prior checkpoint location: 0/1AE2720 Latest checkpoint's REDO location: 0/1B231E8 Latest checkpoint's REDO WAL file: 000000010000000000000001 .......
2)檢視資料庫建立時間
[kingbase@node1 bin]$ ./ksql -U system -W 123456 test
ksql (V008R003C002B0290)
Type "help" for help.
test=# select to_timestamp(((7097041251382751474>>32) &(2^32 -1)::bigint));
to_timestamp
---------------------
2022-05-13 02:24:42
(1 row)
4、修改資料庫時間(修改後時間早於資料庫建立時間)
[root@node1 ~]# date 051010102022
Tue May 10 10:10:00 CST 2022
[root@node1 ~]# date
Tue May 10 10:10:04 CST 2022
[kingbase@node1 bin]$ ./ksql -U system -W 123456 test
ksql (V008R003C002B0290)
Type "help" for help.
test=# select now();
now
-------------------------------
2022-05-10 10:10:24.956613+08
(1 row)
5、執行sys_rman備份
1)sys_rman初始化
[kingbase@node1 bin]$ ./sys_rman init -h 127.0.0.1 -U system -p 54321 -d test -B /data/kingbase/v8r3_290/db_bk -D /data/kingbase/v8r3_290/data1
Password for user system:
[kingbase@node1 bin]$ ls -lh /data/kingbase/v8r3_290/db_bk/
total 4.0K
drwx------ 2 kingbase kingbase 6 May 10 10:24 backups
-rw-rw-r-- 1 kingbase kingbase 41 May 10 10:24 sys_rman.conf
lrwxrwxrwx 1 kingbase kingbase 31 May 10 10:24 wal -> /data/kingbase/v8r3_290/archive
2)執行資料庫全量備份
=== 出現“current time may be rewound”錯誤。===
[kingbase@node1 bin]$ ./sys_rman backup -b full -U system -d test -B /data/kingbase/v8r3_290/db_bk -D /data/kingbase/v8r3_290/data1
Password for user system:
ERROR: current time may be rewound. Please retry with full backup mode.
6、解決方案
1)對資料庫通過sys_dmp備份
[kingbase@node1 bin]$ date
Tue May 10 10:17:24 CST 2022
[kingbase@node1 bin]$ ./sys_dump -U system -W 123456 test -f ~/db.sql
2)重新初始化例項
[kingbase@node1 bin]$ ./initdb -U system -W 123456 --case-insensitive -D /data/kingbase/v8r3_290/data2
......
load security database ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
./sys_ctl -D /data/kingbase/v8r3_290/data2 -l logfile start
3)配置歸檔並啟動新例項
[kingbase@node1 data2]$ cat kingbase.conf |grep -i archive_
archive_mode = on # enables archiving; off, on, or always
archive_command = 'test ! -f /data/kingbase/v8r3_290/archive/%f && cp %p /data/kingbase/v8r3_290/archive/%f' # command to use to archive a logfile segment
archive_dest = '/data/kingbase/v8r3_290/archive' # set archive logfile dest absolute path
# ! waring: if set archive_dest, ignore archive_command.
#archive_timeout = 0 # force a logfile segment switch after this
# 啟動例項
[kingbase@node1 bin]$ ./sys_ctl -D /data/kingbase/v8r3_290/data2 start
4)將原庫備份匯入新例項
[kingbase@node1 bin]$ ./ksql -U system -W 123456 test < ~/db.sql
SET
SET
SET
SET
SET
set_config
-----------------
"$USER", PUBLIC
(1 row)
SET
SET
SET
COMMENT
COPY 0
COPY 0
5)執行sys_rman備份
# sys_rman 初始化
[kingbase@node1 bin]$ ./sys_rman init -h 127.0.0.1 -U system -p 54321 -d test -B /data/kingbase/v8r3_290/db_bk -D /data/kingbase/v8r3_290/data2
Password for user system:
# sys_rman執行全備
[kingbase@node1 bin]$ ./sys_rman backup -b full -U system -d test -B /data/kingbase/v8r3_290/db_bk -D /data/kingbase/v8r3_290/data2
Password for user system:
INFO: validate: RBNB3P backup and archive log files by CRC
6)檢視備份資訊
[kingbase@node1 bin]$ ./sys_rman show -b full -U system -d test -B /data/kingbase/v8r3_290/db_bk
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RBNB3P 2022-05-10 10:38:53 FULL 1 / 0 328s 69MB 0/2000028 0/2000130 OK
[kingbase@node1 bin]$ ./sys_rman validate -b full -U system -d test -B /data/kingbase/v8r3_290/db_bk
INFO: validate: RBNB3P backup and archive log files by CRC
INFO: backup validation completed successfully
[kingbase@node1 bin]$ ./sys_rman show -b full -U system -d test -B /data/kingbase/v8r3_290/db_bk
==========================================================================================================
ID Recovery time Mode Current/Parent TLI Time Data start_lsn stop_lsn Status
==========================================================================================================
RBNB3P 2022-05-10 10:38:53 FULL 1 / 0 328s 69MB 0/2000028 0/2000130 OK
=== 如上所示,sys_rman備份問題解決。====