Db2 LUW Administration Basic Commands
Db2 LUW Administration Basic Commands
Db2 LUW Administration Basic Commands
Administration
Basic Commands for
Absolute Beginners
Instance
CLP Command Description
db2start Starts the database manager
instance.
db2stop <force> Stops the database manager
instance.
db2ilist List the database Instances
db2level Lists DB2 Software Level
db2licm -l Lists the License status
db2ls List the DB2 Product Installed
db2 get instance Returns the current instance.
export DB2INSTANCE=instance_name Switching the instance
db2 terminate
db2 get dbm cfg Instance level configuration settings
db2 get dbm cfg show detail Instance Level current and delayed
values
db2 update dbm cfg using Updates the instance configuration
<parameter> <value> parameter
db2 list active databases Lists active databases and number
of connections.
db2 list application [show Currently connected applications.
detail]
db2 force application (handle1 Disconnects specific application(s)
[,handle2,..,handlen])
db2 force application all Disconnects all applications from all
the database under the instance.
db2 attach to <node> user Attaches to remote instance
<userid> using <pwd>
Database
db2 create database <dbname> Creates Database
db2 drop database <dbname> Drop a database
db2 activate database <dbname> Explicitly activates the database.
db2 deactivate database Explicitly deactivates the database.
<dbname>
db2 connect to <dbname> Connects to database
[ [user <userid>] using <pwd>]
db2 connect reset Disconnects from current database.
db2 get connection state Identifies which database you are
connected to.
db2 get db cfg for <dbname> Database configuration
db2 get db cfg [show detail] Database configuration current
and delayed
db2 update db cfg for <dbname> Updates database
using <parameter> <value> configuration
db2 list tables Lists tables in the database
[for {user | all | system |
schema <schemaname>}] [show
detail]
db2 describe table <tablename> Displays column information for a
table or view.
db2 list tablespaces [show Displays table space ID, name,
detail] type, contents and state.
db2 list tablespace containers Displays container information
for <tablespace_id> [show
detail]
db2 quiesce tablespaces for Resets the state of a table space to
table <tablename> reset normal.
Quiesce Command
db2 quiesce instance Quiesce Instance
<InstanceName> immediate
force connections
db2 quiesce db immediate Quiesce Database
Help
db2 ? SQLCODE Displays the information about the
Error Code
db2 ? COMMAND_NAME Displays the help about the
command
db2licm -h -h option to display help about the
comands
db2 get dbm cfg | findstr Location where db2diag.log file is
DIAGPATH stored which is one-stop file for all
DB2 Errors.
db2pd
db2pd -h db2pd help
db2pd - Status of the Instance
db2pd -alldbs - Status of all the databases
db2pd -db <dbname> -tablespaces Show the tablespaces
Some of the important SYSCAT tables are
Performance
db2 get monitor switches Returns the state of the session’s
monitor switches.
db2 update monitor switches Sets the state of the session
using <monitor> <on|off> monitor switch for <monitor>.
db2 reset monitor all Resets performance monitor values.
db2 get snapshot for dbm Returns performance information at
the instance level.
db2 get snapshot for all on Returns all performance
<dbname> information at the database level
for database <dbname>.
db2 get snapshot for dynamic Returns the contents of the dynamic
sql on <dbname> SQL cache.
db2 runstats on table Gathers statistics for table
<tbschema>.<tbname> <tbname>. Table name must be
fully qualified with <dbschema>.
db2 reorgchk on table all Determines if tables need to be
reorganized. Useful for
automatically performing runstats
on all tables.
db2 reorg table <tablename> Reorganizes a table by
reconstructing the rows to eliminate
fragmented data and compacting
information.
Administration
db2 export Extracts database data into a flat
file.
db2 import Imports data into the database
using the IMPORT utility.
db2 load Imports data into the database
using the LOAD utility.
db2 load query table <tbname> Returns the progress of the LOAD
[to local-message-file] utility.
[nosummary | summaryonly]
[showdelta]
db2 backup database <dbname> Performs a database backup.
[to <path>]
db2 restore database <dbname> Performs a database restore.
[from <path>]
Security
UPDATE DBM CFG USING SYSTEM
SYSADM_GROUP group_name SYSADM, SYSCTRL, SYSMAINT,
SYSMON
UPDATE DBM CFG USING
SYSCTRL_GROUP group_name
REVOKE USE
OF TABLESPACE
[TablespaceName]
FROM [Forfeiter, …..] <BY
ALL>
GRANT [Privilege, …..] SCHEMA
ON SCHEMA [SchemaName] CREATEIN, ALTERIN, DROPIN
TO [Recipient, …..] <WITH
GRANT OPTION>
REVOKE CONTROL
ON INDEX [IndexName]
FROM [Forfeiter, …..] <BY
ALL>
GRANT EXECUTE ON ROUTINE
[RoutineName EXECUTE (Explicit required)
|FUNCTION <SchemaName.> *
|PROCEDURE <SchemaName.> *
|METHOD * FOR [TypeName]
|METHOD * FOR
<SchemaName.> *]
TO [Recipient, …..] <WITH
GRANT OPTION>
REVOKE EXECUTE ON
[Routine Name
|FUNCTION <SchemaName.> *
|PROCEDURE <SchemaName.> *
|METHOD * FOR [TypeName]
|METHOD * FOR
<SchemaName.> *]
FROM [Forfeiter, …..] <BY
ALL>
RESTRICT
GRANT [Privilege, …..] PACKAGE
ON PACKAGE CONTROL, BIND (Explicit
<SchemaName.>[PackageID] required to Bind), EXECUTE
TO [Recipient, …..] <WITH (Implicit)
GRANT OPTION>
Help
db2 ? SQLCODE Displays the information about the
Error Code
db2 ? COMMAND_NAME Displays the help about the
command
db2licm -h -h option to display help about the
comands
db2 get dbm cfg | findstr Location where db2diag.log file is
DIAGPATH stored which is one-stop file for all
DB2 Errors.
db2pd -h Problem Determination Tool.
Multiple Options and mastery over
this tool will allow you to solve many
db2 problems
SYSCAT Schema Data Dictionary schema which
contains multiple views which
details
LIST HISTORY-- List History
+-------------------+----->
+-BACKUP------------+
+-ROLLFORWARD-------+
+-DROPPED TABLE-----+
'-ARCHIVE LOG-------'
+-ALL-----------+-->
+-SINCE--
timestamp-------------------+
FOR--+-DATABASE-+--database-
alias------>
Steps
1. Locate the table from syscat schema using below command
3. Form the SQL query to get the data required e.g. from SYSCAT.TABLES
More on db2pd
db2pd utility is designed to retrieve information, in a non-intrusive manner, from
appropriate DB2 database system memory sets and produce a thorough report
that can be used to monitor or troubleshoot a database system (or any
component of a database system).
You can use db2pd command for monitoring and troubleshooting because it can
return quick and immediate information from DB2 memory sets.
Overview
The tool collects information without acquiring any latches or using any engine
resources. It is therefore possible (and expected) to retrieve information that is
changing while db2pd is collecting information; hence data might not be
completely accurate. If changing memory pointers are encountered, a signal
handler is used to prevent db2pd from ending abnormally. This can result in
messages such as "Changing data structure forced command termination" to
appear in output. Nonetheless, tool can be helpful for troubleshooting. Two
benefits to collecting information without latching include faster retrieval and no
competition for engine resources.
db2pd
<-inst>
<-database [DatabaseName] ,... | -alldatabases>
<-everything>
<-full>
Example:
Diagnosing a lockwait
Example:
Using -wlocks parameter to capture all locks being waited on.
Example:
Using -apinfo parameter to capture detailed runtime information about lock
owner and lock waiter
Use
db2 list applications to get appid
Example:
Using callout scripts when considering a locking problem
To use callout scripts, find db2cos output files. Location of files is controlled by
database manager configuration parameter diagpath. Contents of output files
will differ depending on what commands you enter in db2cos script file.
Example:
Mapping an application to a dynamic SQL statement
Use -applications -dynamic to report current and last anchor ID and statement
unique ID for dynamic SQL statements. This allows direct mapping from an
application to a dynamic SQL statement.
Example:
Monitoring memory usage
Option -memblock can be useful when you are trying to understand memory
usage.
db2pd -memblock
You can also report memory blocks for private memory on UNIX and Linux
operating systems.
Example:
Monitoring recovery
To verify that recovery is progressing and show several counters. Current Log
and Current LSO values provide log position.
db2pd -recovery
Example:
Determining amount of resources a transaction is using
To show number of locks, first log sequence number (LSN), last LSN, first LSO,
last LSO, log space used, and space reserved. This can be useful for
understanding behavior of a transaction.
db2pd -transactions
Example:
Monitoring log usage for a Database
By using Pages Written value, you can determine whether log usage is
increasing:
db2pd -logs
Note: S0000003.LOG and S0000004.LOG do not contain any log records yet
and therefore StartLSN is 0x0
If you issue db2pd command with -edus parameter option, output lists all engine
dispatchable units (EDUs). Output for EDUs can be returned at level of
granularity you specify, such as at instance level or at member. On Linux and
UNIX operating systems only, you can also specify interval parameter suboption
so that two snapshots of all EDUs are taken, separated by an interval you
specify. When interval parameter is specified, two additional columns in output
indicate delta of processor user time (USR DELTA column) and delta of
processor system time (SYS DELTA column) across interval.
In following example, deltas for processor user time and processor system time
are given across a five-second interval:
Example:
Monitoring progress of index reorganization
In DB2 9.8FP3 and later fix packs, progress report of an index reorganization has
following characteristics:
• db2pd -reorgs index command reports index reorg progress for partitioned
indexes (FP1 introduced support for only non-partitioned indexes).
• db2pd -reorgs index command supports monitoring of index reorg at
partition level (that is, during reorganization of a single partition).
Results
Following is an example of output obtained using db2pd command with the-
reorgs index parameter, which reports index reorganization progress for a
range-partitioned table with two partitions.
Example:
Monitoring progress of RUNSTATS operations
You can use LIST UTILITIES command or db2pd command to monitor progress
of RUNSTATS operations on a database.
Procedure
Issue LIST UTILITIES command and specify SHOW DETAIL parameter:
Example:
Monitoring a rollforward operation
You can use db2pd or LIST UTILITIES command to monitor progress of
rollforward operations on a database.
Procedure
Issue LIST UTILITIES command and specify SHOW DETAIL parameter
db2pd -recovery
Results
For rollforward recovery, there are two phases of progress monitoring:
FORWARD and BACKWARD. During FORWARD phase, log files are read and
log records are applied to database. For rollforward recovery, when this phase
begins UNKNOWN is specified for total work estimate. Amount of work
processed in bytes is updated as process continues.