Heim >Datenbank >MySQL-Tutorial >DB2创建数据库示例

DB2创建数据库示例

WBOY
WBOYOriginal
2016-06-07 17:18:561383Durchsuche

DB2创建数据库示例,做完离线备份后,建议做一次在线备份(不确定是不是必须,但是正好可以测试是否能在线备份)在做以上操作时,

1    创建连接用户
mkuser id=1028 pgrp=db2user1 groups=db2user1 home=/home/fmusx core=-1 data=491519 stack=32767 rss=-1 fsize=-1 fmusx

2    创建开发数据库
db2 create database SX3    AUTOMATIC STORAGE YES ON /db2fs/sx2data DBPATH ON /db2fs/sx2  USING CODESET GBK TERRITORY CN

3    创建缓冲池
db2 create bufferpool SX_16K IMMEDIATE SIZE AUTOMATIC PAGESIZE 16K
db2 create bufferpool SX_32K IMMEDIATE SIZE AUTOMATIC PAGESIZE 32K

4    创建系统表空间
db2 CREATE SYSTEM TEMPORARY TABLESPACE TEMPSPACE16 PAGESIZE 16K BUFFERPOOL SX_16K NO FILE SYSTEM CACHING
db2 CREATE SYSTEM TEMPORARY TABLESPACE TEMPSPACE32 PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING
db2 CREATE USER TEMPORARY TABLESPACE temp16k PAGESIZE 16K BUFFERPOOL SX_16K NO FILE SYSTEM CACHING
db2 CREATE USER TEMPORARY TABLESPACE temp32k PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING

db2 GRANT USE OF TABLESPACE "temp16k" TO  fmusx
db2 GRANT USE OF TABLESPACE "temp32k" TO  fmusx

5    创建用户表空间
db2 create LARGE tablespace FMUSX32K_D PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING
db2 create LARGE tablespace FMUSX32K_I PAGESIZE 32K BUFFERPOOL SX_32K NO FILE SYSTEM CACHING

db2 GRANT USE OF TABLESPACE FMUSX32K_D TO  fmusx
db2 GRANT USE OF TABLESPACE FMUSX32K_I TO  fmusx

6    删除默认用户表空间
$ db2 drop tablespace USERSPACE1
DB20000I  The SQL command completed successfully.

7  设置归档模式

db2 update db cfg using LOGFILSIZ 102400
db2 update db cfg using LOGPRIMARY 20
db2 update db cfg using LOGSECOND 50
db2 update db cfg using LOGARCHMETH1 disk:/db2fs/db2backup/archive_log/sx3/ immediate

$ db2 update db cfg using LOGFILSIZ 102400
db2 update db cfg using LOGPRIMARY 20
db2 update db cfg using LOGSECOND 50
db2 update db cfg using LOGARCHMETH1 disk:/db2fs/db2backup/archive_log/sx3/ immediate
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  Database must be deactivated and reactivated before the changes to
one or more of the configuration parameters will be effective.
$ db2 update db cfg using LOGPRIMARY 20
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  Database must be deactivated and reactivated before the changes to
one or more of the configuration parameters will be effective.
$ db2 update db cfg using LOGSECOND 50
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
$ db2 update db cfg using LOGARCHMETH1 disk:/db2fs/db2backup/archive_log/sx3/ immediate
DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W  Database must be deactivated and reactivated before the changes to
one or more of the configuration parameters will be effective.

注:a.归档目录一定要先创建,否则会报错

    b.除LOGSECOND外,,其他参数都需要重启数据库才能生效(或者直接重启instance)

8.  备份数据库

将数据库修改为归档模式后,必须先离线备份数据库,否则整个数据库的状态将为backup pending,无法访问。

$ db2 backup db sx3 to /db2fs/db2backup/sx3backup

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

备注:做完离线备份后,建议做一次在线备份(不确定是不是必须,但是正好可以测试是否能在线备份)

$ db2 backup db sx3 online to /db2fs/db2backup/sx3backup include logs

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

备注:在做以上操作时,为防止其他非本地应用连接数据库,可以将instance的协议注销,类似于Oracle中关闭监听器的操作。

$ db2set -all
[i] DB2_DATABASE_CF_MEMORY=-1
[i] DB2_COMPATIBILITY_VECTOR=ORA
[i] DB2RSHCMD=/bin/ssh
[i] DB2COUNTRY=86
[i] DB2COMM=TCPIP
[i] DB2CODEPAGE=1386
[i] DB2AUTOSTART=NO
[g] DB2SYSTEM=SXYCDBM0
[g] DB2INSTDEF=db2sdin1

关闭连接端口

$ db2set DB2COMM=

$ db2set -all
[i] DB2_DATABASE_CF_MEMORY=-1
[i] DB2_COMPATIBILITY_VECTOR=ORA
[i] DB2RSHCMD=/bin/ssh
[i] DB2COUNTRY=86
[i] DB2CODEPAGE=1386
[i] DB2AUTOSTART=NO
[g] DB2SYSTEM=SXYCDBM0
[g] DB2INSTDEF=db2sdin1

备注:这些有“[i]”标识的参数为实例级参数,需要重启实例才能生效

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn