首页 > Linux操作系统 > Linux操作系统 > IBM DB2 笔记
applications can be run against them. Because of these independent environments, databases in
separate instances can have the same name.
When DB2 is installed on the Windows platform, an instance named DB2 is created by default.
In the Linux and UNIX environments, if you choose to create the default instance, it is called
db2inst1.
To create an instance explicitly, use
db2icrt instance_name
To drop an instance, use
db2idrop instance_name
To start the current instance, use
db2start
To stop the current instance, use
db2stop
To start the DAS, use the following command:
db2admin start
To stop the DAS, use the following command:
db2admin stop
Like many other RDBMSs, DB2 uses different mechanisms to influence the behavior. of the
database management system. These include
• Environment variables
• DB2 profile registry variables
• Configuration parameters
Environment variables are defined at the operating system level.
set DB2INSTANCE=DB2 (on Windows)
or
export DB2INSTANCE=DB2 (on Linux and UNIX)
The DB2 Profile Registry is divided into four categories:
• The DB2 instance-level profile registry
• The DB2 global-level profile registry
• The DB2 instance node-level profile registry
• The DB2 instance profile registry
db2set -lr
To set the value of a specific variable (in this example, DB2INSTPROF) at the global level, use
db2set DB2INSTPROF="C:\PROGRAM FILES\SQLLIB" -g
To set a variable at the instance level for instance myinst, use
db2set DB2INSTPROF="C:\MY FILES\SQLLIB" -i myinst
Configuration parameters are defined at two different levels: the instance level and the database
level. The variables at each level are different (not like DB2 registry variables, where the same
variables can be defined at different levels).
To view the contents of the Database Manager Configuration file, issue the command:
db2 get dbm cfg
To update the value of a specific parameter, use
db2 update dbm cfg using parameter value
For example
db2 update dbm cfg using INTRA_PARALLEL YES
To view the contents of the Database Configuration file, issue the command:
db2 get db cfg for dbname
For example
db2 get db cfg for mydb2
To update the value of a specific variable, use
db2 update db cfg for dbname using parameter value
For example
db2 update db cfg for mydb2 using MINCOMMIT 3
In DB2, directories are used to store connectivity information about databases and the servers on
which they reside.
1. System Database Directory
The system database directory (or system db directory) is like the main “table of contents” that contains information about all the databases to which you can connect from your DB2 server.
To list the contents of the system db directory, use the command:
db2 list db directory
To list the contents of the system db directory, use the command:
db2 list db directory
Any entry from the output of this command containing the word Indirect indicates that the entry
is for a local database, that is, a database that resides on the data server on which you are working.
The entry also points to the local database directory indicated by the Database drive item
(Windows) or Local database directory (Linux or UNIX).
Any entry containing the word Remote indicates that the entry is for a remote database—a
database residing on a server other than the one on which you are currently working. The entry
also points to the node directory entry indicated by the Node name item.
To enter information into the system database directory, use the catalog command:
db2 catalog db dbname as alias at node nodename
For example
db2 catalog db mydb as yourdb at node mynode
The catalog commands are normally used only when adding information for remote databases.
For local databases, a catalog entry is automatically created after creating the database
with the CREATE DATABASE command.
2. Local Database Directory
The local database directory contains information about databases residing on the server where you are currently working.
To list the contents of the local database directory, issue the command:
db2 list db directory on drive / path
3. Node Directory
The node directory stores all connectivity information for remote database servers
To list the contents of the node directory, issue the command:
db2 list node directory
To enter information into the node directory, use
db2 catalog tcpip node node_name
remote hostname or IP_address
server service_name or port_number
For example
db2 catalog tcpip node mynode
remote 192.168.1.100
server 60000
4. Database Connection Services Directory
The Database Connection Services (DCS) directory contains connectivity information for host databases residing on System z (z/OS or OS/390) or System i (OS/400) server. You need to have DB2 Connect software installed.
To list the contents of the DCS directory, issue the following command:
db2 list dcs directory
To enter information into the DCS directory, use
db2 catalog dcs db dbname as location_name
For example
db2 catalog dcs db mydb as db1g
Three table spaces—SYSCATSPACE (holding the Catalog tables), TEMPSPACE1 (system temporary
space), and USERSPACE1 (the default user table space)—are automatically created
when you create a database. SYSCATSPACE and TEMPSPACE1 can be considered system
structures, as they are needed for the normal operation of your database. SYSCATSPACE contains
the catalog tables containing metadata (data about your database objects) and must exist at
all times. Some other RDBMSs call this structure a “data dictionary.”
If the database you want to access is MYDB2, which was in the myinst instance, you would first
need to create this instance, switch to the instance, and then issue the catalog command as
shown below.
db2icrt myinst
set DB2INSTANCE=myinst
catalog db mydb2 on h:
It is a good practice to back up the contents of all your configuration files as shown below.
db2 get dbm cfg > dbmcfg.bk
db2 get db cfg for database_name > dbcfg.bk
db2set -all > db2set.bk
db2 list db directory > systemdbdir.bk
db2 list node directory > nodedir.bk
db2 list dcs directory > dcsdir.bk
Database federated support in DB2 allows tables from multiple databases to be presented as
local tables to a DB2 server. The databases may be local or remote; they can also belong to different
RDBMSs.
First of all, make sure that your server allows federated support: The database manager parameter
FEDERATED must be set to YES.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/701797/viewspace-438925/ ,如需转载,请注明出处,否则将追究法律责任。