DB2 常用命令
查看DB2版本: | db2level |
创建instance: | 进入安装目录instance文件夹,db2icrt -u ${USR} ${USR} 由于instance多和系统用户关联,直接用系统用户名称 |
删除instance: | db2idrop ${NAME} |
列出所有instance: | db2ilist |
列出当前instance: | db2 get instance |
设置当前instance: | set db2instance=${NAME} |
查看DBM配置: | db2 get dbm cfg|more |
更新DBM配置: | db2 update dbm cfg using ${NAME} ${VALUE} |
查看端口号: | db2 get dbm cfg|grep SVCENAME |
查看DB配置: | db2 get db cfg for ${DBNAME}|more |
更新DB配置: | db2 update db cfg for ${DBNAME} using ${NAME} ${VALUE} |
强制关闭数据库: | db2stop force |
启动数据库: | db2start |
在指定目录创建DB: | db2 create db ${DBNAME} on ${DBDIR} using codeset UTF-8 territory US |
设置数据库归档模式: | db2 update db cfg for ${DBNAME} using logarchmeth1 LOGRETAIN |
设置数据库日志目录: | db2 update db cfg for ${DBNAME} using newlogpath ${LOGDIR} |
设置日志文件大小(单位:页): | db2 update db cfg using LOGFILSIZ ${SIZE} |
设置主日志文件数量: | db2 update db cfg using LOGPRIMARY ${AMOUNT} |
设置辅助日志文件数量: | db2 update db cfg using LOGSECOND ${AMOUNT} (LOGPRIMARY+LOGSECOND<256 DB2 UDB V8.1) |
备份数据库: | db2 backup db ${DBNAME} |
还原数据库: | db2 restore db ${DBNAME} |
查看所有现数据库连接: | db2 list application |
强制断开数据库应用连接: | db2 force application all |
连接本地数据库: | db2 connect to ${DBNAME} |
连接远程数据库: | db2 catalog tcpip node ${LOCAL_NODENAME} remote ${REMOTE_HOSTIP} server ${REMOTE_HOSTPORT} db2 catalog db ${REMOTE_DBNAME} as ${LOCAL_ALIAS} at node ${LOCAL_NODENAME} db2 connect to ${LOCAL_ALIAS} user ${USR} using ${PWD} |
查看本地节点: | db2 list node directory |
取消节点编目: | db2 uncatalog node ${LOCAL_NODENAME} |
查看系统数据库目录: | db2 list db directory |
查看本地数据库目录: | db2 list db directory on ${DISK} |
取消数据库编目: | db2 uncatalog db ${DBNAME} |
断开与数据库的连接: | db2 connect reset db2 terminate |
修改code page: | db2set db2codepage=${PAGENO.} |
查看数据库表: | db2 list tables (for schema ${SCHEMANAME}) |
查看系统表: | db2 list tables for system |
查看表结构: | db2 describe table ${TABLENAME} |
查看表空间: | db2 list tablespaces |
导出数据库表结构: | db2look -d ${DBNAME} -e -t ${TABLENAME} -o ${OUTPUT.sql} |
执行导出的文件: | db2 -tvf ${OUTPUT.sql} |
对一张表运行统计信息: | db2 -v runstats on table ${TABLENAME} and indexes all |
查看是否执行了runstats: | db2 -v "select tbname, nleaf, nlevels,stats_time from sysibm.sysindexes" |
DB2帮助命令: | db2 "? SQLXXX" db2 "? RUNSTATS" |
DB2 BIND 命令: | db2 bind XX.bnd |
查看bnd文件: | 进入sqllib/bnd文件夹 db2bfd -b XX.bnd (display bind file header) db2bfd -s XX.bnd (display SQL statements) |