db2iupgrade
$DB2DIR/instance/db2iupgrade InstName
tar -xzvf file.tar.gz
cd server_t
./db2_inistall
SERVER
purescale选NO
groupadd -g 10000 db2igrp
grouped -g 10001 db2fgrp
useradd -u 10000 -g db2igrp -m -d /home/db2inst1 db2inst1
useradd -u 10001 -g db2fgrp -m -d /home/db2fenc1 db2fenc1
./db2icrt -s ese -p 60000 -u db2fenc1 db2inst1
groupadd -g 20000 db2igrp2
groupadd -g 20001 db2fgrp2
useradd -u 20000 -g db2igrp -m -d /home/db2inst2 db2inst2
useradd -u 20001 -g db2fgrp -m -d /home/db2fenc2 db2fenc2
创建fence user是为了防止用户写的存储过程中包含非sql的可能会破坏db2数据结构,使db2引擎崩溃的代码,让这些存储过程在单独的进程下运行,起到隔离和保护作用
创建失败时查看是否ping通127.0.0.1,如果不行,在/etc/hosts文件里增加127.0.0.1 主机名。
cd /opt/IBM/db2/V10.5/instance
./db2icrt -s ese -p 50000 -u db2fenc2 db2inst2
db2ilist
db2greg -dump
db2 get dbm cfg show detail
对于那些无法立即生效的参数,Show detail可以用来显示它们的deferred value。
db2 update dbm cfg using mon_heap_sz 1024 automatic
db2 update db cfg for sample using sortheap 1024
/home/db2inst1/sqllib/db2dump/DIAG0000
diagpath: Location of the log files
diaglevel: Types of errors to be written to log
db2stop force
Db2idrop 实例名
db2start
db2stop
db2 create database sample using codeset utf-8 territory CN
或者
db2sampl
db2 list tables for all
db2 catalog tcpip node N1 remote 127.0.0.1 server 60000(要连接的实例端口)
db2 catalog database sample as sinst1 at node N1 (别名尽量不要超过8位)
db2 connect to sample user db2inst1 using 登录密码
表空间是逻辑上的概念,物理存储是容器。
容器可以是裸设备(比如没有格式化的磁盘),也可以是文件、目录。
sms
使用 CREATE TABLESPACE 语句的 MANAGED BY SYSTEM 子句创建 (重要) sms
要求将容器定义为目录名。
性能差一点,一般用作临时表空间
dms
使用 CREATE TABLESPACE 语句的 MANAGED BY DATABASE 子句创建 dms
要求将容器定义为文件或设备。(重要)
dms性能通常高于sms
自动存储管理表空间不需要指定容器,对于数据表空间会自动选择dms,对临时表空间会选择sms,创建自动存储管理表空间时必须要先开启自动存储管理。
db2 CREATE BUFFERPOOL bp8k size 1000 PAGESIZE 8192
db2 "create tablespace mytbs
pagesize 8192
managed by database
using (file '/home/db2inst2/tablespace/aa' 10000 )
bufferpool bp8k"
db2 "LIST TABLESPACES SHOW DETAIL"
CREATE TABLESPACE mytabs MANAGED BY DATABASE USING (FILE '/db2files/DMS1' 10 M) AUTORESIZE YES
db2 ALTER TABLESPACE mytbs AUTORESIZE YES
db2 "grant select on db2inst1.x1 to user test" #将对表db2inst1.t的select权限赋予testusr (重要)
db2 "revoke select on db2inst1.x1 from user test" #将对表db2inst1.t的select权限从dbuser收回
Db级权限示例:
GRANT DBADM ON DATABASE TO USER "asd"
GRANT CONNECT ON DATABASE TO USER "asd"
db2 force applications all
db2 BACKUP DATABASE sample TO /home/db2inst2/backup
db2 terminate
db2 drop db sample
db2 RESTORE DATABASE sample FROM /home/db2inst2/backup TAKEN AT 20180816232659 WITHOUT ROLLING FORWARD WITHOUT PROMPTING
db2 list tablespaces查看表空间id
db2 RESTORE DATABASE sample FROM /home/db2inst2/backup TAKEN AT 20180816232659 redirect WITHOUT ROLLING FORWARD WITHOUT PROMPTING
db2 "set tablespace containers for 表空间id using (file '/home/db2inst2/backup/dd’ 10000)"
db2 restore db sample continue
db2 start hadr on database hadr_db as standby (重要) 先启动备份机再启动主机
db2 start hadr on database hadr_db as primary
db2 get monitor switches
db2 update monitor switches using bufferpool on
db2 get snapshot for database on sample
db2 "select * from syscat.bufferpools with ur"
db2 "alter bufferpool bp8k immediate size 2000"
db2 ? SQL0104N
db2sampl
db2 connect to sample
db2 list tables for all | grep -i empmdc
db2 "create event monitor dlmon for deadlocks with details
write to file '/home/db2inst1/evmon'"
db2 SET EVENT MONITOR monitor-name STATE 0 / 1
db2evmon -path directory path >1.out
vi 1.sql
select * from empmdc where empno=500 with ur
db2expln -d sample -f 1.sql -z ";" -g -o 1.exp
cd /home/db2inst2/sqllib/misc
db2 -tvf EXPLAIN.DDL 生成相关库
db2advis -d sample -n db2inst2 -i 1.sql > 1.adv
db2 -tvf 1.adv
db2 ?
db2 ? OPTIONS
db2level
Db2look
db2start
db2stop
db2 list db directory
db2 ?
db2 connect to
db2 list tables [for / for all]
db2 list tablespaces [show detail]
db2 list tablespace containers for
Database Manager Configuration
db2 get dbm cfg
db2 update dbm cfg using
DIAGLEVEL & DIAGPATH
Database Configuration
db2 get db cfg for
db2 update db cfg for using
Environment
db2set -all
db2set =
System tables and views
Code /opt/IBM/db2/V10.5/*
Instance home /home//sqllib
Diagnostic data /home//sqllib/db2dump
Database directory
db2 list db directory
Tablespace containers
db2 list tablespaces show detail
db2 list tablespace containers for
Database transaction logs
db2 get db cfg for | grep "Path to log files"
db2 force application all / db2stop
db2stop force
db2_kill
ipclean