DB2-LAB5-备份和恢复数据

实验目的

  • Create a backup image of a database including all of the table spaces.
  • Configure a database to change from circular logging to enable archive logging to make the database fully recoverable.
  • Restore a database from a backup image and Roll forward a database to perform point in time recovery using the RECOVER command.

实验步骤

配置打印日志可用空间

配置log

db2inst1@shahuang-lt:~/course_file/ddl$ db2 update db cfg using logprimary 3 logsecond 1 logfilsiz 6
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
db2inst1@shahuang-lt:~/course_file/ddl$
db2inst1@shahuang-lt:~/course_file/ddl$ db2 get db cfg show detail

       Database Configuration for Database

 Description                                   Parameter   Current Value              Delayed Value
 ---------------------------------------------------------------------------------------------------------------
 Database configuration release level                    = 0x1500
 Database release level                                  = 0x1500

 Database territory                                      = US
 Database code page                                      = 1208
 Database code set                                       = UTF-8
 Database country/region code                            = 1
 Database collating sequence                             = IDENTITY                   IDENTITY
 Alternate collating sequence              (ALT_COLLATE) =
 Number compatibility                                    = OFF
 Varchar2 compatibility                                  = OFF
 Date compatibility                                      = OFF
 Database page size                                      = 4096                       4096

 Statement concentrator                      (STMT_CONC) = OFF                        OFF

 Discovery support for this database       (DISCOVER_DB) = ENABLE                     ENABLE

 Restrict access                                         = NO
 Default query optimization class         (DFT_QUERYOPT) = 5                          5
 Degree of parallelism                      (DFT_DEGREE) = 1                          1
 Continue upon arithmetic exceptions   (DFT_SQLMATHWARN) = NO                         NO
 Default refresh age                   (DFT_REFRESH_AGE) = 0                          0
 Default maintained table types for opt (DFT_MTTB_TYPES) = SYSTEM                     SYSTEM
 Number of frequent values retained     (NUM_FREQVALUES) = 10                         10
 Number of quantiles retained            (NUM_QUANTILES) = 20                         20

 Decimal floating point rounding mode  (DECFLT_ROUNDING) = ROUND_HALF_EVEN            ROUND_HALF_EVEN

 DECIMAL arithmetic mode                (DEC_ARITHMETIC) =

 Backup pending                                          = NO

 All committed transactions have been written to disk    = NO
 Rollforward pending                                     = NO
 Restore pending                                         = NO

 Upgrade pending                                         = NO                         NO

 Multi-page file allocation enabled                      = YES

 Log retain for recovery status                          = NO
 User exit for logging status                            = NO

 Self tuning memory                    (SELF_TUNING_MEM) = ON (Active)                ON
 Size of database shared memory (4KB)  (DATABASE_MEMORY) = AUTOMATIC(942222)          AUTOMATIC(942222)
 Database memory threshold               (DB_MEM_THRESH) = 100                        100
 Max storage for lock list (4KB)              (LOCKLIST) = AUTOMATIC(15360)           AUTOMATIC(15360)
 Percent. of lock lists per application       (MAXLOCKS) = AUTOMATIC(98)              AUTOMATIC(98)
 Package cache size (4KB)                   (PCKCACHESZ) = AUTOMATIC(4711)            AUTOMATIC(4711)
 Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = AUTOMATIC(56784)           AUTOMATIC(56784)
 Sort list heap (4KB)                         (SORTHEAP) = AUTOMATIC(11356)           AUTOMATIC(11356)

 Database heap (4KB)                            (DBHEAP) = AUTOMATIC(5027)            AUTOMATIC(5027)
 Catalog cache size (4KB)              (CATALOGCACHE_SZ) = 300                        300
 Log buffer size (4KB)                        (LOGBUFSZ) = 2150                       2150
 Utilities heap size (4KB)                (UTIL_HEAP_SZ) = AUTOMATIC(61243)           AUTOMATIC(61243)
 SQL statement heap (4KB)                     (STMTHEAP) = AUTOMATIC(8192)            AUTOMATIC(8192)
 Default application heap (4KB)             (APPLHEAPSZ) = AUTOMATIC(256)             AUTOMATIC(256)
 Application Memory Size (4KB)             (APPL_MEMORY) = AUTOMATIC(40000)           AUTOMATIC(40000)
 Statistics heap size (4KB)               (STAT_HEAP_SZ) = AUTOMATIC(4384)            AUTOMATIC(4384)

 Interval for checking deadlock (ms)         (DLCHKTIME) = 10000                      10000
 Lock timeout (sec)                        (LOCKTIMEOUT) = -1                         -1

 Changed pages threshold                (CHNGPGS_THRESH) = 80                         80
 Number of asynchronous page cleaners   (NUM_IOCLEANERS) = AUTOMATIC(4)               AUTOMATIC(4)
 Number of I/O servers                   (NUM_IOSERVERS) = AUTOMATIC(12)              AUTOMATIC(12)
 Sequential detect flag                      (SEQDETECT) = YES                        YES
 Default prefetch size (pages)         (DFT_PREFETCH_SZ) = AUTOMATIC                  AUTOMATIC

 Track modified pages                         (TRACKMOD) = NO                         NO

 Default number of containers                            = 1                          1
 Default tablespace extentsize (pages)   (DFT_EXTENT_SZ) = 32                         32

 Max number of active applications            (MAXAPPLS) = AUTOMATIC(40)              AUTOMATIC(40)
 Average number of active applications       (AVG_APPLS) = AUTOMATIC(1)               AUTOMATIC(1)
 Lifetime of cached credentials   (AUTHN_CACHE_DURATION) = 3                          3
 Max number of users in the cache    (AUTHN_CACHE_USERS) = 0                          0
 Max DB files open per database               (MAXFILOP) = 61440                      61440

 Active log space disk capacity (MB)      (LOG_DISK_CAP) = 0                          0
 Log file size (4KB)                         (LOGFILSIZ) = 1024                       6
 Number of primary log files                (LOGPRIMARY) = 5                          3
 Number of secondary log files               (LOGSECOND) = 1                          1
 Changed path to log files                  (NEWLOGPATH) =
 Path to log files                                       = /home/db2inst1/db2inst1/NODE0000/SQL00002/LOGSTREAM0000/ /home/db2inst1/db2inst1/NODE0000/SQL00002/LOGSTREAM0000/
 Overflow log path                     (OVERFLOWLOGPATH) =
 Mirror log path                         (MIRRORLOGPATH) =
 First active log file                                   =
 Block log on disk full                (BLK_LOG_DSK_FUL) = NO                         NO
 Block non logged operations            (BLOCKNONLOGGED) = NO                         NO
 Percent max primary log space by transaction  (MAX_LOG) = 0                          0
 Num. of active log files for 1 active UOW(NUM_LOG_SPAN) = 0                          0

 Percent log file reclaimed before soft chckpt (SOFTMAX) = 0                          0
 Target for oldest page in LBP       (PAGE_AGE_TRGT_MCR) = 240                        240

 HADR database role                                      = STANDARD                   STANDARD
 HADR local host name                  (HADR_LOCAL_HOST) =
 HADR local service name                (HADR_LOCAL_SVC) =
 HADR remote host name                (HADR_REMOTE_HOST) =
 HADR remote service name              (HADR_REMOTE_SVC) =
 HADR instance name of remote server  (HADR_REMOTE_INST) =
 HADR timeout value                       (HADR_TIMEOUT) = 120                        120
 HADR target list                     (HADR_TARGET_LIST) =
 HADR log write synchronization mode     (HADR_SYNCMODE) = NEARSYNC                   NEARSYNC
 HADR peer window duration (seconds)  (HADR_PEER_WINDOW) = 0                          0

 First log archive method                 (LOGARCHMETH1) = OFF                        OFF
 Archive compression for logarchmeth1    (LOGARCHCOMPR1) = OFF                        OFF
 Options for logarchmeth1                  (LOGARCHOPT1) =
 Second log archive method                (LOGARCHMETH2) = OFF                        OFF
 Archive compression for logarchmeth2    (LOGARCHCOMPR2) = OFF                        OFF
 Options for logarchmeth2                  (LOGARCHOPT2) =
 Failover log archive path                (FAILARCHPATH) =
 Number of log archive retries on error   (NUMARCHRETRY) = 5                          5
 Log archive retry Delay (secs)         (ARCHRETRYDELAY) = 20                         20
 Vendor options                              (VENDOROPT) =

 Auto restart enabled                      (AUTORESTART) = ON                         ON
 Index re-creation time and redo index build  (INDEXREC) = SYSTEM                     SYSTEM (RESTART)
 Log pages during index build            (LOGINDEXBUILD) = OFF                        OFF
 Default number of loadrec sessions    (DFT_LOADREC_SES) = 1                          1
 Number of database backups to retain   (NUM_DB_BACKUPS) = 12                         12
 Recovery history retention (days)     (REC_HIS_RETENTN) = 90                         90
 Auto deletion of recovery objects    (AUTO_DEL_REC_OBJ) = OFF                        OFF

 TSM management class                    (TSM_MGMTCLASS) =
 TSM node name                            (TSM_NODENAME) =
 TSM owner                                   (TSM_OWNER) =
 TSM password                             (TSM_PASSWORD) =

 Automatic maintenance                      (AUTO_MAINT) = ON                         ON
   Automatic database backup            (AUTO_DB_BACKUP) = OFF                        OFF
   Automatic table maintenance          (AUTO_TBL_MAINT) = ON                         ON
     Automatic runstats                  (AUTO_RUNSTATS) = ON                         ON
       Real-time statistics            (AUTO_STMT_STATS) = ON                         ON
       Statistical views              (AUTO_STATS_VIEWS) = OFF                        OFF
       Automatic sampling                (AUTO_SAMPLING) = ON                         ON
       Automatic column group statistics (AUTO_CG_STATS) = OFF                        OFF
     Automatic reorganization               (AUTO_REORG) = OFF                        OFF

 Auto-Revalidation                          (AUTO_REVAL) = DEFERRED                   DEFERRED

 Currently Committed                        (CUR_COMMIT) = ON                         ON
 CHAR output with DECIMAL input        (DEC_TO_CHAR_FMT) = NEW                        NEW
 Enable XML Character operations        (ENABLE_XMLCHAR) = YES                        YES
 Enforce Constraint                  (DDL_CONSTRAINT_DEF) = YES                        YES
 Enable row compression by default  (DDL_COMPRESSION_DEF) = NO                         NO
 Replication site ID                      (REPL_SITE_ID) = 0                          0
 WLM Collection Interval (minutes)     (WLM_COLLECT_INT) = 0                          0

 Monitor Collect Settings
 Request metrics                       (MON_REQ_METRICS) = BASE                       BASE
 Activity metrics                      (MON_ACT_METRICS) = BASE                       BASE
 Object metrics                        (MON_OBJ_METRICS) = EXTENDED                   EXTENDED
 Routine data                             (MON_RTN_DATA) = NONE                       NONE
   Routine executable list            (MON_RTN_EXECLIST) = OFF                        OFF
 Unit of work events                      (MON_UOW_DATA) = NONE                       NONE
   UOW events with package list        (MON_UOW_PKGLIST) = OFF                        OFF
   UOW events with executable list    (MON_UOW_EXECLIST) = OFF                        OFF
 Lock timeout events                   (MON_LOCKTIMEOUT) = NONE                       NONE
 Deadlock events                          (MON_DEADLOCK) = WITHOUT_HIST               WITHOUT_HIST
 Lock wait events                         (MON_LOCKWAIT) = NONE                       NONE
 Lock wait event threshold               (MON_LW_THRESH) = 5000000                    5000000

 Number of package list entries         (MON_PKGLIST_SZ) = 32                         32
 Lock event notification level         (MON_LCK_MSG_LVL) = 1                          1

 SMTP Server                               (SMTP_SERVER) =
 SQL conditional compilation flags         (SQL_CCFLAGS) =
 Section actuals setting               (SECTION_ACTUALS) = NONE                       NONE
 Connect procedure                        (CONNECT_PROC) =
 Adjust temporal SYSTEM_TIME period (SYSTIME_PERIOD_ADJ) = NO                         NO
 Log DDL Statements                      (LOG_DDL_STMTS) = NO                         NO
 Log Application Information             (LOG_APPL_INFO) = NO                         NO
 Default data capture on new Schemas   (DFT_SCHEMAS_DCC) = NO                         NO
 HADR spool log data limit (4KB)      (HADR_SPOOL_LIMIT) = AUTOMATIC(0)               AUTOMATIC(0)
 HADR log replay delay (seconds)     (HADR_REPLAY_DELAY) = 0                          0
 Strict I/O for EXTBL_LOCATION         (EXTBL_STRICT_IO) = NO                         NO
 Allowed paths for external tables      (EXTBL_LOCATION) = /home/db2inst1             /home/db2inst1
 Default table organization              (DFT_TABLE_ORG) = ROW                        ROW
 Default string units                     (STRING_UNITS) = SYSTEM                     SYSTEM
 National character string mapping       (NCHAR_MAPPING) = CHAR_CU32                  CHAR_CU32
 Database is in write suspend state                      = NO
 Extended row size support             (EXTENDED_ROW_SZ) = ENABLE                     ENABLE
 Encryption Library for Backup                 (ENCRLIB) =
 Encryption Options for Backup                (ENCROPTS) =
 Encrypted database                                      = NO                         NO
 Procedural language stack trace        (PL_STACK_TRACE) = NONE                       NONE
 HADR SSL certificate label             (HADR_SSL_LABEL) =
 Target agent load per CPU core    (WLM_AGENT_LOAD_TRGT) = AUTOMATIC(14)              AUTOMATIC(14)
 WLM admission control enabled      (WLM_ADMISSION_CTRL) = NO                         NO
 Allocated share of CPU resources       (WLM_CPU_SHARES) = 1000                       1000
 CPU share behavior (hard/soft)     (WLM_CPU_SHARE_MODE) = HARD                       HARD
 Maximum allowable CPU utilization (%)   (WLM_CPU_LIMIT) = 0                          0

db2inst1@shahuang-lt:~/course_file/ddl$

检查配置

db2inst1@shahuang-lt:~/course_file/ddl$ db2pd -db musicdb -dbcfg | grep "LOG"
CATALOGCACHE_SZ (4KB)          300                  300
LOGBUFSZ (4KB)                 2150                 2150
LOGFILSIZ (4KB)                1024                 6
LOGPRIMARY                     5                    3
LOGSECOND                      1                    1
NEWLOGPATH (memory)
NEWLOGPATH (disk)
Path to log files (memory)     /home/db2inst1/db2inst1/NODE0000/SQL00002/LOGSTREAM0000/
OVERFLOWLOGPATH (memory)
OVERFLOWLOGPATH (disk)
MIRRORLOGPATH (memory)
MIRRORLOGPATH (disk)
First active log file          S0000000.LOG         S0000000.LOG
BLK_LOG_DSK_FUL                NO                   NO
BLOCKNONLOGGED                 NO                   NO
MAX_LOG                        0                    0
NUM_LOG_SPAN                   0                    0
LOGARCHMETH1 (memory)          OFF
LOGARCHMETH1 (disk)            OFF
LOGARCHCOMPR1                  OFF                  OFF
LOGARCHOPT1
LOGARCHMETH2 (memory)          OFF
LOGARCHMETH2 (disk)            OFF
LOGARCHCOMPR2                  OFF                  OFF
LOGARCHOPT2
LOGINDEXBUILD                  0                    0
LOG_DDL_STMTS                  NO                   NO
LOG_APPL_INFO                  NO                   NO
LOG_DISK_CAP                   0                    0
db2inst1@shahuang-lt:~/course_file/ddl$

尝试触发log打印错误

db2inst1@shahuang-lt:~/course_file/ddl$ db2 force application all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.

db2inst1@shahuang-lt:~/course_file/ddl$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$ db2 connect to musicdb

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.4.0
 SQL authorization ID   = DB2INST1
 Local database alias   = MUSICDB

db2inst1@shahuang-lt:~/course_file/ddl$ db2pd -db musicdb -logs

Database Member 0 -- Database MUSICDB -- Active -- Up 0 days 00:00:13 -- Date 2024-05-25-11.26.53.822233

Logs:
Current Log Number            0
Pages Written                 0
Cur Commit Disk Log Reads     0
Cur Commit Total Log Reads    0
Method 1 Archive Status       n/a
Method 1 Next Log to Archive  n/a
Method 1 First Failure        n/a
Method 2 Archive Status       n/a
Method 2 Next Log to Archive  n/a
Method 2 First Failure        n/a
Extraction Status             n/a
Current Log to Extract        n/a
Log Chain ID                  0
Current LSO                   78226593
Current LSN                   0x000000000005913F

Address            StartLSN         StartLSO             State      Size       Pages      Filename
0x00007F2B2FA5F1B8 0000000000000000 78226593             0x00000000 6          6          S0000000.LOG
0x00007F2B2FD10DD8 0000000000000000 78251049             0x00000000 6          6          S0000001.LOG
0x00007F2BDDF91E78 0000000000000000 78275505             0x00000000 6          6          S0000002.LOG
db2inst1@shahuang-lt:~/course_file/ddl$ db2 -tvf create_temp_stock.sql
set current schema music
DB20000I  The SQL command completed successfully.

create table temp_stock (ITEMNO SMALLINT NOT NULL , TYPE CHAR(1) NOT NULL , PRICE DECIMAL(5,2) NOT NULL WITH DEFAULT  , QTY INTEGER NOT NULL WITH DEFAULT) in userspace1
DB20000I  The SQL command completed successfully.

db2inst1@shahuang-lt:~/course_file/ddl$ db2 +C -tvf stock_insert.sql
set current schema music
DB20000I  The SQL command completed successfully.

insert into temp_stock select itemno,type,price,qty  from stock where itemno < 100
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0964C  The transaction log for the database is full.  SQLSTATE=57011

insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0964C  The transaction log for the database is full.  SQLSTATE=57011

insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0964C  The transaction log for the database is full.  SQLSTATE=57011

delete from temp_stock
SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result of a
query is an empty table.  SQLSTATE=02000

db2inst1@shahuang-lt:~/course_file/ddl$

增大log空间

db2inst1@shahuang-lt:~/course_file/ddl$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$ db2 connect to musicdb

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.4.0
 SQL authorization ID   = DB2INST1
 Local database alias   = MUSICDB

db2inst1@shahuang-lt:~/course_file/ddl$ db2 -tvf increase_logs.ddl
update db cfg for musicdb using logfilsiz 1000 logsecond 10
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.

force application all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.


db2inst1@shahuang-lt:~/course_file/ddl$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$

rerun

修改配置后,rerun成功了

db2inst1@shahuang-lt:~/course_file/ddl$ db2 connect to musicdb

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.4.0
 SQL authorization ID   = DB2INST1
 Local database alias   = MUSICDB

db2inst1@shahuang-lt:~/course_file/ddl$ db2 +C -tvf stock_
stock_insert.sql     stock_select.sql     stock_select_rs.sql  stock_update.sql
stock_insert2.sql    stock_select_cs.sql  stock_select_ur.sql
db2inst1@shahuang-lt:~/course_file/ddl$ db2 +C -tvf stock_insert.sql
set current schema music
DB20000I  The SQL command completed successfully.

insert into temp_stock select itemno,type,price,qty  from stock where itemno < 100
DB20000I  The SQL command completed successfully.

insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB20000I  The SQL command completed successfully.

insert into temp_stock select itemno,type,price,qty from stock where itemno < 100
DB20000I  The SQL command completed successfully.

delete from temp_stock
DB20000I  The SQL command completed successfully.

db2inst1@shahuang-lt:~/course_file/ddl$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$

使用存档日志进行数据库数据恢复

配置使能存档日志

正常情况下,默认的log是循环log(circular),我们可以通过配置修改为存档日志(achived)。
执行命令报错

db2inst1@shahuang-lt:~/course_file/ddl$ db2 UPDATE DATABASE CONFIGURATION USING logarchmeth1 "DISK:/home/db2inst1/archive" logprimary 3 logsecond 10 logfilsiz 1000 LOGINDEXBUILD OFF
SQL5099N  The value "/home/db2inst1/archive" indicated by the database
configuration parameter "LOGARCHMETH1" is not valid, reason code "2".
SQLSTATE=08004

找到原因,这个文件夹没有创建,创建后再执行,成功。

db2inst1@shahuang-lt:~/course_file/ddl$ mkdir /home/db2inst1/archive
db2inst1@shahuang-lt:~/course_file/ddl$ db2 UPDATE DATABASE CONFIGURATION USING logarchmeth1 "DISK:/home/db2inst1/archive" logprimary 3 logsecond 10 logfilsiz 1000 LOGINDEXBUILD OFF
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
db2inst1@shahuang-lt:~/course_file/ddl$
db2inst1@shahuang-lt:~/course_file/ddl$ db2 connect reset
DB20000I  The SQL command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$ db2 force application all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.

db2inst1@shahuang-lt:~/course_file/ddl$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$ db2 deactivate database musicdb
DB20000I  The DEACTIVATE DATABASE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$

同样原因执行失败,创建文件夹后成功

db2inst1@shahuang-lt:~/course_file/ddl$ db2 BACKUP DATABASE MUSICDB TO /home/db2inst1/backup COMPRESS
SQL2036N  The path for the file, named pipe, or device "/home/db2inst1/backup"
is not valid.
db2inst1@shahuang-lt:~/course_file/ddl$ mkdir /home/db2inst1/backup
db2inst1@shahuang-lt:~/course_file/ddl$ db2 BACKUP DATABASE MUSICDB TO /home/db2inst1/backup COMPRESS

Backup successful. The timestamp for this backup image is : 20240525172034

db2inst1@shahuang-lt:~/course_file/ddl$

修改数据库

db2inst1@shahuang-lt:~/course_file/ddl$ db2 connect to musicdb

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.4.0
 SQL authorization ID   = DB2INST1
 Local database alias   = MUSICDB

db2inst1@shahuang-lt:~/course_file/ddl$ db2 -tvf stock_insert2.sql
set current schema music
DB20000I  The SQL command completed successfully.

insert into temp_stock select itemno,type,price,qty from stock where TYPE = 'C'
DB20000I  The SQL command completed successfully.

SELECT COUNT(*) AS CURRENT_SIZE, CURRENT DATE , CURRENT TIME FROM temp_stock

CURRENT_SIZE 2          3
------------ ---------- --------
         518 05/25/2024 17:27:02

  1 record(s) selected.


db2inst1@shahuang-lt:~/course_file/ddl$

再执行一次来创建更多的改动和日志

db2inst1@shahuang-lt:~/course_file/ddl$ db2 connect to musicdb

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.4.0
 SQL authorization ID   = DB2INST1
 Local database alias   = MUSICDB

db2inst1@shahuang-lt:~/course_file/ddl$ db2 -tvf stock_insert2.sql
set current schema music
DB20000I  The SQL command completed successfully.

insert into temp_stock select itemno,type,price,qty from stock where TYPE = 'C'
DB20000I  The SQL command completed successfully.

SELECT COUNT(*) AS CURRENT_SIZE, CURRENT DATE , CURRENT TIME FROM temp_stock

CURRENT_SIZE 2          3
------------ ---------- --------
         518 05/25/2024 17:27:02

  1 record(s) selected.


db2inst1@shahuang-lt:~/course_file/ddl$

恢复数据到指定的时间点

db2inst1@shahuang-lt:~/course_file/ddl$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$ db2 force application all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.

db2inst1@shahuang-lt:~/course_file/ddl$ db2 recover database musicdb to 2024-05-25-17.27.02

                                 Rollforward Status

 Input database alias                   = musicdb
 Number of members have returned status = 1

 Member ID                              = 0
 Rollforward status                     = not pending
 Next log file to be read               =
 Log files processed                    =  -
 Last committed transaction             = 2024-05-25-17.27.02.000000 Local

DB20000I  The RECOVER DATABASE command completed successfully.
db2inst1@shahuang-lt:~/course_file/ddl$ db2 connect to musicdb

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.4.0
 SQL authorization ID   = DB2INST1
 Local database alias   = MUSICDB

db2inst1@shahuang-lt:~/course_file/ddl$ db2 "select count(*) from music.temp_stock"

1
-----------
        518

  1 record(s) selected.

db2inst1@shahuang-lt:~/course_file/ddl$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
posted @ 2024-05-25 11:34  HuangShawn  阅读(23)  评论(0)    收藏  举报