Common DB2 commands

Source: Internet
Author: User
Tags db2 connect db2 create table db2 describe table
Start Database: Start db2 service: db2start activate database instance: db2activatedatabaselt; db_namegt; view activated Database: db2listac

Start database: Start db2 service: db2start activate database instance: db2 activate database lt; db_namegt; view activated database: db2 list ac

Start the database:
Start the db2 service: db2start
Activate database instance: db2 activate database
View activated databases: db2 list active databases


Close the database:
Invalid database instance: db2 deactivate database
Disable 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 -Tablespace
View Database Configuration: db2 get db cfg
Connect to the database: db2 connect
Db2 connect User [user_name] using [password]
Disconnect the database: db2 connect reset/db2 terminate
Create Database: db2 create db
Delete database: db2 drop database (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

View deadlocks: db2 get snapshot for locks on
Db2 "select agent_id, tabname, lock_mode from table (snap_get_lock (' ') As aa"
Kill process: db2 force application (NUM)

Monitor SQL statements that consume a lot in DB2:
Eg :( DB_NAME = CMSDB)
Db2top-d CMSDB ----- view the resource consumption. Follow the prompts to press l. Application Handle is displayed, and Application Handle (stat) with high resource consumption is found)
Write down app handle.
Db2pd-d CMSDB-dyn-application>/tmp/db2pd1.txt ---- session Statements everywhere, ready for tuning


Set the connection mode (restart will take effect ):
Db2set DB2COMM = tcpip
Db2set DB2COMM =

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.