DB2 database startup and shutdown __ Database

Source: Internet
Author: User
Tags db2 db2 connect db2 connect to server port

Under a DB2 instance, you can create multiple database (how many databases can be created under each instance, which can be viewed through the DB2 get DBM cfg. Once the database is established, it can be manipulated, however, Before you can create objects in a database or Access objects (data) in a database, you must first know how to start and stop the database.
This section provides a brief description of how DB2 database implements startup and stop through command line.
Activating a database
If a connect to database_name or an implicit connection is used in the application before the database is activated, then the application must wait. Know that the database manager has started the database you want to connect to. Generally the first application raises all the overhead of waiting for Database Manager to perform database startup.
We can also use commands such as activate database database_name to launch specific databases. This command eliminates the time it takes to wait for the database to initialize when the first application is connected. In general, the DB2 DBA activates all necessary databases in advance.
Note: 1 If the application for the Activate Database command has already established an active database connection with one of the databases, the error message is returned back.
2 If the database that requires a reboot (restart) accepts a activate DB command, the Activate Database command works like a connect to or an implicit connection.
3 If the database is configured
Enabled automatic reboot (autorestart) = On
The database will then be restarted before the Activate DB command initializes it.
View configuration parameters for the specified database
--Default
DB2 get DB CFG for study
--Split-screen display
DB2 get DB CFG for study | More
--Save display results in Study.txt file
DB2 get DB CFG for study > Study.txt

Here is an example where I created 3 database under the current DB2 instance, and I used the activate command to activate them one at a a

D:DB2BIN>DB2 Db2start
Db20000i db2start Command completed successfully.
D:DB2BIN>DB2 List Database Directory
System Database Directory
Number of entries in the directory = 3
Database 1 Item:
Database alias = TEST
Database name = TEST
Local Database directory = D:db2test
Database Release level = c.00
Comment = Test
Directory Entry Type = Indirect
directory database partition Number = 0
Alternate server Host name =
Alternate server port number =
Database 2 Item:
Database alias = Bank
Database name = Bank
Local Database directory = D:db2bank
Database Release level = c.00
Comment = Bank
Directory Entry Type = Indirect
directory database partition Number = 0
Alternate server Host name =
Alternate server port number =
Database 3 Item:
Database alias = STUDY
Database name = STUDY
Local Database directory = D:db2study
Database Release level = c.00
Comment = STUDY
Directory Entry Type = Indirect
directory database partition Number = 0
Alternate server Host name =
Alternate server port number =
D:DB2BIN>DB2 List Active databases
SQL1611W "Database System Monitor" does not return any data.
D:DB2BIN>DB2 Activate database study
db20000i ACTIVATE Database command completed successfully.
D:DB2BIN>DB2 List Active databases
Active database
Database name = STUDY
The currently connected Application = 0
Database path = d:db2studydb2node0000sql00001
D:DB2BIN>DB2 Activate Database Bank
db20000i ACTIVATE Database command completed successfully.
D:DB2BIN>DB2 List Active databases
Active database
Database name = STUDY
The currently connected Application = 0
Database path = d:db2studydb2node0000sql00001
Database name = Bank
The currently connected Application = 0
Database path = d:db2bankdb2node0000sql00001
D:DB2BIN>DB2 Activate database test
db20000i ACTIVATE Database command completed successfully.
D:DB2BIN>DB2 List Active databases
Active database
Database name = STUDY
The currently connected Application = 0
Database path = d:db2studydb2node0000sql00001
Database name = Bank
The currently connected Application = 0
Database path = d:db2bankdb2node0000sql00001
Database name = TEST
The currently connected Application = 0
Database path = d:db2testdb2node0000sql00001
D:db2bin> Stop Database

Databases initialized by the Activate Database command can be shut down by the Deactivate database command or terminated by the Stop DB Manager (or db2stop) command.

If you initialize a database with the Activate DB command, the last application disconnected from the database will not close the database. You must use the Deactivate database. In this case, the Stop Database Manager ( Or db2stop closes the database and terminates the instance.

If you use connect to or implicitly connect to the startup database, and then another application issues the Activate Database command for the same databases, you must close the database using the Deactivate Database command. If activate is not used Database starts the databases, the database shuts down when the last application disconnects from the database.

Example one: Database started with connect to mode

D:DB2BIN>DB2 List Active databases
SQL1611W "Database System Monitor" does not return any data.
D:DB2BIN>DB2 Connect to study-connecting to the study database automatically activates the study database
Database connection Information
Database Server = Db2/nt 9.5.0
SQL Authorization id = zhangrp
Local Database alias = STUDY
D:DB2BIN>DB2 List Active databases
Active database
Database name = STUDY
The currently connected Application = 1
Database path = d:db2studydb2node0000sql00001

Description: The database is activated and there is an application attached (on the above connect to study operation)
D:DB2BIN>DB2 Connect Reset--Disconnect
Db20000i SQL command completed successfully.
D:db2bin>
D:DB2BIN>DB2 List Active databases
SQL1611W "Database System Monitor" does not return any data.

D:db2bin>

Note: You can find that the above connection is disconnected, the database study also automatically stop (because this study database is activated by connect to)
Example two: Databases launched using the Activate database

D:DB2BIN>DB2 list Active Databases--no databases started at this time
SQL1611W "Database System Monitor" does not return any data.
D:DB2BIN>DB2 Activate database Study--activating study databases with activate DB
db20000i ACTIVATE Database command completed successfully.
D:DB2BIN>DB2 list Active Databases--you can see that study data is activated, but no connection is applied.
Active database
Database name = STUDY
The currently connected Application = 0
Database path = d:db2studydb2node0000sql00001
D:DB2BIN>DB2 Connect to study--initiates a connection to the study database
Database connection Information
Database Server = Db2/nt 9.5.0
SQL Authorization id = zhangrp
Local Database alias = STUDY
D:DB2BIN>DB2 list Active Databases--look at the active database and find an application connection on the study database.
Active database
Database name = STUDY
The currently connected Application = 1
Database path = d:db2studydb2node0000sql00001
D:DB2BIN>DB2 Connect Reset--Close the connection just to see if the database will automatically shut down
Db20000i SQL command completed successfully.
D:DB2BIN>DB2 list Active databases--database still started, although no connection
Active database
Database name = STUDY
The currently connected Application = 0
Database path = d:db2studydb2node0000sql00001
D:DB2BIN>DB2 Deactivate database Study--shutting down databases using the Deactivate database command
db20000i DEACTIVATE Database command completed successfully.
D:db2bin>
D:DB2BIN>DB2 List Active databases
SQL1611W "Database System Monitor" does not return any data.
D:db2bin>

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.