KingbaseES V8R3 由于修改系统时间导致sys_rman备份故障案例
阅读原文时间:2023年07月09日阅读:3

案例说明:

此案例,为复现“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备份问题解决。====

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章