- 浏览: 288846 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zkshun12:
请问cas登录成功后返回更多信息的那块儿可不可以配置成多个查询 ...
SSO与CAS -
KillEr_Jok:
写的很好!明白了。谢谢LZ
DB2 Catalog使用及浅析 -
bgolovelc:
struts 利用Jdom 生成xml字符串 -
bgolovelc:
struts 利用Jdom 生成xml字符串
DB2学习文档
(一)DB2的安装说明:
===========================================
[root@fedora home]# ./db2_install
Specify one or more of the following keywords,
separated by spaces, to install DB2 products.
Keyword Product Description
DB2.ESE DB2 Enterprise Server Edition for LINUX
DB2.ADMCL DB2 Administration Client for LINUX
DB2.ADCL DB2 Application Development Client for LINUX
Enter "help" to redisplay product names.
Enter "quit" to exit.
***********************************************************
DB2.ESE
The installation logfile can be found in /tmp/db2_install_log.3439.
db2_install program completed successfully.
(二)实例的相关说明
================================================
(1.)在建立实例前,首先要创建组和用户
[root@fedora home]# groupadd wangzm
[root@fedora home]# groupadd wzm
[root@fedora home]# useradd -g wangzm -d -m /home/wangzm -p 123456 wangzm
[root@fedora home]# useradd -g wzm -m -d /home/wzm -p 123456 wzm
(2.)实例的创建
[root@fedora home]# /opt/IBM/db2/V8.1/instance/db2icrt -u wangzm wzm
DBI1070I Program db2icrt completed successfully.
(3.)数据库的启动
[root@fedora home]# su - wzm
[wzm@fedora ~]$ db2start
05/20/2006 14:27:39 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
(4.)db2的进程
wzm 5981 0.0 14.1 121364 17808 pts/0 S 14:27 0:00 db2sysc
wzm 5987 0.0 13.6 121364 17108 pts/0 S 14:27 0:00 db2ipccm
wzm 5988 0.0 14.1 121364 17808 pts/0 S 14:27 0:00 db2resync
wzm 5989 0.0 12.9 118820 16228 pts/0 S 14:27 0:00 db2srvlst
wzm 5991 0.2 18.8 138584 23760 pts/0 Sl 14:27 0:01 db2hmon ,0,0,0,1,0,0,0,1e014,2,0,1,9fe0,0x11250000,0x11250000,15fc000,98006,2,138017
wzm 6204 0.0 6.0 35996 7624 pts/0 S 14:31 0:00 /home/wzm/sqllib/bin/db2bp 5846A513 5 A
wzm 6285 0.0 14.2 121364 17864 pts/0 S 14:32 0:00 db2agent (idle)
(5.)实例的显示----显示所有的
[wzm@fedora ~]$ db2ilist
db2inst1
dl
qing
wzm
(6.)显示当前的实例
[wzm@fedora ~]$ db2 get instance
The current database manager instance is: wzm
[wzm@fedora ~]$
(7.)删除一个实例
[root@fedora ~]# /opt/IBM/db2/V8.1/instance/db2idrop qing
DBI1070I Program db2idrop completed successfully.
(8.)列出当前实例中有哪些数据库
[wzm@fedora ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = WZMDB
Database name = WZMDB
Local database directory = /home/wzm
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
(三.)数据库的操作说明
===========================================================
(1.) 数据库的创建
[wzm@fedora ~]$ db2 "create database wzmdb"
DB20000I The CREATE DATABASE command completed successfully.
(2.)连接数据库
[wzm@fedora ~]$ db2 connect to wzmdb
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB
()查看表的空间
db2 list tablespaces (show detail)
db2pd -tablespaces -db <数据库名>
(3.)表的创建
[wzm@fedora ~]$ db2 "create table wzmtb (id int,name varchar(30))"
DB20000I The SQL command completed successfully.
(4.) 显示数据库里有那些表
[wzm@fedora ~]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
WZMTB WZM T 2006-05-20-14.46.34.953560
1 record(s) selected.
(5.) 向表里添加数据
[wzm@fedora ~]$ db2 "insert into wzmtb values (1,''wzm'')"
DB20000I The SQL command completed successfully.
(6.)显示表的内容
[wzm@fedora ~]$ db2 "select * from wzmtb"
ID NAME
----------- ------------------------------
1 wzm
1 record(s) selected.
(7.)断开数据库的连接
[wzm@fedora ~]$ db2 disconnect wzmdb
DB20000I The SQL DISCONNECT command completed successfully.
(8.)显示当前数据库连接的有哪些应用程序
[wzm@fedora ~]$ db2 list application
Auth Id Application Appl. Application Id DB # of
Name Handle Name Agents
-------- -------------- ---------- ------------------------------ -------- -----
WZM db2bp 44 *LOCAL.wzm.060520074504 WZMDB 1
(9.)db2的停止
[wzm@fedora ~]$ db2stop
05/20/2006 15:50:47 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
(10.)db2的强制停止
[wzm@fedora ~]$ db2stop force
05/20/2006 16:01:32 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
(五.)db2的参数说明
===============================================
1,
(1.1)db2set -lr...........列出要设置 DB2 概要文件注册表 (针对db2数据库)
(1.2)db2set -all..........列出在服务器上已经设置的所有DB2概要文件注册表 (针对db2数据库)
(1.3)db2 get db cfg ......查看数据库的配置参数,(针对所有数据库都有效)
(1.4)db2 get db cfg for wzmdb ......查看数据库的配置参数,(针对具体的数据库有效)
(1.5)db2 get dbm cfg .............查看数据库管理器的配置参数 (针对具体的实例有效)
2.参数的更改
(2.1) db2 update db cfg using 参数名=参数值
列: db2set DB2COMM=TCPIP
(2.2)显示以更改的参数(说明:参数该完之后需重起数据库才能生效)
列:[wzm@fedora ~]$ db2set
DB2COMM=TCPIP
(2.3)给实例增加端口号
vi/etc/services
DB2_db2inst1 60000/tcp
DB2_db2inst1_1 60001/tcp
DB2_db2inst1_2 60002/tcp
DB2_db2inst1_END 60003/tcp
DB2_dl 60004/tcp
DB2_dl_1 60005/tcp
DB2_dl_2 60006/tcp
DB2_dl_END 60007/tcp
#DB2tcp 50000/tcp
#DB2tcp1 50001/tcp
DB2_qing 60008/tcp
DB2_qing_1 60009/tcp
DB2_qing_2 60010/tcp
DB2_qing_END 60011/tcp
#
db2_master 50506/tcp
db2_slave 50505/tcp
DB2_wzm 60012/tcp
DB2_wzm_1 60013/tcp
DB2_wzm_2 60014/tcp
DB2_wzm_END 60015/tcp
(2.4)把dbm的VCENAME 的值和/etc/services中的端口号对应
[wzm@fedora ~]$ db2 update dbm cfg using SVCENAME 50000
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
(2.5)查看监听端口
[wzm@fedora db2backup]$ netstat -an | grep 50000
tcp 0 0 0.0.0.0:50000 0.0.0.0:* LISTEN
说明:综合上述的更改,这时就可以远程连接到实例。
(六.) 数据库的远程编目
===========================================================================
(6.1) 编目节点
[dl@fedora ~]$ db2 catalog tcpip node wzmode remote 10.4.5.212 server 50000
DB20000I The CATALOG TCPIP NODE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
(6.2)显示编目的接点
[dl@fedora ~]$ db2 list node directory
Node Directory
Number of entries in the directory = 2
Node 1 entry:
Node name = WZMODE
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = 10.4.5.212
Service name = 50000
(6.3)编目远程的数据库到节点
[dl@fedora ~]$ db2 catalog db wzmdb as wzmdb_bm at node wzmode
DB20000I The CATALOG DATABASE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
(6.4)显示编目的数据库
[dl@fedora ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 3
Database 1 entry:
Database alias = WZMDB_BM
Database name = WZMDB
Node name = WZMODE
Database release level = a.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
(6.4)连接编目的数据库
[dl@fedora ~]$ db2 connect to wzmdb_bm user wzm using 123456
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB_BM
(6.5) 显示编目数据库的内容
[dl@fedora ~]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
WZMTB WZM T 2006-05-20-14.46.34.953560
1 record(s) selected.
(七.)数据库中的数据移动
================================================================================
(7.1) 将表中的数据导出
[wzm@fedora db2backup]$ db2 "export to wzmtb.ixf of ixf messages wzm.out select * from wzmtb"
Number of rows exported: 1
(7.2) 将数据导入
[wzm@fedora db2backup]$ db2 "import from wzmtb.ixf of ixf messages wzm.out create into wzmtb_tb"
Number of rows read = 1
Number of rows skipped = 0
Number of rows inserted = 1
Number of rows updated = 0
Number of rows rejected = 0
Number of rows committed = 1
(7.3)显示到入的内容
[wzm@fedora db2backup]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
WZMTB WZM T 2006-05-20-14.46.34.953560
WZMTB_TB WZM T 2006-05-20-17.43.52.010679
2 record(s) selected.
(7.4) 另一种的数据到入方法(说明,首先要建一个和原来表结构一样的表)
[wzm@fedora db2backup]$ db2 "load from wzmtb.ixf of ixf messages wzm.out insert into wzmtb_tb_tb"
Number of rows read = 1
Number of rows skipped = 0
Number of rows loaded = 1
Number of rows rejected = 0
Number of rows deleted = 0
Number of rows committed = 1
(八.)数据库备份与恢复
============================================================================
(8.1)脱机备份
[wzm@fedora db2backup]$ db2 backup db wzmdb to /home/db2backup/
Backup successful. The timestamp for this backup image is : 20060520175904
(8.2)恢复
[wzm@fedora db2backup]$ db2 restore db wzmdb taken at 20060520175904 into wamdb_db
DB20000I The RESTORE DATABASE command completed successfully.
(8.3)恢复显示
[wzm@fedora db2backup]$ db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = WZMDB
Database name = WZMDB
Local database directory = /home/wzm
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = WAMDB_DB
Database name = WAMDB_DB
Local database directory = /home/wzm
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
(8.4)在线备份(online)
(8.4.1) Log retain for recovery enabled (LOGRETAIN) = OFF 状态只能脱机备份
更改参数后可以进行在线全备份
[wzm@fedora ~]$ db2 update db cfg using LOGRETAIN ON
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, all
applications must disconnect from this database before the changes become
effective.
(8.4.2) 更改后的参数显示
wzm@fedora ~]$ db2 get db cfg | grep -i logretain
Log retain for recovery enabled (LOGRETAIN) = RECOVERY
First log archive method (LOGARCHMETH1) = LOGRETAIN
(8.4.3)在更改完参数后。连不上数据库,必须进行一次脱机全备份才能连上数据库
[wzm@fedora ~]$ db2 connect to wzmdb
SQL1116N A connection to or activation of database "WZMDB" cannot be made
because of BACKUP PENDING. SQLSTATE=57019
(8.4.4)进行一次全备份
[wzm@fedora ~]$ db2 backup db wzmdb to /home/db2backup/
Backup successful. The timestamp for this backup image is : 20060521124511
(8.4.5)连接数据库成功
[wzm@fedora ~]$ db2 connect to wzmdb
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB
(8.4.6) 进行在线全备份
[wzm@fedora db2backup]$ db2 backup db wzmdb online to /home/db2backup/ include logs without prompting
Backup successful. The timestamp for this backup image is : 20060521124905
(8.4.7)备份恢复
[wzm@fedora db2backup]$ db2 restore db wzmdb taken at 20060521130338 into wzmdb_db logtarget /home/db2backup/logs/ without prompting
SQL2540W Restore is successful, however a warning "2580" was encountered
during Database Restore while processing in No Interrupt mode.
(8.4.8)连接数据库不成功,显示暂挂前滚状态。
[wzm@fedora db2backup]$ db2 connect to wzmdb_db
SQL1117N A connection to or activation of database "WZMDB_DB" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
(8.4.9)日志的恢复
[wzm@fedora db2backup]$ db2 "rollforward db wzmdb_db to end of logs and stop overflow log path (/home/db2backup/logs)"
Rollforward Status
Input database alias = wzmdb_db
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000001.LOG - S0000001.LOG
Last committed transaction = 2006-05-21-05.03.53.000000
DB20000I The ROLLFORWARD command completed successfully.
(8.9.10)数据库的连接成功
[wzm@fedora db2backup]$ db2 connect to wzmdb_db
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB_DB
(8.5)增量备份(两种)说明,在进行增量备份是第一次要全备份,接着才可以进行增量备份
增量备份需要该的参数(trackmod)
[wzm@fedora logs]$ db2 get db cfg for wzmdb | grep -i trackmod
Track modified pages (TRACKMOD) = OFF
[wzm@fedora logs]$ db2 update db cfg for wzmdb using TRACKMOD ON
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
(8.5.1)全备份
[wzm@fedora db2backup]$ db2 backup db wzmdb online to /home/db2backup/ include logs without prompting
Backup successful. The timestamp for this backup image is : 20060521140150
(8.5.2)增量备份
[wzm@fedora db2backup]$ db2 backup db wzmdb online incremental to /home/db2backup/ include logs without prompting
Backup successful. The timestamp for this backup image is : 20060521140301
(8.5.3)备份的恢复(说明先指明恢复的时间点)
[wzm@fedora db2backup]$ db2 restore db wzmdb incremental taken at 20060521140301 into wzmddd logtarget /home/db2backup/logs
DB20000I The RESTORE DATABASE command completed successfully.
(8.5.4)进行一次恢复(恢复到全备份的时间点的内容)
[wzm@fedora db2backup]$ db2 restore db wzmdb incremental taken at 20060521140150 into wzmddd logtarget /home/db2backup/logs
DB20000I The RESTORE DATABASE command completed successfully.
(8.5.5)恢复到所指定的时间点的内容
[wzm@fedora db2backup]$ db2 restore db wzmdb incremental taken at 20060521140301 into wzmddd logtarget /home/db2backup/logs
SQL2580W Warning! Restoring logs to a path which contains existing log files. Attempting to overwrite an existing log file during restore will cause the restore operation to fail.
Do you want to continue ? (y/n) y
DB20000I The RESTORE DATABASE command completed successfully.
(8.5.6)进行前滚恢复
[wzm@fedora db2backup]$ db2 "rollforward db wzmddd to end of logs and stop overflow log path (home/db2backup/logs)"
Rollforward Status
Input database alias = wzmddd
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000006.LOG - S0000006.LOG
Last committed transaction = 2006-05-21-06.03.12.000000
DB20000I The ROLLFORWARD command completed successfully.
(8.5.7)db2连接
[wzm@fedora db2backup]$ db2 connect to wzmddd
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDDD
(九,)HADR的配置
=======================================================
说明:一。主服务器10.4.5.212 重服务器10.4.5.210
二。进行hadr的配置需要数据库的名字相同,但实例名字可以不同。
三。db2 update db cfg for wzmdb using LOGINDEXBUILD on
1.首先对主数据库进行一次全备份
[wzm@fedora db2backup]$ db2 backup db wzmdb
Backup successful. The timestamp for this backup image is : 20060521165702
2.将备份考到重服务器上
[wzm@fedora db2backup]$ scp WZMDB.0.wzm.NODE0000.CATN0000.20060521165702.001 dl@10.4.5.210:/home/dl/db2backup/
dl@10.4.5.210''s password:
WZMDB.0.wzm.NODE0000.CATN0000.20060521165702.001 100% 35MB 1.3MB/s 00:26
3.对重服务器进行数据库的恢复
[dl@fedora db2backup]$ db2 restore db wzmdb taken at 20060521165702
SQL2539W Warning! Restoring to an existing database that is the same as the ba ckup image database. The database files will be deleted.
Do you want to continue ? (y/n) y
DB20000I The RESTORE DATABASE command completed successfully.
4.修改之后的配置文件
[wzm@fedora db2backup]$ db2 get db cfg for wzmdb | grep -i hadr
HADR database role = STANDARD
HADR local host name (HADR_LOCAL_HOST) = 10.4.5.212
HADR local service name (HADR_LOCAL_SVC) = wzm8
HADR remote host name (HADR_REMOTE_HOST) = 10.4.5.210
HADR remote service name (HADR_REMOTE_SVC) = wzm9
HADR instance name of remote server (HADR_REMOTE_INST) = dl
HADR timeout value (HADR_TIMEOUT) = 120
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
同理
[dl@fedora db2backup]$ db2 get db cfg for wzmdb | grep -i hadr
HADR database role = STANDARD
HADR local host name (HADR_LOCAL_HOST) = 10.4.5.210
HADR local service name (HADR_LOCAL_SVC) = wzm9
HADR remote host name (HADR_REMOTE_HOST) = 10.4.5.212
HADR remote service name (HADR_REMOTE_SVC) = wzm8
HADR instance name of remote server (HADR_REMOTE_INST) = wzm
HADR timeout value (HADR_TIMEOUT) = 120
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
5.启动重服务器
[dl@fedora ~]$ db2 start hadr on db wzmdb as standby
DB20000I The START HADR ON DATABASE command completed successfully.
6.启动主服务器
[wzm@fedora db2backup]$ db2 start hadr on db wzmdb as primary
DB20000I The START HADR ON DATABASE command completed successfully.
7.查看hadr的状态为peer状态。
[dl@fedora ~]$ db2pd -hadr -db wzmdb
Database Partition 0 -- Database WZMDB -- Active -- Up 0 days 00:01:15
HADR Information:
Role State SyncMode HeartBeat LogGapRunAvg (bytes)
Standby Peer Nearsync 0 0
ConnectStatus ConnectTime Timeout
Connected Sun May 21 13:40:57 2006 (1148190057) 120
LocalHost LocalService RemoteHost RemoteService RemoteInstance
10.4.5.210 wzm9
10.4.5.212 wzm8 wzm
PrimaryFile PrimaryPg PrimaryLSN StandByFile StandByPg StandByLSN
S0000007.LOG 0 0x000002AF800080AB3C43A05E0 S0000007.LOG 0 0x000002AF800080AB3C43A05E0
[wzm@fedora db2backup]$ db2pd -hadr -db wzmdb
Database Partition 0 -- Database WZMDB -- Active -- Up 0 days 00:00:33
HADR Information:
Role State SyncMode HeartBeat LogGapRunAvg (bytes)
Primary Peer Nearsync 0 0
ConnectStatus ConnectTime Timeout
Connected Sun May 21 17:18:39 2006 (1148203119) 120
LocalHost LocalService RemoteHost RemoteService RemoteInstance
10.4.5.212 wzm8
10.4.5.210 wzm9 dl
PrimaryFile PrimaryPg PrimaryLSN StandByFile StandByPg StandByLSN
S0000007.LOG 0 0x000002AF800080AB3C46C55E0 S0000007.LOG 0 0x000002AF800080AB3
转载自http://blog.sina.com.cn/s/blog_60359c5b0100hj0e.html
(一)DB2的安装说明:
===========================================
[root@fedora home]# ./db2_install
Specify one or more of the following keywords,
separated by spaces, to install DB2 products.
Keyword Product Description
DB2.ESE DB2 Enterprise Server Edition for LINUX
DB2.ADMCL DB2 Administration Client for LINUX
DB2.ADCL DB2 Application Development Client for LINUX
Enter "help" to redisplay product names.
Enter "quit" to exit.
***********************************************************
DB2.ESE
The installation logfile can be found in /tmp/db2_install_log.3439.
db2_install program completed successfully.
(二)实例的相关说明
================================================
(1.)在建立实例前,首先要创建组和用户
[root@fedora home]# groupadd wangzm
[root@fedora home]# groupadd wzm
[root@fedora home]# useradd -g wangzm -d -m /home/wangzm -p 123456 wangzm
[root@fedora home]# useradd -g wzm -m -d /home/wzm -p 123456 wzm
(2.)实例的创建
[root@fedora home]# /opt/IBM/db2/V8.1/instance/db2icrt -u wangzm wzm
DBI1070I Program db2icrt completed successfully.
(3.)数据库的启动
[root@fedora home]# su - wzm
[wzm@fedora ~]$ db2start
05/20/2006 14:27:39 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
(4.)db2的进程
wzm 5981 0.0 14.1 121364 17808 pts/0 S 14:27 0:00 db2sysc
wzm 5987 0.0 13.6 121364 17108 pts/0 S 14:27 0:00 db2ipccm
wzm 5988 0.0 14.1 121364 17808 pts/0 S 14:27 0:00 db2resync
wzm 5989 0.0 12.9 118820 16228 pts/0 S 14:27 0:00 db2srvlst
wzm 5991 0.2 18.8 138584 23760 pts/0 Sl 14:27 0:01 db2hmon ,0,0,0,1,0,0,0,1e014,2,0,1,9fe0,0x11250000,0x11250000,15fc000,98006,2,138017
wzm 6204 0.0 6.0 35996 7624 pts/0 S 14:31 0:00 /home/wzm/sqllib/bin/db2bp 5846A513 5 A
wzm 6285 0.0 14.2 121364 17864 pts/0 S 14:32 0:00 db2agent (idle)
(5.)实例的显示----显示所有的
[wzm@fedora ~]$ db2ilist
db2inst1
dl
qing
wzm
(6.)显示当前的实例
[wzm@fedora ~]$ db2 get instance
The current database manager instance is: wzm
[wzm@fedora ~]$
(7.)删除一个实例
[root@fedora ~]# /opt/IBM/db2/V8.1/instance/db2idrop qing
DBI1070I Program db2idrop completed successfully.
(8.)列出当前实例中有哪些数据库
[wzm@fedora ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = WZMDB
Database name = WZMDB
Local database directory = /home/wzm
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
(三.)数据库的操作说明
===========================================================
(1.) 数据库的创建
[wzm@fedora ~]$ db2 "create database wzmdb"
DB20000I The CREATE DATABASE command completed successfully.
(2.)连接数据库
[wzm@fedora ~]$ db2 connect to wzmdb
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB
()查看表的空间
db2 list tablespaces (show detail)
db2pd -tablespaces -db <数据库名>
(3.)表的创建
[wzm@fedora ~]$ db2 "create table wzmtb (id int,name varchar(30))"
DB20000I The SQL command completed successfully.
(4.) 显示数据库里有那些表
[wzm@fedora ~]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
WZMTB WZM T 2006-05-20-14.46.34.953560
1 record(s) selected.
(5.) 向表里添加数据
[wzm@fedora ~]$ db2 "insert into wzmtb values (1,''wzm'')"
DB20000I The SQL command completed successfully.
(6.)显示表的内容
[wzm@fedora ~]$ db2 "select * from wzmtb"
ID NAME
----------- ------------------------------
1 wzm
1 record(s) selected.
(7.)断开数据库的连接
[wzm@fedora ~]$ db2 disconnect wzmdb
DB20000I The SQL DISCONNECT command completed successfully.
(8.)显示当前数据库连接的有哪些应用程序
[wzm@fedora ~]$ db2 list application
Auth Id Application Appl. Application Id DB # of
Name Handle Name Agents
-------- -------------- ---------- ------------------------------ -------- -----
WZM db2bp 44 *LOCAL.wzm.060520074504 WZMDB 1
(9.)db2的停止
[wzm@fedora ~]$ db2stop
05/20/2006 15:50:47 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
(10.)db2的强制停止
[wzm@fedora ~]$ db2stop force
05/20/2006 16:01:32 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
(五.)db2的参数说明
===============================================
1,
(1.1)db2set -lr...........列出要设置 DB2 概要文件注册表 (针对db2数据库)
(1.2)db2set -all..........列出在服务器上已经设置的所有DB2概要文件注册表 (针对db2数据库)
(1.3)db2 get db cfg ......查看数据库的配置参数,(针对所有数据库都有效)
(1.4)db2 get db cfg for wzmdb ......查看数据库的配置参数,(针对具体的数据库有效)
(1.5)db2 get dbm cfg .............查看数据库管理器的配置参数 (针对具体的实例有效)
2.参数的更改
(2.1) db2 update db cfg using 参数名=参数值
列: db2set DB2COMM=TCPIP
(2.2)显示以更改的参数(说明:参数该完之后需重起数据库才能生效)
列:[wzm@fedora ~]$ db2set
DB2COMM=TCPIP
(2.3)给实例增加端口号
vi/etc/services
DB2_db2inst1 60000/tcp
DB2_db2inst1_1 60001/tcp
DB2_db2inst1_2 60002/tcp
DB2_db2inst1_END 60003/tcp
DB2_dl 60004/tcp
DB2_dl_1 60005/tcp
DB2_dl_2 60006/tcp
DB2_dl_END 60007/tcp
#DB2tcp 50000/tcp
#DB2tcp1 50001/tcp
DB2_qing 60008/tcp
DB2_qing_1 60009/tcp
DB2_qing_2 60010/tcp
DB2_qing_END 60011/tcp
#
db2_master 50506/tcp
db2_slave 50505/tcp
DB2_wzm 60012/tcp
DB2_wzm_1 60013/tcp
DB2_wzm_2 60014/tcp
DB2_wzm_END 60015/tcp
(2.4)把dbm的VCENAME 的值和/etc/services中的端口号对应
[wzm@fedora ~]$ db2 update dbm cfg using SVCENAME 50000
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
(2.5)查看监听端口
[wzm@fedora db2backup]$ netstat -an | grep 50000
tcp 0 0 0.0.0.0:50000 0.0.0.0:* LISTEN
说明:综合上述的更改,这时就可以远程连接到实例。
(六.) 数据库的远程编目
===========================================================================
(6.1) 编目节点
[dl@fedora ~]$ db2 catalog tcpip node wzmode remote 10.4.5.212 server 50000
DB20000I The CATALOG TCPIP NODE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
(6.2)显示编目的接点
[dl@fedora ~]$ db2 list node directory
Node Directory
Number of entries in the directory = 2
Node 1 entry:
Node name = WZMODE
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = 10.4.5.212
Service name = 50000
(6.3)编目远程的数据库到节点
[dl@fedora ~]$ db2 catalog db wzmdb as wzmdb_bm at node wzmode
DB20000I The CATALOG DATABASE command completed successfully.
DB21056W Directory changes may not be effective until the directory cache is
refreshed.
(6.4)显示编目的数据库
[dl@fedora ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 3
Database 1 entry:
Database alias = WZMDB_BM
Database name = WZMDB
Node name = WZMODE
Database release level = a.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
(6.4)连接编目的数据库
[dl@fedora ~]$ db2 connect to wzmdb_bm user wzm using 123456
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB_BM
(6.5) 显示编目数据库的内容
[dl@fedora ~]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
WZMTB WZM T 2006-05-20-14.46.34.953560
1 record(s) selected.
(七.)数据库中的数据移动
================================================================================
(7.1) 将表中的数据导出
[wzm@fedora db2backup]$ db2 "export to wzmtb.ixf of ixf messages wzm.out select * from wzmtb"
Number of rows exported: 1
(7.2) 将数据导入
[wzm@fedora db2backup]$ db2 "import from wzmtb.ixf of ixf messages wzm.out create into wzmtb_tb"
Number of rows read = 1
Number of rows skipped = 0
Number of rows inserted = 1
Number of rows updated = 0
Number of rows rejected = 0
Number of rows committed = 1
(7.3)显示到入的内容
[wzm@fedora db2backup]$ db2 list tables
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
WZMTB WZM T 2006-05-20-14.46.34.953560
WZMTB_TB WZM T 2006-05-20-17.43.52.010679
2 record(s) selected.
(7.4) 另一种的数据到入方法(说明,首先要建一个和原来表结构一样的表)
[wzm@fedora db2backup]$ db2 "load from wzmtb.ixf of ixf messages wzm.out insert into wzmtb_tb_tb"
Number of rows read = 1
Number of rows skipped = 0
Number of rows loaded = 1
Number of rows rejected = 0
Number of rows deleted = 0
Number of rows committed = 1
(八.)数据库备份与恢复
============================================================================
(8.1)脱机备份
[wzm@fedora db2backup]$ db2 backup db wzmdb to /home/db2backup/
Backup successful. The timestamp for this backup image is : 20060520175904
(8.2)恢复
[wzm@fedora db2backup]$ db2 restore db wzmdb taken at 20060520175904 into wamdb_db
DB20000I The RESTORE DATABASE command completed successfully.
(8.3)恢复显示
[wzm@fedora db2backup]$ db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = WZMDB
Database name = WZMDB
Local database directory = /home/wzm
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = WAMDB_DB
Database name = WAMDB_DB
Local database directory = /home/wzm
Database release level = a.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
(8.4)在线备份(online)
(8.4.1) Log retain for recovery enabled (LOGRETAIN) = OFF 状态只能脱机备份
更改参数后可以进行在线全备份
[wzm@fedora ~]$ db2 update db cfg using LOGRETAIN ON
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, all
applications must disconnect from this database before the changes become
effective.
(8.4.2) 更改后的参数显示
wzm@fedora ~]$ db2 get db cfg | grep -i logretain
Log retain for recovery enabled (LOGRETAIN) = RECOVERY
First log archive method (LOGARCHMETH1) = LOGRETAIN
(8.4.3)在更改完参数后。连不上数据库,必须进行一次脱机全备份才能连上数据库
[wzm@fedora ~]$ db2 connect to wzmdb
SQL1116N A connection to or activation of database "WZMDB" cannot be made
because of BACKUP PENDING. SQLSTATE=57019
(8.4.4)进行一次全备份
[wzm@fedora ~]$ db2 backup db wzmdb to /home/db2backup/
Backup successful. The timestamp for this backup image is : 20060521124511
(8.4.5)连接数据库成功
[wzm@fedora ~]$ db2 connect to wzmdb
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB
(8.4.6) 进行在线全备份
[wzm@fedora db2backup]$ db2 backup db wzmdb online to /home/db2backup/ include logs without prompting
Backup successful. The timestamp for this backup image is : 20060521124905
(8.4.7)备份恢复
[wzm@fedora db2backup]$ db2 restore db wzmdb taken at 20060521130338 into wzmdb_db logtarget /home/db2backup/logs/ without prompting
SQL2540W Restore is successful, however a warning "2580" was encountered
during Database Restore while processing in No Interrupt mode.
(8.4.8)连接数据库不成功,显示暂挂前滚状态。
[wzm@fedora db2backup]$ db2 connect to wzmdb_db
SQL1117N A connection to or activation of database "WZMDB_DB" cannot be made
because of ROLL-FORWARD PENDING. SQLSTATE=57019
(8.4.9)日志的恢复
[wzm@fedora db2backup]$ db2 "rollforward db wzmdb_db to end of logs and stop overflow log path (/home/db2backup/logs)"
Rollforward Status
Input database alias = wzmdb_db
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000001.LOG - S0000001.LOG
Last committed transaction = 2006-05-21-05.03.53.000000
DB20000I The ROLLFORWARD command completed successfully.
(8.9.10)数据库的连接成功
[wzm@fedora db2backup]$ db2 connect to wzmdb_db
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDB_DB
(8.5)增量备份(两种)说明,在进行增量备份是第一次要全备份,接着才可以进行增量备份
增量备份需要该的参数(trackmod)
[wzm@fedora logs]$ db2 get db cfg for wzmdb | grep -i trackmod
Track modified pages (TRACKMOD) = OFF
[wzm@fedora logs]$ db2 update db cfg for wzmdb using TRACKMOD ON
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
(8.5.1)全备份
[wzm@fedora db2backup]$ db2 backup db wzmdb online to /home/db2backup/ include logs without prompting
Backup successful. The timestamp for this backup image is : 20060521140150
(8.5.2)增量备份
[wzm@fedora db2backup]$ db2 backup db wzmdb online incremental to /home/db2backup/ include logs without prompting
Backup successful. The timestamp for this backup image is : 20060521140301
(8.5.3)备份的恢复(说明先指明恢复的时间点)
[wzm@fedora db2backup]$ db2 restore db wzmdb incremental taken at 20060521140301 into wzmddd logtarget /home/db2backup/logs
DB20000I The RESTORE DATABASE command completed successfully.
(8.5.4)进行一次恢复(恢复到全备份的时间点的内容)
[wzm@fedora db2backup]$ db2 restore db wzmdb incremental taken at 20060521140150 into wzmddd logtarget /home/db2backup/logs
DB20000I The RESTORE DATABASE command completed successfully.
(8.5.5)恢复到所指定的时间点的内容
[wzm@fedora db2backup]$ db2 restore db wzmdb incremental taken at 20060521140301 into wzmddd logtarget /home/db2backup/logs
SQL2580W Warning! Restoring logs to a path which contains existing log files. Attempting to overwrite an existing log file during restore will cause the restore operation to fail.
Do you want to continue ? (y/n) y
DB20000I The RESTORE DATABASE command completed successfully.
(8.5.6)进行前滚恢复
[wzm@fedora db2backup]$ db2 "rollforward db wzmddd to end of logs and stop overflow log path (home/db2backup/logs)"
Rollforward Status
Input database alias = wzmddd
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0000006.LOG - S0000006.LOG
Last committed transaction = 2006-05-21-06.03.12.000000
DB20000I The ROLLFORWARD command completed successfully.
(8.5.7)db2连接
[wzm@fedora db2backup]$ db2 connect to wzmddd
Database Connection Information
Database server = DB2/LINUX 8.2.0
SQL authorization ID = WZM
Local database alias = WZMDDD
(九,)HADR的配置
=======================================================
说明:一。主服务器10.4.5.212 重服务器10.4.5.210
二。进行hadr的配置需要数据库的名字相同,但实例名字可以不同。
三。db2 update db cfg for wzmdb using LOGINDEXBUILD on
1.首先对主数据库进行一次全备份
[wzm@fedora db2backup]$ db2 backup db wzmdb
Backup successful. The timestamp for this backup image is : 20060521165702
2.将备份考到重服务器上
[wzm@fedora db2backup]$ scp WZMDB.0.wzm.NODE0000.CATN0000.20060521165702.001 dl@10.4.5.210:/home/dl/db2backup/
dl@10.4.5.210''s password:
WZMDB.0.wzm.NODE0000.CATN0000.20060521165702.001 100% 35MB 1.3MB/s 00:26
3.对重服务器进行数据库的恢复
[dl@fedora db2backup]$ db2 restore db wzmdb taken at 20060521165702
SQL2539W Warning! Restoring to an existing database that is the same as the ba ckup image database. The database files will be deleted.
Do you want to continue ? (y/n) y
DB20000I The RESTORE DATABASE command completed successfully.
4.修改之后的配置文件
[wzm@fedora db2backup]$ db2 get db cfg for wzmdb | grep -i hadr
HADR database role = STANDARD
HADR local host name (HADR_LOCAL_HOST) = 10.4.5.212
HADR local service name (HADR_LOCAL_SVC) = wzm8
HADR remote host name (HADR_REMOTE_HOST) = 10.4.5.210
HADR remote service name (HADR_REMOTE_SVC) = wzm9
HADR instance name of remote server (HADR_REMOTE_INST) = dl
HADR timeout value (HADR_TIMEOUT) = 120
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
同理
[dl@fedora db2backup]$ db2 get db cfg for wzmdb | grep -i hadr
HADR database role = STANDARD
HADR local host name (HADR_LOCAL_HOST) = 10.4.5.210
HADR local service name (HADR_LOCAL_SVC) = wzm9
HADR remote host name (HADR_REMOTE_HOST) = 10.4.5.212
HADR remote service name (HADR_REMOTE_SVC) = wzm8
HADR instance name of remote server (HADR_REMOTE_INST) = wzm
HADR timeout value (HADR_TIMEOUT) = 120
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
5.启动重服务器
[dl@fedora ~]$ db2 start hadr on db wzmdb as standby
DB20000I The START HADR ON DATABASE command completed successfully.
6.启动主服务器
[wzm@fedora db2backup]$ db2 start hadr on db wzmdb as primary
DB20000I The START HADR ON DATABASE command completed successfully.
7.查看hadr的状态为peer状态。
[dl@fedora ~]$ db2pd -hadr -db wzmdb
Database Partition 0 -- Database WZMDB -- Active -- Up 0 days 00:01:15
HADR Information:
Role State SyncMode HeartBeat LogGapRunAvg (bytes)
Standby Peer Nearsync 0 0
ConnectStatus ConnectTime Timeout
Connected Sun May 21 13:40:57 2006 (1148190057) 120
LocalHost LocalService RemoteHost RemoteService RemoteInstance
10.4.5.210 wzm9
10.4.5.212 wzm8 wzm
PrimaryFile PrimaryPg PrimaryLSN StandByFile StandByPg StandByLSN
S0000007.LOG 0 0x000002AF800080AB3C43A05E0 S0000007.LOG 0 0x000002AF800080AB3C43A05E0
[wzm@fedora db2backup]$ db2pd -hadr -db wzmdb
Database Partition 0 -- Database WZMDB -- Active -- Up 0 days 00:00:33
HADR Information:
Role State SyncMode HeartBeat LogGapRunAvg (bytes)
Primary Peer Nearsync 0 0
ConnectStatus ConnectTime Timeout
Connected Sun May 21 17:18:39 2006 (1148203119) 120
LocalHost LocalService RemoteHost RemoteService RemoteInstance
10.4.5.212 wzm8
10.4.5.210 wzm9 dl
PrimaryFile PrimaryPg PrimaryLSN StandByFile StandByPg StandByLSN
S0000007.LOG 0 0x000002AF800080AB3C46C55E0 S0000007.LOG 0 0x000002AF800080AB3
转载自http://blog.sina.com.cn/s/blog_60359c5b0100hj0e.html
相关推荐
Linux 下 DB2 常用命令 DB2 是一个 relation database management system(关系数据库管理系统),广泛应用于企业级的数据存储和管理中。在 Linux 环境下,DB2 提供了丰富的命令行工具,用于管理和维护数据库。下面...
本文将深入探讨Linux下DB2的常用命令,帮助开发者更好地理解和操作DB2数据库。 1. **安装与启动DB2** - `sudo rpm -ivh db2_v11.5_linux_x86_64.rpm`:在Linux上安装DB2的RPM包。 - `db2start`:启动DB2实例。 -...
在 Linux 系统上安装 DB2 可以为开发者和管理员提供一个强大的数据存储和管理平台。以下是对 DB2 在 Linux 上安装及建库过程的详细说明: ### 一、DB2 安装步骤 1. **上传与解压安装文件**:首先,将 DB2 的安装...
- 进入安装包的 server 目录:`cd db2forlinux/server`。 - 执行 `./db2prereqcheck -v10.1.0.4` 来检查系统是否满足 DB2 的最低要求。 - 如果提示缺少某些库(例如 libstdc++),可以通过命令 `yum -y install ...
你可以通过执行`db2 list applications for db db_name`命令来检查当前是否有活动的链接。如果有活动链接,你需要终止它们,这可以通过`db2 force application all`命令完成。接着,再次运行`db2 list applications ...
下面,我们将详细解析Linux下DB2的常用命令及其功能。 ### 1. 启动数据库 `db2start` 此命令用于启动DB2数据库管理器,是开启数据库服务的第一步。当服务器启动后,DB2数据库才能接受来自客户端的连接请求。 ###...
本文将详细介绍DB2 High Availability (HA) for Linux的具体实施步骤和技术要点。 #### 二、DB2 HA for Linux的基本概念 DB2 HA for Linux主要通过双机热备机制实现高可用性。该方案通常涉及三个关键组成部分:...
### DB2 9.7 for Linux 5.4 手动安装步骤详解 #### 一、概述 IBM DB2 9.7是一款功能强大的企业级数据库管理系统,它为用户提供了一系列全面的数据管理和分析工具。本文将详细介绍如何在Linux 5.4环境下手动安装DB2...
2. 使用`wget`命令下载DB2安装文件到Linux服务器,例如:`wget http://example.com/DB2LinuxInstaller.tar.gz` 3. 解压下载的文件:`tar -xvf DB2LinuxInstaller.tar.gz` 4. 进入解压后的目录:`cd DB2...
【DB2 V9 for Linux 静默安装】 DB2 V9.7 ESE(Enterprise Server Edition)是在Linux操作系统上的数据库管理系统,适用于大型企业和组织。静默安装是一种自动化安装方式,通常用于批量部署或无人值守的环境。以下...
例如,你可能需要编辑`/etc/profile.d`下的脚本来添加DB2的路径到系统PATH,以便在任何目录下都能运行DB2命令。此外,还需要配置DB2的启动脚本,使其能在系统启动时自动运行。 最后,别忘了进行必要的安全性设置,...
在Linux环境下安装IBM的DB2数据库管理系统是一项技术性较强的任务,需要遵循一定的步骤来确保安装过程的顺利。本文将详细阐述在Linux系统中安装DB2的详细步骤。 首先,安装DB2之前,需要确保你的Linux操作系统版本...
### DB2 For Linux安装配置详解 #### 一、DB2 安装 DB2 的安装是部署该数据库管理系统的第一步。对于 Linux 环境,本文档提供了在 Red Hat AS5 下安装 DB2 的详细步骤。 1. **准备工作**: - 首先需要获取 DB2 的...
db2c_db2inst1 50000/tcp # TCP/IP services for db2inst1 ``` ##### 10. 设置实例通信方式 - **切换用户**: ```sh su - db2inst1 ``` - **设置通信方式**: ```sh db2set DB2COMM=tcpip db2update dbmcfg ...
使用`db2_install -f response_file.txt`命令进行静默安装,其中`response_file.txt`是响应文件的路径。 5. **后续配置**: 安装完成后,还需要进行一系列的配置工作,包括创建数据库、设置环境变量、启动和停止...
- **产品背景**:IBM DB2 for Linux是IBM公司专为Linux系统设计的一款数据库管理软件,支持多种Linux发行版。 - **主要特性**: - 高性能查询处理能力。 - 支持SQL标准,并提供扩展功能。 - 强大的数据安全性与...
在Linux环境下操作IBM DB2数据库管理系统时,掌握一系列的DB2命令是至关重要的。这些命令不仅帮助用户管理和维护数据库,还能够实现数据的备份、恢复、优化以及日常的查询和管理任务。以下是对给定文件中提及的关键...
在 Linux 环境中安装 DB2,你需要遵循一系列步骤,确保系统满足必要的前提条件,并且能够正确配置以提供服务。 首先,安装 DB2 前的准备工作至关重要。操作系统必须已经设置为中文语言环境,这有助于在安装过程中...
### Linux环境下DB2命令详解 #### 一、概述 DB2是IBM开发的一款关系型数据库管理系统,被广泛应用于企业级环境中。在Linux操作系统下,掌握DB2的基本命令对于数据库管理员而言至关重要。本文将详细介绍如何在Linux...