DB2 Basic Commands
DB2 Basic Commands
com/
Basic Commands
Size of your database: =>db2 'call get_dbsize_info(?,?,?,0)'
Version of DB2 you are running:
=>db2level Stop the db2 instance =>db2stop Stop an instance that has current connections =>db2 force applications all =>db2 deactivate db <dbname> =>db2 terminate =>db2stop force =>ipclean
Activate a database
=>db2 activate db <dbname>
Deactivate a database
=>db2licm -l
IBM DB2 UDB for Linux, Unix and Windows Command Examples
View the names, pagesize, and number of pages of the bufferpools in your database: =>db2 "select bpname,pagesize,npages from syscat.bufferpools" Make a bufferpool resize automatically. You must have STMM turned on at the database configuration level =>db2 alter bufferpool bp1 size AUTOMATIC Alter a bufferpool size that is a fixed size =>db2 ALTER BUFFERPOOL IBMDEFAULTBP SIZE 15000; Add space to a DMS tablespace: =>db2 "alter tablespace <tblspace> extend (all 8000)"
=>db2 "describe select <colname> from schema.tablename" Look at indexes on a table: =>db2 describe indexes for table schema.tablename Export data to a file in ixf format:
=>db2 import from filename.ixf of ixf messages tablename.txt insert into SCHEMA.TABNAME
Import using Load which is faster (doesn't check constraints) and NONRECOVERABLE doesn't log anything.
Build a file to set integrity on all tables that are in set integrity pending state.
=>db2 "select 'set integrity for '||tabschema||'.'||tabname ||' immediate checked;' from syscat.tables where type = 'T' and status = 'C'" > file.out
dbadm auth must be revoked before any other database privlege. create_not_fenced_routine must be revoked before create_external_routine
Copy backup image from primary to standby system. Restore database on standby system RESTORE DATABASE SAMPLE REPLACE HISTORY FILE WITHOUT PROMPTING Configure databases for client reroute - Primary UPDATE ALTERNATE SERVER FOR DATABASE SAMPLE USING HOSTNAME <Standby ip address> PORT <inst port> Configure databases for client reroute -Standby UPDATE ALTERNATE SERVER FOR DATABASE SAMPLE USING HOSTNAME <prim ip address> PORT <inst port> Edit /etc/services file and create an HADR port on both systems. On Windows: notepad %SystemRoot%\system32\drivers\etc\services Add HADR line on both primary and standby system. Same port number. ie. DB2_HADR1 Update HADR configuration parameters on primary database UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_HOST <prim ip> UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_SVC DB2_HADR1 UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_HOST <sb ip> UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_SVC DB2_HADR1 UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_INST DB2 UPDATE DB CFG FOR SAMPLE USING HADR_SYNCMODE NEARSYNC UPDATE DB CFG FOR SAMPLE USING HADR_TIMEOUT 120 Enable cfg changes by forcing off all connections CONNECT TO SAMPLE QUIESCE DATABASE IMMEDIATE FORCE CONNECTIONS UNQUIESCE DATABASE CONNECT RESET Update HADR configuration parameters on standby database - -UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_HOST <sb ip> UPDATE DB CFG FOR SAMPLE USING HADR_LOCAL_SVC DB2_HADR_14 UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_HOST COL27VM UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_SVC DB2_HADR_13 UPDATE DB CFG FOR SAMPLE USING HADR_REMOTE_INST DB2 UPDATE DB CFG FOR SAMPLE USING HADR_SYNCMODE NEARSYNC UPDATE DB CFG FOR SAMPLE USING HADR_TIMEOUT 120 Start HADR on standby database DEACTIVATE DATABASE SAMPLE 55005
START HADR ON DATABASE SAMPLE AS STANDBY Start HADR on primary database DEACTIVATE DATABASE SAMPLE START HADR ON DATABASE SAMPLE AS PRIMARY View status of HADR
=>db2 takeover hadr on db <dbname> Takeover Primary operation on the standby db when the original primary is down =>db2 takeover hadr on db <dbname> by force