Instance-level operations:
Start the current instance with db2start
Db2stop
Create a new instance using db2icrt
Db2idrop delete an instance
Db2ilist: displays the list of all your current instances.
DB2 get instance displays the currently running instance
Database-level operations:
DB2 create database creates a new database
DB2 drop database delete a database
DB2 connect to <database_name> connect to the database
DB2 create table/create view/create index create SQL statements for tables, views, and indexes respectively
DB2 list database directory view several databases on the database server
With the creation of a database, several default objects are also created: tablespace, table, buffer pool, and log files.
The syscatspace tablespace contains a directory table (Catalog ). This directory also exists in other relational database management systems as a data dictionary.
It contains unmodifiable and unrecoverable system information, otherwise the database will not work properly.
Table space tempspace1 is used when DB2 performs operations that require additional space such as sorting.
If no space is specified during table creation, the system usually uses userspace1 to store your database table.
A DB2 server can be configured on four levels:
1. System Environment Variables
Set db2instance = myinst
2. Database Manager configuration file (dbm cfg)
DB2 get dBm CFG re-obtains the information of DBM cfg
DB2 update dBm CFG using <parameter_name> <value> updates the parameter information of DBM cfg
3. database configuration file (db cfg)
Get dB CFG for <database_name> re-obtain the db cfg information of the specified database
Update dB CFG for <database_name> using <parameter_name> <value> Update dB cfg parameter value
4. DB2 profile Registry
The db2set-All List displays all the currently set DB2 profile registry Variables
The db2set-LR List displays the Registry variables of all DB2 profiles.
Db2set <parameter >=< value> to set a parameter to a specified value
Lab operation:
1. Create a new instance named newinst from the command window
Db2icrt newinst
2. In the newinst instance, use the default value to create a database named newdb.
Set db2instance = newinst
Db2start
DB2 create database newdb
3. list all instances on the server
Db2ilist
4. Switch to the DB2 instance and confirm that the conversion is successful.
Set db2instance = DB2
Pediatrics
DB2 get instance
5. Change the federated parameter value of dbm cfg from no to yes and verify the Modification result.
DB2 update dBm CFG using federated Yes
DB2 Force applications all
DB2 terminate
Db2stop
Db2start
DB2 get dBm cfg
6. Use the username and password used to log on to the operating system to connect to the sample database.
DB2 connect to sample user <userid> using <psw>
7. view the number of applications on the current instanceProgramRunning
DB2 list applications show detail
8. Open another DB2 command window without specifying the user name and password to connect to the sample database. Then, check how many applications are connected to the instance.
DB2 connect to sample
DB2 list applications
Container Freight
9. Force close a DB2 command window
DB2 force <Application> (<Application> db2bp.exe "handle, which is obtained by the DB2 list appli-cations command)
10. Delete instance newinst
Db2idrop newinst
11. Delete and recreate the DAS, and then start the DAS
Db2admin stop
Db2admin drop
Db2admin create
Db2admin start
12. Set DB2 registration variable db2comm in your instance to TCPIP, npipe
Db2set db2comm = TCPIP, npipe
Db2stop
Db2start
13. Leave empty the db2comm registration variable
Db2set db2comm =
Db2stop
Db2start
14. Check the logsecond parameter of the current dB CFG, set the value to 5, and verify the new value.
DB2 connect to sample
DB2 get dB cfg
DB2 update dB CFG using logsecond 5
DB2 get dB cf
Common tool commands:
Command editor db2ce
Command Line processor DB2
Command window (only on Windows platforms) db2cmd
Control center db2cc
Task center db2tc
Health Center db2hc
Configuration assistant db2ca
First steps db2fs
After the database runs for a period of time, the tables in the database will be modified due to update, delete, insert, and other operations, and the database files will be split. We need to regularly reorg.
If reorg is executed, we recommend that you run runstats and rebind.