Table of Contents
- DB2 Installation on Solaris
- Administration
- DB2 Connect Installation on Windows
DB2 Installation on Solaris
Setup
The shmsys:shminfo_shmmax parameters should be set to the suggested value in the above data, or 90% of the physical memory (in bytes), whichever is higher. For example, if you have 196 MB of physical memory in your system, set the shmsys:shminfo_shmmax parameter to 184968806 (196*1024*1024*0.9).
- Setup Solaris kernel configuration parameters. To set a kernel parameter, add a line at the end of the /etc/system file as follows:
- set msgsys:msginfo_msgmax=65535
- set msgsys:msginfo_msgmnb=65535
- set msgsys:msginfo_msgmap=258
- set msgsys:msginfo_msgmni=256
- set msgsys:msginfo_msgssz=16
- set msgsys:msginfo_msgtql=1024
- set msgsys:msginfo_msgseg=32767
- set shmsys:shminfo_shmmax=536870912
- set shmsys:shminfo_shmseg=50
- set shmsys:shminfo_shmmni=300
- set semsys:seminfo_semmni=1024
- set semsys:seminfo_semmap=1026
- set semsys:seminfo_semmns=2048
- set semsys:seminfo_semmnu=2048
- set semsys:seminfo_semume=50
Install Software
- Execute db2_install, as root, in the 008_EEE_SUN32_SBCS directory in db2inst1's home directory.
- Select where software is to install DB2 (/export/home/db2inst1/). [Note that, in Linux, you don't choose the installation destination, it is /opt/IBM]
- Install DB2. (NOTE: IBMdb2/V7.1 directory is created in db2inst1 home directory during installation).
Administration
Create Database Instance
- Execute db2setup, as root, in the IBMdb2/V7.1/install directory.
- Select "[ Create... ]"
- Select "Create a DB2 Instance" and followed the directions.
- After creating the instance, the sqllib and db2inst1 directories appear in db2inst1's home directory (/export/home/db2inst1/). The /db2inst1/NODE0000 directory contains each database directory identified by SQL0000#. The sqllib dir contains admin scripts.
Install Database Administration Server (DAS) Instance
- Execute, as root, "dasicrt" in the /export/home/db2inst1/IBMdb2/V7.1/instance directory. This creates the sqllib directory in db2as1's home directory. db2admin start and db2admin stop commands, start and stop the DAS Instance.
Create Sample Database
- db2sampl creates the SAMPLE database. Three tablespaces are created:
- SYSCATSPACE - This is where the DB2 system catalog, which tracks all of the metadata associated with DB2 objects, is kept. Same as SYSTEM tablespace in Oracle.
- TEMPSPACE1 - A temporary work area for DB2 to place intermediate results.
- USERSPACE1 - A place where all user objects (tables, indexes) reside by default.
Users
Connecting
SYSADM authority is controlled in the DBM CFG via the SYSADM_GROUP parameter. To update the config file: db2 update dbm cfg using SYSADM_GROUP grp1
- Connect to the SAMPLE database by executing: db2 connect to sample as db2inst1 or db2 connect to sample user db2inst1 using db2inst1. The user db2inst1 with password db2inst1 is verified by the operating system. User db2inst1 is successfully connected to the SAMPLE database. This user must have been created by the operating system before connecting to the database.
- All users in PUBLIC are automatically granted the following DB privileges:
- CONNECT - Access the DB
- BINDADD - Create new packages in the DB
- CREATETAB - Create tables
- IMPLICIT_SCHEMA - Create an object and specify a schema name for it that doesn't exist.
- The USE privilege on USERSPACE1 tablespace is the only tablespace privilege and it allows users to create tables within a tablespace. These prileges must be explicitely revoked from PUBLIC.
Killing Users
To list the current connections:db2 => list applications Auth Id Application Appl. Application Id DB # of Name Handle Name Agents -------- -------------- ---------- ------------------------------ -------- ----- DB2INST1 db2bp 22 *LOCAL.db2inst1.020827203431 SAMPLE 1 DB2INST1 db2bp 24 *LOCAL.db2inst1.020827203934 SAMPLE 1To kill one of the connections:db2 => force application (24) DB20000I The FORCE APPLICATION command completed successfully. DB21024I This command is asynchronous and may not be effective immediately. db2 => list applications Auth Id Application Appl. Application Id DB # of Name Handle Name Agents -------- -------------- ---------- ------------------------------ -------- ----- DB2INST1 db2bp 22 *LOCAL.db2inst1.020827203431 SAMPLE 1Establishing Schemas
To create an ecasino user with an ecasino password and ecasino schema name:
- Create OS ecasino user: useradd -d /home/ecasino -m -k /etc/skel ecasino
- db2 connect to sample as db2inst1, who has SYSADM authority.
- As db2inst1, create schema ecasino authorization ecasino
- Connect as ecasino user in OS.
- db2 connect to sample
- set schema = ecasino
- You are now connected as ecasino and are working in the ecasino schema.
Using Schemas
- To execute the db2-GPMS.sql script: db2sql92 -d sample -f db2-GPMS.sql
- To simply connect to sample database and manipulate GPMS tables: db2sql92 -d sample
Commands
- db2ilist - list instances
- db2icrt & db2idrop - create and drop instance
- db2start & db2stop - start and stop instances
- get dbm cfg - get instance parameters
- get db cfg for dbname - look at configuration file parameters for database
- update dbm cfg using DIAGLEVEL 4 - e.g setting DIAGLEVEL variable in config file from 3 to 4. Must re-start instance.
- dasicrt & dasidrop - create and drop Database Administration Server (DAS)
- db2admin start & db2admin stop - start and stop DAS instances
- get admin config - look at configuration file parameters for admin server
- list applications - lists sessions connected to the database
- reorgchk - table statistics, how many rows.
- set db2instance=db2inst1 - Same as: set ORACLE_SID=dbname
- list tablespaces show detail - list tablespaces
- grant insert on table sales to user tst1 - grant privileges on sales table to tst1 user.
- grant update on table facilities to group group_name
- revoke update on table facilities from group group_name - revoke statement
- revoke all on table facilities from group group_name - revoke all the privileges granted to the group group_name.
- db2 -vf script.sql - Run DB2 script.
- db2 ? sqlxxxxx - where the xxxxx is the sql error.
Select Statements
- Grant role
- grant dbadm on database to user tellis
- sysibm.sysdummy1 is similar to Oracle's dual table
- select user, current date, current time, current schema, current server from sysibm.sysdummy1
- Select these values from the sysibm.sysdummy1 table:
- CURRENT DATE = Oracle SYSDATE
- CURRENT REFRESH AGE
- CURRENT DEFAULT TRANSFORM GROUP
- CURRENT SCHEMA
- CURRENT DEGREE
- CURRENT SERVER
- CURRENT EXPLAIN MODE
- CURRENT TIME
- CURRENT EXPLAIN SNAPSHOT
- CURRENT TIMESTAMP
- CURRENT NODE
- CURRENT TIMEZONE
- CURRENT PATH USER
- CURRENT QUERY OPTIMIZATION
- List all tables
- select tabname, tabschema from sysstat.tables
- List user privileges on tables
- select * from syscat.tabauth
- List table constraints
- select * from syscat.tabconst
- List all schemas
- select schemaname from syscat.schemata
- List all objects and their types
- select tabname, type from syscat.tables
- List all tablespaces and their owners
- select tbspace, definer from syscat.tablespaces
- List all bufferpools
- select * from syscat.bufferpools
Architecture, Definitions and Oracle Comparisons
- Architecture
- Database
- Tablespace
- Extent
- Container (O/S file)
- Data Page (Oracle block)
- DB2 vs. Oracle
- buffer pool = Oracle DB buffer cache
- log buffer = Redo log buffer
- log files = Redo log files
- data pages = Oracle blocks
- Auto-Loader = Oracle SQLLoader
- SYSADM authority = Oracle DBA role
- DB configuration file = Oracle parameter file
- describe table table_name = desc table_name
- Engine dispatchable units (EDUs) or DB2 agents = Oracle Server and User Processes
Tuning
- The configuration of one or more buffer pools is the single most important tuning area, since it is here that most of the data manipulation takes place for applications connected to the database (excluding large objects and long field data).
Import & Export
- Export
- db2 export to sample.exp of ixf select empno from employee
- Import
- db2 import from sample.exp of ixf insert into userid.staff
Backup & Recovery
Backup and Restore documentation and examples. The IBM tutorial is at: www7b.boulder.ibm.com/dmdd/library/techarticle/pworld/0112mccluney.html, which has been copied here on this wiki at DB2BackupRestoreRollforward. Enjoy. Further reading after reviewing the above link: Recoverable databases have either the logretain database configuration parameter set to "RECOVERY", the userexit database configuration parameter enabled, or both. Active logs are still available for crash recovery, but you also have the archived logs, which contain committed transaction data. Such a database can only be restored offline. It is restored to the state it was in when the backup image was taken. However, with rollforward recovery, you can roll the database forward (that is, past the time when the backup image was taken) by using the active and archived logs to either a specific point in time, or to the end of the active logs. Recoverable database backup operations can be performed either offline or online (online meaning that other applications can connect to the database during the backup operation). Database restore and rollforward operations must always be performed offline. During an online backup operation, rollforward recovery ensures that all table changes are captured and reapplied if that backup is restored. If you have a recoverable database, you can back up, restore, and roll individual table spaces forward, rather than the entire database. When you back up a table space online, it is still available for use, and simultaneous updates are recorded in the logs. When you perform an online restore or rollforward operation on a table space, the table space itself is not available for use until the operation completes, but users are not prevented from accessing tables in other table spaces. To enable logging:To see if a backup is corrupted:
- db2 update database configuration for sample using logretain on
- db2stop
- db2start
- Must then backup database before use.
Backup
- db2ckbkp SAMPLE.0.DB201.NODE0000.CATN0000.200210010138344.001
Restore
- db2 backup db sample to /export/home/db2inst1 - create backup in specified directory*
- db2 retore db sample from /export/home/db2inst1 - restore from file to db of same name.*
- db2 restore db sample into mytest - restore sample db into another db called mytest.*
To restore the database and not apply the logs use "without rolling forward" in the restore command. Logs are applied automatically.
You may restore a backup copy of a full database backup to an existing database. To restore to an existing database, you must have SYSADM, SYSCTRL, or SYSMAINT authority. The backup image may differ from the existing database in its alias name, its database name, or its database seed.
- db2 update database configuration for test using logretain on db2stop force - force in case there are disconnected applications.
- db2start
- db2 list history backup all for database test
- db2 backup database sample online to /export/home/db2inst1 - online backup. Archiving must be enabled. To enable archiving: Enable either the logretain or the userexit database configuration parameters, or both.
- Can enable incremental backups. database configuration parameter = trackmod
- Logs are found in the /db2inst1/NODE0000/SQL00001/SQLOGDIR directory. Restoring to an Existing Database.
(Offline) Full Database Recovery
Situation: Logging IS NOT enabled and a version recovery is required.
- backup db sample
- Error occurs or changes that must be reversed are made.
- restore db sample
- rollforward database
(Online) Tablespace Recovery Using Full Database Backup
Situation: Logging IS enabled and a full recovery is required. Performed an online full database backup:Deleted everything from /db2inst1/NODE0000/SQL00001/SQLT0002.0, which is the USERSPACE1 tablespace directory.
- backup db sample online
db2 => connect to sample Database Connection Information Database server = DB2/SUN 7.2.0 SQL authorization ID = DB2INST1 Local database alias = SAMPLE db2 => select * from person ID CARD_ID GIVEN_NAME -------------------- -------------------- -------------------- SQL0290N Table space access is not allowed. SQLSTATE=55039Since all of the tablespace files were deleted, no access is allowed to any object in the USERSPACE1 tablespace. I made sure the last full database online backup was the only backup file in db2inst1's home directory and executed the following to recover the database:[db2inst1@chubb ~]$ db2 restore db sample SQL2539W Warning! Restoring to an existing database that is the same as the backup image database. The database files will be deleted. Do you want to continue ? (y/n) y DB20000I The RESTORE DATABASE command completed successfully. db2 => connect to sample SQL1117N A connection to or activation of database "SAMPLE" cannot be made because of ROLL-FORWARD PENDING. SQLSTATE=57019 db2 => rollforward db sample to end of logs Rollforward Status Input database alias = sample Number of nodes have returned status = 1 Node number = 0 Rollforward status = DB working Next log file to be read = S0000005.LOG Log files processed = S0000001.LOG - S0000004.LOG Last committed transaction = 2002-08-16-18.19.32.000000 DB20000I The ROLLFORWARD command completed successfully. db2 => connect to sample SQL1117N A connection to or activation of database "SAMPLE" cannot be made because of ROLL-FORWARD PENDING. SQLSTATE=57019 db2 => rollforward db sample complete Rollforward Status Input database alias = sample Number of nodes have returned status = 1 Node number = 0 Rollforward status = not pending Next log file to be read = Log files processed = S0000001.LOG - S0000004.LOG Last committed transaction = 2002-08-16-18.19.32.000000 DB20000I The ROLLFORWARD command completed successfully. db2 => select * from person ID CARD_ID GIVEN_NAME -------------------- -------------------- -------------------- Mike W Fennel Graham W Bartlett David M Jackson Gene G Parker Dave K Cane 5 record(s) selected.(Online) Tablespace Recovery Using Tablespace Backup
Situation: Logging IS enabled and a full recovery is required. Performed an online tablespace backup of the USERSPACE1 tablespace:Deleted everything from /db2inst1/NODE0000/SQL00001/SQLT0002.0, which is the USERSPACE1 tablespace directory.
- backup db sample tablespace userspace1 online
db2 => connect to sample Database Connection Information Database server = DB2/SUN 7.2.0 SQL authorization ID = DB2INST1 Local database alias = SAMPLE db2 => select * from person ID CARD_ID GIVEN_NAME -------------------- -------------------- -------------------- SQL0290N Table space access is not allowed. SQLSTATE=55039Since all of the tablespace files were deleted, no access is allowed to any table in the USERSPACE1 tablespace. I made sure the last online tablespace backup of the USERSPACE1 tablespace was the only backup file in db2inst1's home directory and executed the following:[db2inst1@chubb ~]$ db2 restore db sample tablespace online DB20000I The RESTORE DATABASE command completed successfully. [db2inst1@chubb ~]$ db2 rollforward db sample to end of logs tablespace online Rollforward Status Input database alias = sample Number of nodes have returned status = 1 Node number = 0 Rollforward status = not pending Next log file to be read = S0000007.LOG Log files processed = - Last committed transaction = 2002-08-16-21.44.37.000000 DB20000I The ROLLFORWARD command completed successfully. db2 => select * from person ID CARD_ID GIVEN_NAME -------------------- -------------------- -------------------- Mike W Fennel Graham W Bartlett David M Jackson Gene G Parker Dave K Cane 5 record(s) selected. ----------------------------------Other Examples
LOAD...COPY TO...
Incremental Delta (differential)
Situation: Logging IS enabled and a full recovery is required. NOTE: For SMS table spaces, the granularity of this tracking is at the table space level. For DMS table spaces, the granularity is at the extent level for data and index pages, and at the table space level for other page types. To enable incremental or incremental delta online backups you must first enable modification tracking:
- update db cfg for sample using trackmod on
- db2stop force
- db2start
- db2 backup db sample - full offline database backup
- db2 backup db sample online incremental delta - delta
- db2 backup db sample online incremental delta - delta
- The following are what was produced:
- (full) SAMPLE.0.db2inst1.NODE0000.CATN0000.20020822102416.001
- (delta) SAMPLE.0.db2inst1.NODE0000.CATN0000.20020822103902.001
- (delta) SAMPLE.0.db2inst1.NODE0000.CATN0000.20020822104024.001
- Delete everything from /db2inst1/NODE0000/SQL00001/SQLT0002.0, which is the USERSPACE1 tablespace directory.
- Change to the directory where all three backup images are found.
db2 => connect to sample SQL1224N A database agent could not be started to service a request, or was terminated as a result of a database system shutdown or a force command. SQLSTATE=55032 [db2inst1@chubb ~/bkpdir]$ db2 restore db sample incremental automatic taken at 20020822104024 SQL2539W Warning! Restoring to an existing database that is the same as the backup image database. The database files will be deleted. Do you want to continue ? (y/n) y DB20000I The RESTORE DATABASE command completed successfully. [db2inst1@chubb ~/bkpdir]$ db2 rollforward db sample to end of logs Rollforward Status Input database alias = sample Number of nodes have returned status = 1 Node number = 0 Rollforward status = DB working Next log file to be read = S0000025.LOG Log files processed = S0000022.LOG - S0000024.LOG Last committed transaction = 2002-08-22-17.45.27.000000 DB20000I The ROLLFORWARD command completed successfully. [db2inst1@chubb ~/bkpdir]$ db2 rollforward db sample complete Rollforward Status Input database alias = sample Number of nodes have returned status = 1 Node number = 0 Rollforward status = not pending Next log file to be read = Log files processed = S0000022.LOG - S0000024.LOG Last committed transaction = 2002-08-22-17.45.27.000000 DB20000I The ROLLFORWARD command completed successfully. db2 => connect to sample Database Connection Information Database server = DB2/SUN 7.2.0 SQL authorization ID = DB2INST1 Local database alias = SAMPLE db2 => select * from person ID CARD_ID GIVEN_NAME -------------------- -------------------- -------------------- 1 123ds Graham 2 32d Mike 3 adsf sad 4 234 erg 5 324 324d 5 record(s) selected.May have also used:
- db2 restore db sample tablespace ('USERSPACE1') incremental automatic taken at 20020822104024
Point in Time Recovery
db2 rollforward db sample to 2002-08-18-14.21.56.245378Troubleshooting Errors
SQL1478W - Bufferpool Error
SQL1478W The database has been started but only one buffer pool has been activated. SQLSTATE=01626 The cause of this error is that there is not enough memory to allocate to this buffer.db2 => select * from syscat.bufferpools BPNAME BUFFERPOOLID NGNAME NPAGES PAGESIZE ESTORE ------------ ------------ ------ ------ -------- ------ IBMDEFAULTBP 1 - 77406 4096 NYou'll notice there is a large buffer pool called IBMDEFAULTBP that is 77,406 pages large. This is (77406 pages * 4096 bytes) = 317054976 bytes. Approximately 300 MB of memory is being requested for the buffer pool. Buffer pool sizes: (range per OS)
64-bit UNIX: 2 pages - 2,147,483,647 pages
32-bit UNIX: 2 pages - 524,288 pages
32-bit WONDOWS: 2 pages - 524,288 pages
To fix the error you need to alter the buffer pool size: alter bufferpool ibmdefaultbp size 2000 Stop and start DB2 and the error should not appear. To confirm the change query syscat.bufferpools again and you should see:BPNAME BUFFERPOOLID NGNAME NPAGES PAGESIZE ESTORE ------------ ------------ ------ ------ -------- ------ IBMDEFAULTBP 1 - 2000 4096 NAlert Files
Check the db2alert.log and db2diag.log files when sever conditions occur.DB2 Connect Installation on Windows
Install Software
- Go to: http://www-3.ibm.com/cgi-bin/db2www/data/db2/udb/winos2unix/support/download.d2w/report and select the Administration Client download for Windows. You will see a bunch of files. Copy the first one (on the left) to your PC, extract it and run setup.exe. You wil be asked to provide a username and password for the Client Administration software. After providing this the installation software creates that user and installs the client software.
- A First Steps window will appear. Select Catalog Sample Databases. This launches the Client Configuration Assistant (CCA).
- Select the Add Database... button.
- Select the Search the network radio button and click the Next push button.
- Click the [+] sign beside the Known Systems icon to list all the systems known to your client.
- Click the [+] sign beside a system to get a list of the instances and databases on it. Select the database that you want to add, click the Next push button.
- If the system that contains the database that you want to add is not listed:
- Click on the [+] sign beside the Other Systems (Search the network) icon to search the network for additional systems.
- Click on the [+] sign beside a system to get a list of the instances and databases on it.
- Select the database that you want to add and click Next.
- NOTE: If the Client Configuration Assistant is unable to detect a remote system:
- The Administration Server is not running on the remote system.
- The Discovery function times out. By default, the Discovery function will search the network for 40 seconds; this may not be long enough to detect the remote system. You can set the DB2DISCOVERYTIME registry variable to specify a longer period of time.
- The network that the Discovery request is running on is configured so that the Discovery request does not reach the remote system desired.
- You are using NetBIOS? as the Discovery protocol. You may need to set the DB2NBDISCOVERRCVBUFS registry variable to a larger value to enable the client to receive more concurrent Discovery replies.
- If the system that you want to add is still not listed, it can be added to the list of systems by performing the following steps:
- Click Add System. The Add System window opens.
- Enter the required communication protocol parameters for the remote Administration Server and click OK. A new system is added.
- Select the database that you want to add and click Next.
- Select Finish
- Select Test Connection
| Edit -:- Attach -:- Ref-By -:- Printable -:- More |