DB2数据库创建数据库操作过程

2018-06-17 20:06:36来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

/* 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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:深入学习Redis(1):Redis内存模型

下一篇:PostgreSQL如何实现类似Oracle中的家族树功能