Start database: Start db2 service: db2start activate database instance: db2 activate database <db_name> View activated database: db2 list active databases
Shut down database: Invalid database instance: db2 deactivate database <db_name> shut down database Service: db2stop
View Database: db2 list db directory
View database applications: db2 list applications view database applications and processes: db2 list applications show detail View database tablespace: db2pd-db <db_name>-tablespace
View Database Configuration: db2 get db cfg for <db_name> connect to database: db2 connect to <db_name> db2 connect to <db_name> user [user_name] using [password] Disconnect the database: db2 connect reset/db2 terminate create database: db2 create db <db_name> delete database: db2 drop database <db_name> (if it cannot be deleted, try to disconnect the activated connection or restart db2)
List system tables: db2 list tables for system list all user tables: db2 list tables list all tables: db2 list tables for all list specific user tables: db2 list tables for schema [user]
Copy a table: db2 create table t1 like t2 display table structure: db2 describe table tablename query table: db2 "select * from table tablename where... "Run the SQL Script: db2-tvf scripts. SQL
View error code: db2? 10054 stop the activation connection: db2 force application all; \ db2 force application all; \ db2 force application all; \ db2stop to view the deadlock: db2 get snapshot for locks on <db_name> db2 "select agent_id, tabname, lock_mode from table (snap_get_lock ('<db_name>') as aa" kill a process: db2 force application (NUM) monitors SQL statements that consume a lot of data in DB2: eg :( DB_NAME = CMSDB) db2top-d CMSDB ----- view the resource consumption and press l as prompted. Application Handle appears, find the Application Handle (stat) with high resource consumption and write down the app handle . Db2pd-d CMSDB-dyn-application>/tmp/db2pd1.txt ---- the session statements are prepared for optimization.
Set the connection mode (which takes effect after restart): db2set DB2COMM = tcpipdb2set DB2COMM =