}

IBM DB2 Administration Cheatsheet — Essential Commands (2026)

IBM DB2 Administration Cheatsheet — Essential Commands (2026)

Quick reference for IBM DB2 LUW (Linux, Unix, Windows) administration. All commands run as the DB2 instance owner unless noted.

Instance Management

db2start                    # Start DB2 instance
db2stop                     # Stop DB2 gracefully
db2stop force               # Force stop (disconnects all users)
db2 get instance            # Show current instance name
db2 get dbm cfg             # Show database manager config
db2 update dbm cfg using MAXAGENTS 200  # Update DBM config

Database Connection

db2 connect to MYDB                         # Connect (prompts for credentials)
db2 connect to MYDB user db2inst1 using pw  # Connect with credentials
db2 connect reset                           # Disconnect current connection
db2 terminate                               # Terminate backend process
db2 list db directory                       # List all catalogued databases
db2 list db directory on /data              # List databases on a path

Active Connections & Applications

db2 list active databases           # Show active databases
db2 list applications               # Show all active connections
db2 list applications show detail   # Connections with SQL statements
db2 force applications all          # Disconnect all applications
db2 force application (12345)       # Disconnect specific app by ID

Database Status & Snapshots

db2 get snapshot for database on MYDB          # Database snapshot
db2 get snapshot for all databases             # All databases snapshot
db2 get snapshot for applications on MYDB      # Application snapshot
db2 get snapshot for locks on MYDB             # Lock snapshot
db2pd -db MYDB -locks                          # DB2 problem determination (locks)
db2pd -db MYDB -transactions                   # Active transactions

Tables & Schema

db2 list tables                         # Tables in current schema
db2 list tables for schema MYSCHEMA     # Tables in a specific schema
db2 list tables for all                 # All tables in database
db2 describe table SCHEMA.TABLENAME     # Table column definition
db2 "select tabname, tabschema from syscat.tables limit 10"

Users & Authorities

db2 get authorizations                          # Current user's authorities
db2 "grant connect on database to user myuser"  # Grant connect
db2 "grant dbadm on database to user myuser"    # Grant DBA
db2 "revoke connect on database from user myuser"

Backup & Restore

# Online backup
db2 backup database MYDB online to /backup compress include logs

# Offline backup
db2 deactivate database MYDB
db2 backup database MYDB to /backup

# List backup images
db2 list history backup all for MYDB

# Restore
db2 restore database MYDB from /backup taken at 20260401120000

Configuration

db2 get db cfg for MYDB                        # Database config
db2 update db cfg for MYDB using LOGFILSIZ 4096  # Update log file size
db2 get dbm cfg                                # DBM config
db2 reset db cfg for MYDB                      # Reset to defaults
db2 activate database MYDB                     # Pre-activate database
db2 deactivate database MYDB                   # Deactivate database

Logs & Diagnostics

db2diag -gi msg::"SQL0964"          # Search db2diag.log for error
db2diag -time 2026-04-01            # Entries from specific date
db2 get db cfg for MYDB | grep -i log  # Log-related config
db2 "select * from sysibmadm.diag_msgs order by timestamp desc fetch first 20 rows only"

Common Error Codes

Error Code Message Common Cause Fix
SQL1032N No start database manager command DB2 not running Run db2start
SQL1025N Databases still active Active connections during db2stop Use db2stop force
SQL0964C Transaction log full Log space exhausted Increase LOGFILSIZ or add log path
SQL0818N Timestamp conflict Clock skew between nodes Sync clocks with NTP
SQL1092C Not authorized Wrong user Switch to instance owner
SQL30081N Communication error Network issue or DB2 not listening Check db2comm and ports
SQL0204N Object not found Table/schema doesn't exist Check spelling and schema

Useful One-Liners

# Check DB2 version
db2level

# Database disk usage
db2 "call sysproc.admin_get_tab_info(null, null)" | head -40

# Long-running queries
db2pd -db MYDB -applications -dynamic

# Table statistics last updated
db2 "select tabname, stats_time from syscat.tables where tabschema = 'MYSCHEMA'"

# Rebuild statistics
db2 "runstats on table MYSCHEMA.MYTABLE with distribution and detailed indexes all"

Related IBM DB2 Guides