DB2创建库 数据恢复


例:
数据库:PRODB2
用户 :DB2ADMIN/DB2ADMIN
备份库路径:D:/bank

一.恢复数据库
1.启动数据库
运行-》db2cmd
-》db2
Db2=>start db manager
Db2=>force application all
Db2=>drop database tjns

db2 =>
2.创建数据库
CREATE DATABASE ppdev0309 ON D:\ USING CODESET GBK TERRITORY CN

3.连接数据库
connect to ppdev0309 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 'D:\DB2\NODE0000\ppdev0309\NNC_DATA01' 198144 ) 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\ppdev0309\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\ppdev0309\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 'D:\DB2\NODE0000\ppdev0309\NNC_INDEX01' 262144 ) 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\ppdev0309\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\ppdev0309\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 'D:\DB2\NODE0000\ppdev0309\usertemp' 162144 ) 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 'D:\DB2\NODE0000\ppdev0309\tempspace2' 65536 ) 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 PPDEV0309 WITH GRANT OPTION;
GRANT USE OF TABLESPACE NNC_DATA02 TO USER PPDEV0309 WITH GRANT OPTION;
GRANT USE OF TABLESPACE NNC_DATA03 TO USER PPDEV0309 WITH GRANT OPTION;
GRANT USE OF TABLESPACE NNC_INDEX01 TO USER PPDEV0309 WITH GRANT OPTION;
GRANT USE OF TABLESPACE NNC_INDEX02 TO USER PPDEV0309 WITH GRANT OPTION;
GRANT USE OF TABLESPACE NNC_INDEX03 TO USER PPDEV0309 WITH GRANT OPTION;
GRANT USE OF TABLESPACE USERTEMP TO USER PPDEV0309 WITH GRANT OPTION;

5.数据库优化 ---导库不用做
update dbm cfg using aslheapsz 1024;
update dbm cfg using sheapthres 40000;
update dbm cfg using maxagents 300;
update dbm cfg using NUM_POOLAGENTS 100;
update database configuration for PRODB2 using DBHEAP 10240;
update database configuration for PRODB2 using logbufsz 2048;
update database configuration for PRODB2 using CATALOGCACHE_SZ 3072;
update database configuration for PRODB2 using locklist 10240;
update database configuration for PRODB2 using app_ctl_heap_sz 4096;
update database configuration for PRODB2 using sortheap 4096;
update database configuration for PRODB2 using stmtheap 3072;
update database configuration for PRODB2 using applheapsz 16384;
update database configuration for PRODB2 using pckcachesz 20480;
update database configuration for PRODB2 using maxlocks 18;
update database configuration for PRODB2 using NUM_IOCLEANERS 8;
update database configuration for PRODB2 using NUM_IOSERVERS 5;
update database configuration for PRODB2 using MAXAPPLS 300;
update database configuration for PRODB2 using AVG_APPLS 200;
update database configuration for PRODB2 using logfilsiz 204800;
update database configuration for PRODB2 using logprimary 50;
update database configuration for PRODB2 using logsecond 150;
update database configuration for PRODB2 using MINCOMMIT 2;
update database configuration for PRODB2 using BLK_LOG_DSK_FUL OFF;

6.修改用户名
db2move.lst 中把原来的用户名都改成db2admin (为大写,AIX严格控制)
credb.sql 中把原来的用户名都改成db2admin (为大写,AIX严格控制)
将文件头上的数据库联接命令改成

CONNECT TO PRODB2 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 PPDEV0309 user db2admin using admin
reorgchk update statistics on table all

10.导出数据库 cmd控制台
connect to PPDEV0309;
--导出表结构
db2look -d PPDEV0309 -u db2admin -e -o credb.sql -i db2admin -w db2admin
--导出表数据
db2move protest export -tc db2admin -u db2admin -p db2admin>export.sql

import from D:\20150101\tab1.ixf of del insert into rm_port

11.断开连接
disconnect PRODB2

12.删除数据库
删除数据库
用运行-》db2cmd
db2 drop db 数据库名称

13.重启服务器
db2stop force
db2start

posted on 2017-08-31 14:30  奇天异下  阅读(530)  评论(0编辑  收藏  举报

导航