DB2 Common Command Summary "turn"

Source: Internet
Author: User
Tags db2 connect db2 connect to db2 create table db2 describe table switches

Go from DB2 script House: http://www.jb51.net/article/20497.html

1. Open the Command Line window
#db2cmd
2. Open the control center
# Db2cmd DB2CC
3. Open the Command editor
Db2cmd Db2ce
===== Operation Database Command =====

4. Start the DB instance
#db2start

5. Stop the DB instance
#db2stop

If you cannot stop the database due to the active connection, execute DB2 force application before running db2stop all to/db2stop force
6. Create a database
#db2 Create DB [dbname]
7. Connect to the database
#db2 connect to [dbname] user [username] using [password]
8. Disconnect the database
#db2 Connect Reset
9. List all databases
#db2 List db Directory

10. List all active databases
#db2 List Active databases
11. List all database configurations
#db2 Get DB cfg
12. Delete Database
#db2 drop database [dbname]
(Take care to do this)
If you cannot delete, disconnect all database connections or restart DB2

========= Operation Data Sheet command ==========
13. List all user tables
#db2 List Tables
14. List all system tables
#db2 List Tables for system
15. List all Tables
#db2 List Tables for all
16. List system tables
#db2 List Tables for system
17. List User Tables
#db2 List Tables for user
18. List specific user tables
#db2 list tables for schema [user]
19. Create a new table (T1) with the same structure as a table (T2) in the database
#db2 CREATE table T1 like T2
20. Import data from one table T1 to another table T2
#db2 "INSERT INTO T1 select * from T2"
21. Enquiry Form
#db2 "SELECT * from table name where ..."
22. Display table Structure
#db2 describe table tablename
23. Modify Columns
#db2 ALTER TABLE [TABLENAME] ALTER COLUMN [COLUMNAME] SET data type varchar (24)
====== script file Operations Command =======
24. Execute script File
#db2-TVF Scripts.sql
25. Help command
* View command Help
#db2? Db2start
* View error code information
#db2? 22001
* Memo: Please use "DB2" for detailed commands. <command> "to view.
=========================
26. Backing Up the database
#db2 Backup DB <db name>
Note: The database connection needs to be disconnected before executing the above command

27. Online BACKUP Database
#db2-v BACKUP DATABASE <database name> ONLINE to <path> with 2 buffers BUFFER 1024x768 INCLUDE LOGS without PROM Pting "
28. Restore the Database
#db2 Restore DB <source db name>

29. Online Recovery Database
#db2 "RESTORE DB <database name> to <db path> logtarget <logpath> without prompting"
#db2 "Rollforward DB <database name> to END of LOGS and STOP" ...
30. Export Data File

#db2move <db name> Export

[-SN < mode name, generally db2admin>]
[-tn < table name, multiple separated by commas;]
31. Import data Files
#db2move <db name> Import
32. Get DB2 Database management configuration environment information
#db2 get dbm CFG
33. Get DB2 a database Database management configuration environment information
#db2 get db cfg for <db name>

Or: Execute DB2 get DB CFG after connecting to a database

34. Change the size of the DB2 log space
Note: In order to prevent the DB2 database from using hard disk space, the following command is only used for DB2 on the developer's own machine, and if it is a server, the parameters need to be modified.

#db2 UPDATE DB CFG for <db name> USING logretain OFF logprimary 3 logsecond 2 logfilsiz 25600;
If the page size is 4KB, the above command creates 3 100M log files that occupy 300MB of hard disk space. 25600*4kb=102400kb.
35. Create a temporary table space
#DB2 CREATE USER Temporary tablespace stmaspace PAGESIZE-K MANAGED by DATABASE USING (FILE ' D:\DB2_TAB\STMASPACE. F1 ' 10000)
Extentsize 256
36. Get snapshot data for Database Manager
#db2 –v get snapshot for dbm
37. Show the process number
#db2 List Applications Show Detail
===================================================
First, load the data:
1, loaded with default delimiter, default to "," number
DB2 "Import from Btpoper.txt of del insert INTO Btpoper"
2. To specify the delimiter "|" Load
DB2 "Import from Btpoper.txt of Del Modified by coldel| INSERT INTO Btpoper "
Second, unload data:
1. Unload all data in a table
DB2 "Export to Btpoper.txt of del select * from Btpoper"
DB2 "Export to Btpoper.txt of Del Modified by coldel| SELECT * FROM Btpoper "
2. Unloading data in a table with conditions
DB2 "Export to Btpoper.txt of del select * from Btpoper where brhid= ' 907020000 '"
DB2 "Export to Cmmcode.txt of del select * from Cmmcode where codtp= ' 01 '"
DB2 "Export to Cmmcode.txt of Del Modified by coldel| SELECT * from Cmmcode where codtp= ' 01 ' "
Third, query data structure and information:
DB2 "SELECT * FROM Btpoper"
DB2 "SELECT * from Btpoper where brhid= ' 907020000 ' and oprid= ' 0001 '"
DB2 "Select OPRID,OPRNM,BRHID,PASSWD from Btpoper"
Iv. Delete data from the table:
DB2 "Delete from Btpoper"
DB2 "Delete from Btpoper where brhid= ' 907020000 ' or brhid= ' 907010000 '"
Five, modify the table data:
DB2 "Update svmmst set prtlines=0 where brhid= ' 907010000 ' and jobtp= ' 02 '"
DB2 "Update svmmst set prtlines=0 where jobtp= ' or jobtp= ' 03 '"
Vi. joining the database
DB2 Connect to Btpdbs
VII. Clearing Database joins
DB2 Connect reset Disconnects the database
DB2 Terminate disconnecting the database
DB2 force applications all disconnects all database connections
Viii. backing up the database
1. DB2 Backup DB Btpdbs
2. Db2move Btpdbs Export
db2look-d btpdbs-e-X [-a]-o crttbl.sql
ix. Recovery of the database
1. DB2 restore DB Btpdbs without rolling forward
2, DB2-TVF Crtdb.sql
Crtdb.sql file contents: Create DB Btpdbs On/db2catalog
DB2-STVF Crttbl.sql
Db2move Btpdbs Import
Ten, DB2 help command:
DB2?
DB2? Restroe
DB2? Sqlcode (Example: DB2 sql0803) Note: code must be 4 digits, not enough 4 bits, front 0

Xi. bind command: Bind the application to the database, each time the database is restored, it is recommended
(1) DB2 bind BR8200.BND
(2)/btp/bin/bndall/btp/bnd
/btp/bin/bndall/btp/tran/bnd
12. View Database parameters:
DB2 get dbm CFG
DB2 get DB CFG for Btpdbs
13. Modify Database parameters:
DB2 Update DB CFG for Btpdbs using LOGBUFSZ 20
DB2 Update DB CFG for Btpdbs using LOGFILSIZ 5120
After you have changed, you should execute the following command to make it effective:
DB2 stop
DB2 start

Add:
DB2 Set schema BTP modify the current mode to "BTP"
DB2 List tablespaces Show Detail view current database table space allocation status
DB2 list tablespace containers for 2 show Detail view tablespace id=2 using the directory where the container is located
DB2 List Application
DB2 List DB directory lists all databases
DB2 list Active databases lists all active databases
DB2 list tables for all lists all tables under the current database
DB2 list tables for schema BTP lists tables in the current database with schema BTP
DB2 List tablespaces show detail Show Database space usage
DB2 List packages for all

DB2 "Import from TAB76.IXF of Ixf Commitcount, insert into Achact"
DB2 "CREATE table achact_t like Achact"
DB2 "Rename table achact_t to Achact"
DB2 "INSERT INTO achact_t select * from Achact where txndt>= (select Lstpgdt from
Acmact where Actno=achact.actno) "
DB2 get snapshot for Dynaimic SQL on Jining
To delete an instance:
# cd/usr/lpp/db2_07_01/instance
#./db2idrop Instname
List all DB2 instances:
# Cd/usr/lpp/db2_07_01/bin
#./db2ilist
Creating catalogs for databases
$ DB2 Catalog DB Btpdbs On/db2catalog
Canceling a cataloged database Btpdbs
$ DB2 Uncatalog DB Btpdbs
View version
# Db2level
Display the current database management instance
$ DB2 Get Instance
Sets whether the instance system starts automatically when it starts.
$ db2iauto-on Auto-start
$ db2iauto-off does not start automatically
Database Optimization Commands:
Reorg, Runstats
As the database is used over time, the data space becomes more and more large. Some delete out
Data is still stored in the database, occupying data space, affecting system performance. It is therefore necessary to periodically
Run the reorg, runstats command to purge deleted data and optimize data structures.
DB2 reorg Table Name
DB2 runstats on table name with distribution and indexes all
Since the table to be optimized is much more, a SH program runsall is provided under the/btp/bin directory,
Runsall can be run at the end of the day to optimize the database

During the development of DB2, it is important to maintain the database in the whole development process, and it is necessary to maintain a large information system, and to leave a simple maintenance manual for a rainy day; some of the maintenance commands collected below are for our maintenance engineers and project managers.
=================================================================
38. Change the size of the DB2 log space
Note: In order to prevent the DB2 database from using hard disk space, the following command is only used for DB2 on the developer's own machine, and if it is a server, the parameters need to be modified.
# DB2 UPDATE DB CFG for <db name> USING logretain OFF logprimary 3 logsecond 2 logfilsiz 25600;
If the page size is 4KB, the above command creates 3 100M log files that occupy 300MB of hard disk space. 25600*4kb=102400kb.
39. Create a temporary table space
#DB2 CREATE USER Temporary tablespace stmaspace PAGESIZE-K MANAGED by DATABASE USING (FILE ' D:\DB2_TAB\STMASPACE. F1 ' 10000) extentsize 256
40. CREATE TABLE Space
REM Create buffer pool space 8K
#db2 Connect to gather
#db2 CREATE bufferpool stmabmp IMMEDIATE SIZE 25000 PAGESIZE 8K
REM Create tablespace: STMA
REM must confirm that the path is correct
REM D:\DB2CONTAINER\STMA
#db2 Drop Tablespace Stma
#db2 CREATE REGULAR tablespace stma PAGESIZE 8 K MANAGED by SYSTEM USING (' D:\DB2Container\Stma ') Extentsize 8 OVERHEAD 1 0.5 prefetchsize 8 transferrate 0.14 bufferpool stmabmp DROPPED TABLE RECOVERY OFF
#db2 Connect Reset
41. Restore pending data to roll forward status
#db2 rollforward DATABASE TESTDB to END of LOGS and complete Noretrieve

42. Backup Table Space
#BACKUP DATABASE YNDC tablespace (USERSPACE1) to ' D:\temp ' with 2 buffers BUFFER 1024x768 PARALLELISM 1 without prompting
43. Create DB2 Tool database
#db2 Create Tools Catalog SysTools Create new Database Toolsdb
44. How to make incremental/differential backup
Increment: The portion of data that was added between the last full backup and the backup;
Difference (Delta): The portion of data that has been added to this backup since the last backup, possibly a full, incremental, or differential backup;
45. Update STATISTICS for all tables
#db2-V Connect to Db_name
#db2-V "select Tbname, Nleaf, Nlevels, Stats_timefrom sysibm.sysindexes"
#db2-v reorgchkupdate statistics on table all
#db2-V "select Tbname, Nleaf, Nlevels, Stats_timefrom sysibm.sysindexes"
#db2-V Terminate

46. Run statistics on a single table
#db2-v Runstatson table Tab_nameand Indexes all
47. See if Runstats is performed on the database
#db2-V "select Tbname, Nleaf, Nlevels,stats_timefrom sysibm.sysindexes"
48. Change the size of the buffer pool
Buffer pool, when Syscat.bufferpools's npages is-1, the size of the buffer pool is controlled by the configuration parameters of the database bufferpage.
Change the value of npages to the command of-1:
#db2-V Connect to Db_name
#db2-V SELECT * from Syscat.bufferpools
#db2-V Alter BUFFERPOOLIBMDEFAULTBP SIZE-1
#db2-V Connect Reset
#db2-V Terminate
The command to change the database configuration parameter bufferpages is as follows:
#db2-V Update db cfgfor dbnameusing BUFFPAGE bigger_value
#db2-V Terminate
49, look at the database monitoring content list
#db2-V Get monitor switches
50. Open a database monitoring content
#db2-V Update monitor switches using Bufferpoolon
51. Get a snapshot of a database
#db2-V Get snapshot for all databases > Snap.out
#db2-V Get snapshot for dbm>> snap.out
#db2-V Get snapshot for all bufferpools>> snap.out
#db2-V Terminate

52. Resetting the Database snapshot
#db2-V Reset Monitor all
53. Calculate the buffer pool hit rate
Ideally, the buffer pool hit rate is above 95% and the formula is as follows:
(1-(Buffer pool data physical reads + buffer pool Index physical reads)
/(Buffer pool data logical reads + Pool index logical reads)) *100%
========= DB Instance ========================
54. Create DB2 instances
#db2icrt < Instance name >
55. Delete DB2 Instances
#db2idrop < Instance name >
56. Set the current DB2 instance
#set DB2INTANCE=DB2
57. Display DB2 owned instances
#db2ilist
58. Restore the offline incremental backup DATABASE command
#DB2 RESTORE DATABASE yndc INCREMENTAL AUTOMATIC from D:\backup\autobak\db2 taken at 20060314232015
59. Create a sample database
On UNIX platforms, use:
#sqllib/bin/db2sampl <path>
On the WINDOWS,OS/2 platform, using: Db2sampl e,e is an optional parameter that specifies the drive that will create the database

60. Set the federated database to be available (the default federated database is unavailable)

#db2 update dbm CFG using federated Yes

61. List all tables in the database
#db2 List Tables
62. Data Migration Method 1
Export Script Example
#db2 Connect to TestDB user test password test
#db2 "Export to AA1.IXF of IXF select * FROM table1"
#db2 "Export to AA2.IXF of IXF select * from Table2"
#db2 Connect Reset
Import Script Example
#db2 Connect to TestDB user test password test
#db2 "Load from AA1.IXF of IXF replace into table1 COPY NO without prompting"
#db2 "Load from AA2.IXF of IXF replace into table2 COPY NO without prompting"
#db2 Connect Reset

DB2 Common Command Summary "turn"

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.