/* author simon */ 例:資料庫:NCDB2用戶 :DB2ADMIN/DB2ADMIN備份庫路徑:D:/bank 一.恢複數據庫1.啟動資料庫運行-》db2cmd-》db2Db2=>start db managerDb2=>force application allDb2=>drop ...
/* author simon */
例:
資料庫:NCDB2
用戶 :DB2ADMIN/DB2ADMIN
備份庫路徑:D:/bank
一.恢複數據庫
1.啟動資料庫
運行-》db2cmd
-》db2
Db2=>start db manager
Db2=>force application all
Db2=>drop database tjns
db2 =>
2.創建資料庫
db2 CREATE DATABASE ftpese ON E:\ USING CODESET GBK TERRITORY CN
3.連接資料庫
connect to ftmdev63 user DB2ADMIN using db2admin
3.創建緩衝池/表空間
db2 CREATE Bufferpool BUFFER4 SIZE 102400 PAGESIZE 4K
db2 CREATE Bufferpool BUFFER16 SIZE 38400 PAGESIZE 16K
db2 CREATE REGULAR TABLESPACE NNC_DATA01 PAGESIZE 16 K MANAGED BY DATABASE USING ( FILE 'E:\DB2\NODE0000\FTPESE\NNC_DATA01' 2G ) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.18 BUFFERPOOL BUFFER16 DROPPED TABLE RECOVERY OFF
db2 CREATE REGULAR TABLESPACE NNC_DATA02 PAGESIZE 16 K MANAGED BY DATABASE USING ( FILE 'D:\DB2\NODE0000\xhsh_ftp\NNC_DATA02' 105536 ) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.18 BUFFERPOOL BUFFER16 DROPPED TABLE RECOVERY OFF
db2 CREATE REGULAR TABLESPACE NNC_DATA03 PAGESIZE 16 K MANAGED BY DATABASE USING ( FILE 'D:\DB2\NODE0000\xhsh_ftp\NNC_DATA03' 105536 ) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.14 BUFFERPOOL BUFFER16 DROPPED TABLE RECOVERY OFF
db2 CREATE REGULAR TABLESPACE NNC_INDEX01 PAGESIZE 4 K MANAGED BY DATABASE USING ( FILE 'E:\DB2\NODE0000\FTPESE\NNC_INDEX01' 2G ) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.18 BUFFERPOOL BUFFER4 DROPPED TABLE RECOVERY OFF
db2 CREATE REGULAR TABLESPACE NNC_INDEX02 PAGESIZE 4 K MANAGED BY DATABASE USING ( FILE 'D:\DB2\NODE0000\xhsh_ftp\NNC_INDEX02' 202144) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.18 BUFFERPOOL BUFFER4 DROPPED TABLE RECOVERY OFF
db2 CREATE REGULAR TABLESPACE NNC_INDEX03 PAGESIZE 4 K MANAGED BY DATABASE USING ( FILE 'D:\DB2\NODE0000\xhsh_ftp\NNC_INDEX03' 262144 ) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.18 BUFFERPOOL BUFFER4 DROPPED TABLE RECOVERY OFF
db2 CREATE USER TEMPORARY TABLESPACE USERTEMP PAGESIZE 16K MANAGED BY database USING ( FILE 'E:\DB2\NODE0000\FTPESE\USERTEMP' 1G ) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.18 BUFFERPOOL BUFFER16
db2 CREATE SYSTEM TEMPORARY TABLESPACE TEMPSPACE2 PAGESIZE 16 K MANAGED BY database USING ( FILE 'E:\DB2\NODE0000\FTPESE\TEMPSPACE2' 1G ) AUTORESIZE YES EXTENTSIZE 32 OVERHEAD 12.67 PREFETCHSIZE 32 TRANSFERRATE 0.18 BUFFERPOOL BUFFER16
4.賦值許可權
GRANT DBADM, CREATETAB, BINDADD, CONNECT, CREATE_NOT_FENCED_ROUTINE, IMPLICIT_SCHEMA, LOAD, CREATE_EXTERNAL_ROUTINE, QUIESCE_CONNECT ON DATABASE TO USER TJNS
GRANT USE OF TABLESPACE NNC_DATA01 TO USER PRPTEST WITH GRANT OPTION
GRANT USE OF TABLESPACE NNC_DATA02 TO USER PRPTEST WITH GRANT OPTION
GRANT USE OF TABLESPACE NNC_DATA03 TO USER PRPTEST WITH GRANT OPTION
GRANT USE OF TABLESPACE NNC_INDEX01 TO USER PRPTEST WITH GRANT OPTION
GRANT USE OF TABLESPACE NNC_INDEX02 TO USER PRPTEST WITH GRANT OPTION
GRANT USE OF TABLESPACE NNC_INDEX03 TO USER PRPTEST WITH GRANT OPTION
GRANT USE OF TABLESPACE USERTEMP TO USER PRPTEST WITH GRANT OPTION
5.資料庫優化 ---導庫不用做
db2 update dbm cfg using aslheapsz 1024
db2 update dbm cfg using sheapthres 40000
db2 update dbm cfg using maxagents 300
db2 update dbm cfg using NUM_POOLAGENTS 100
db2 update database configuration for ftpese using DBHEAP 10240
db2 update database configuration for ftpese using logbufsz 2048
db2 update database configuration for ftpese using CATALOGCACHE_SZ 3072
db2 update database configuration for ftpese using locklist 10240
db2 update database configuration for ftpese using app_ctl_heap_sz 4096
db2 update database configuration for ftpese using sortheap 4096
db2 update database configuration for ftpese using stmtheap 3072
db2 update database configuration for ftpese using applheapsz 16384
db2 update database configuration for ftpese using pckcachesz 20480
db2 update database configuration for ftpese using maxlocks 18
db2 update database configuration for ftpese using NUM_IOCLEANERS 8
db2 update database configuration for ftpese using NUM_IOSERVERS 5
db2 update database configuration for ftpese using MAXAPPLS 300
db2 update database configuration for ftpese using AVG_APPLS 200
db2 update database configuration for ftpese using logfilsiz 204800
db2 update database configuration for ftpese using logprimary 50
db2 update database configuration for ftpese using logsecond 150
db2 update database configuration for ftpese using MINCOMMIT 2
db2 update database configuration for ftpese using BLK_LOG_DSK_FUL NO
6.修改用戶名
db2move.lst 中把原來的用戶名都改成db2admin (為大寫,AIX嚴格控制)
credb.sql 中把原來的用戶名都改成db2admin (為大寫,AIX嚴格控制)
將文件頭上的資料庫聯接命令改成
CONNECT TO NCDB2 USER DB2INST1 USING DB2INST1
7.拆分表結構
以foreign keys 查詢區分,將credb.sql拆分成credb1.sql(表和索引),credb2.sql(外鍵和視圖)。
8.導入庫 cmd控制台
方式1:
--導入庫數據(load 方式需要先導入表和索引,import不需要)
db2move TJNS import -u DB2ADMIN -p db2admin>import.log
方式2:
--導入表和索引(需要先連接connect資料庫)
db2 -tvf credb1.sql > credb1.log
--導入庫數據(load 方式需要先導入表和索引,import不需要)
db2move TJNS load -u DB2ADMIN -p db2admin>load.log
--導入外鍵和視圖
db2 -tvf credb2.sql > credb2.log
9.做資料庫整理
--查詢資料庫表是否有掛起
select tabschema,tabname from syscat.tables where status='C'
--如果有,對錶進行解決
set INTEGRITY for db2inst1.BD_DEFDOCLIST IMMEDIATE CHECKED
--也可以對整表和庫進行reorgchk整理
--分析單張表 :
runstats on table db2inst1.gl_detail with distribution and detailed indexes all
--分析整個用戶下麵所有表:
connect to prptest user db2admin using admin
reorgchk update statistics on table all
10.導出資料庫 cmd控制台
connect to prptest
--導出表結構
db2look -d prptest -u db2admin -e -o credb.sql -i db2admin -w db2admin
--導出表數據
db2move prptest export -tc db2admin -u db2admin -p db2admin>export.sql
db2 import from dwf_demand_deposit.ixf of ixf insert into dwf_demand_deposit
11.斷開連接
disconnect NCDB2
12.刪除資料庫
刪除資料庫
用運行-》db2cmd
db2 drop db 資料庫名稱
13.重啟伺服器
db2stop force
db2start