D_backup and restore(物理与逻辑备份)与重建

来源:互联网 发布:手机恶意软件排行 编辑:程序博客网 时间:2024/04/30 13:14
测试数据库的实例为SAMPLE,在db2inst用户下,未开启归档模式。
一、物理备份:首先使用离线备份方式测试
离线备份要保证没有APP连接在数据库上,并将数据库置于非活动状态后备份:
db2inst@linux11:~$ db2 list applications  

Auth Id Application Appl. Application Id DB # of
         Name Handle Name Agents
-----------------------------------------------------------------------------------------------------------
DB2INST db2bp 885 *LOCAL.db2inst.120214151237 SAMPLE 1    

db2inst@linux11:~$ db2 connect reset
DB20000I The SQL command completed successfully.
db2inst@linux11:~$ db2 list applications 
SQL1611W No data was returned by Database System Monitor.
db2inst@linux11:~$ db2 force applications all
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.
db2inst@linux11:~$ db2 deactivate db sample
SQL1496W Deactivate database is successful, but the database was not activated.
db2inst@linux11:~$ mkdir /tmp/db_backup_sample_20120214
db2inst@linux11:~$ db2 backup db sample to /tmp/db_backup_sample_20120214

Backup successful. The timestamp for this backup image is: 20120214231707
 
查看备份集信息:
db2inst@linux11:~$ cd /tmp/db_backup_sample_20120214 
db2inst@linux11:/tmp/db_backup_sample_20120214$ ls -al

total 297224
drwxr-xr-x 2 db2inst db2iadm 4096 2012-02-1423:17 .
drwxrwxrwt 7 root root 4096 2012-02-1423:17 ..
-rw-------1 db2inst db2iadm 304345088 2012-02-1423:17 SAMPLE.0.db2inst.NODE0000.CATN0000.20120214231707.001
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 list backup since 20120214 for sample  

                    List History File for sample

Number of matching file entries = 4


 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
 -- ------------------------- --- --------------------------------------
  B D 20120214231641000 F S0000000.LOG               
 ----------------------------------------------------------------------------
  Contains 6 tablespace(s):

  00001 SYSCATSPACE                                                           
  00002 USERSPACE1                                                            
  00003 IBMDB2SAMPLEREL                                                       
  00004 IBMDB2SAMPLEXML                                                       
  00005 SYSTOOLSPACE                                                          
  00006 TEMPSPACE2                                                            
 ----------------------------------------------------------------------------
    Comment: DB2 BACKUP SAMPLE OFFLINE                                        
 Start Time: 20120214231641
   End Time: 20120214231642
     Status: A
 ----------------------------------------------------------------------------
  EID: 14 Location: 

SQLCA Information

 sqlcaid : SQLCA sqlcabc:136 sqlcode:-2036 sqlerrml:30

 sqlerrmc: /tmp/db_backup_sample_20120214
 sqlerrp : sqlubMWR
 sqlerrd : (1)0 (2) 0 (3) 0
           (4) 0 (5)0 (6) 0
 sqlwarn : (1) (2) (3) (4) (5) (6)
           (7) (8) (9) (10) (11)
 sqlstate:

 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
 -- ------------------------- --- --------------------------------------
  B D 20120214231657000 F S0000000.LOG               
 ----------------------------------------------------------------------------
  Contains 6 tablespace(s):

  00001 SYSCATSPACE                                                           
  00002 USERSPACE1                                                            
  00003 IBMDB2SAMPLEREL                                                       
  00004 IBMDB2SAMPLEXML                                                       
  00005 SYSTOOLSPACE                                                          
  00006 TEMPSPACE2                                                            
 ----------------------------------------------------------------------------
    Comment: DB2 BACKUP SAMPLE OFFLINE                                        
 Start Time: 20120214231657
   End Time: 20120214231658
     Status: A
 ----------------------------------------------------------------------------
  EID: 15 Location: 

SQLCA Information

 sqlcaid : SQLCA sqlcabc:136 sqlcode:-2036 sqlerrml:30

 sqlerrmc: /tmp/db_backup_sample_20120214
 sqlerrp : sqlubMWR
 sqlerrd : (1)0 (2) 0 (3) 0
           (4) 0 (5)0 (6) 0
 sqlwarn : (1) (2) (3) (4) (5) (6)
           (7) (8) (9) (10) (11)
 sqlstate:

 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
 -- ------------------------- --- --------------------------------------
  B D 20120214231707001 F D S0000000.LOG S0000000.LOG  
 ----------------------------------------------------------------------------
  Contains 6 tablespace(s):

  00001 SYSCATSPACE                                                           
  00002 USERSPACE1                                                            
  00003 IBMDB2SAMPLEREL                                                       
  00004 IBMDB2SAMPLEXML                                                       
  00005 SYSTOOLSPACE                                                          
  00006 TEMPSPACE2                                                            
 ----------------------------------------------------------------------------
    Comment: DB2 BACKUP SAMPLE OFFLINE                                        
 Start Time: 20120214231707
   End Time: 20120214231718
     Status: A
 ----------------------------------------------------------------------------
  EID: 16 Location:/tmp/db_backup_sample_20120214


 Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID
 -- ------------------------- --- --------------------------------------
  R D 20120214232518001 F S0000000.LOG S0000000.LOG20120214231707 
 ----------------------------------------------------------------------------
  Contains 6 tablespace(s):

  00001 SYSCATSPACE                                                           
  00002 USERSPACE1                                                            
  00003 IBMDB2SAMPLEREL                                                       
  00004 IBMDB2SAMPLEXML                                                       
  00005 SYSTOOLSPACE                                                          
  00006 TEMPSPACE2                                                            
 ----------------------------------------------------------------------------
    Comment: RESTORE SAMPLE NO RF                                             
 Start Time: 20120214232518
   End Time: 20120214232609
     Status: A
 ----------------------------------------------------------------------------
  EID: 17 Location:
 
然后删除一个系统表数据(systools.HMON_ATM_INFO):
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 "select count(*) from systools.hmon_atm_info" 

1          
-----------
        213

  1 record(s) selected.

db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 "drop table systools.hmon_atm_info"
DB20000I The SQL command completed successfully.
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 "select count(*) from systools.hmon_atm_info"
SQL0204N "SYSTOOLS.HMON_ATM_INFO" is an undefined name. SQLSTATE=42704
 
开始进行备份恢复:
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 connect reset
DB20000I The SQL command completed successfully.
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 force applications all
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.

db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 deactivate db sample
SQL1496W Deactivate database is successful, but the database was not 
activated.
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 restore db sample from /tmp/db_backup_sample_20120214 taken at 20120214231707
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.
db2inst@linux11:/tmp/db_backup_sample_20120214$date
Tue Feb 14 23:26:13 CST2012
 
查看数据表是否已经恢复:
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 connect to sample 

   Database Connection Information

 Database server = DB2/LINUX9.7.1
 SQL authorization ID = DB2INST
 Local database alias = SAMPLE

db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 "select count(*) from systools.hmon_atm_info"

1          
-----------
        213

  1 record(s) selected.
 
注意查看备份集的信息,此备份不支持ROLLFORWARD:
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 rollforward db sample to 2012-02-14-23.18.01.000000 using local time and stop 
SQL1260N Database "sample" is not configured for roll-forward recovery on node(s)"0".
 
二、物理备份:在线方式备份
在线备份同离线备份基本相同,备份命令backup db sample online to ......即可。
三、物理备份:恢复重定向
在一个物理备份做恢复时,遇到需要修改数据文件存储路径等数据库结构定义信息时,需要用到REDIRECT方法。
REDIRECT重定向是指在RESTORE时,使用自动生成的脚本来修改相关结构变化的信息并恢复数据库。
 
脚本的生成方法是通过RESOTRE ..... REDIRECT .....命令来生成脚本后再相应修改:
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2 restore db sample from /tmp/db_backup_sample_20120214 taken at 20120214231707 redirect generate script redirect_db.sql
DB20000I The RESTORE DATABASE command completed successfully.
 
这个脚本主要由几个部分组成:
  1. RESTORE DATABASE... REDIRECT 命令
  2. SET TABLESPACE CONTAINERS FOR ... USING命令
  3. RESTORE DATABASE ... CONTINUE命令
注意,其中<>内的内容需要修改或补充。
db2inst@linux11:/tmp/db_backup_sample_20120214$ cat redir*.sql 
-- *****************************************************************************
-- ** automatically created redirect restore script
-- *****************************************************************************
UPDATE COMMAND OPTIONS USING SON Z ON SAMPLE_NODE0000.out VON;
SET CLIENT ATTACH_DBPARTITIONNUM0;
SET CLIENT CONNECT_DBPARTITIONNUM0;
-- *****************************************************************************
-- ** automatically created redirect restore script
-- *****************************************************************************
RESTORE DATABASE SAMPLE
-- USER <username>
-- USING '<password>'
FROM '/tmp/db_backup_sample_20120214'
TAKEN AT 20120214231707
--ON '/home/db2inst'
-- DBPATHON '<target-directory>'

INTO SAMPLE
-- NEWLOGPATH'/home/db2inst/db2inst/NODE0000/SQL00001/SQLOGDIR/'
-- WITH <num-buff> BUFFERS
-- BUFFER <buffer-size>
-- REPLACE HISTORY FILE
-- REPLACE EXISTING
REDIRECT
-- PARALLELISM<n>
WITHOUT ROLLING FORWARD
-- WITHOUT PROMPTING
;
-- *****************************************************************************
-- ** tablespace definition
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = SYSCATSPACE
-- ** Tablespace ID = 0
-- ** Tablespace Type = Database managed space                      
-- ** Tablespace Content Type = All permanent data. Regulartable space.    
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage= Yes     
-- ** Auto-resize enabled= Yes     
-- ** Total numberof pages = 20480
-- ** Numberof usable pages = 20476
-- ** High water mark (pages) = 19084
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = TEMPSPACE1
-- ** Tablespace ID = 1
-- ** Tablespace Type = System managed space                        
-- ** Tablespace Content Type = System Temporarydata                       
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage= Yes     
-- ** Total numberof pages = 1
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = USERSPACE1
-- ** Tablespace ID = 2
-- ** Tablespace Type = Database managed space                      
-- ** Tablespace Content Type = All permanent data.Large table space.      
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage= Yes     
-- ** Auto-resize enabled= Yes     
-- ** Total numberof pages = 4096
-- ** Numberof usable pages = 4064
-- ** High water mark (pages) = 1888
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = IBMDB2SAMPLEREL
-- ** Tablespace ID = 3
-- ** Tablespace Type = Database managed space                      
-- ** Tablespace Content Type = All permanent data.Large table space.      
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage= Yes     
-- ** Auto-resize enabled= Yes     
-- ** Total numberof pages = 12288
-- ** Numberof usable pages = 12256
-- ** High water mark (pages) = 12192
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = IBMDB2SAMPLEXML
-- ** Tablespace ID = 4
-- ** Tablespace Type = Database managed space                      
-- ** Tablespace Content Type = All permanent data.Large table space.      
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage= Yes     
-- ** Auto-resize enabled= Yes     
-- ** Total numberof pages = 4096
-- ** Numberof usable pages = 4064
-- ** High water mark (pages) = 1440
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = SYSTOOLSPACE
-- ** Tablespace ID = 5
-- ** Tablespace Type = Database managed space                      
-- ** Tablespace Content Type = All permanent data.Large table space.      
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage= Yes     
-- ** Auto-resize enabled= Yes     
-- ** Total numberof pages = 4096
-- ** Numberof usable pages = 4092
-- ** High water mark (pages) = 116
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = SYSTOOLSTMPSPACE
-- ** Tablespace ID = 6
-- ** Tablespace Type = System managed space                        
-- ** Tablespace Content Type = User Temporarydata                         
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 4
-- ** Using automatic storage= Yes     
-- ** Total numberof pages = 1
-- *****************************************************************************
-- *****************************************************************************
-- ** Tablespace name = TEMPSPACE2
-- ** Tablespace ID = 7
-- ** Tablespace Type = System managed space                        
-- ** Tablespace Content Type = All permanent data. Regulartable space.    
-- ** Tablespace Page size (bytes) = 8192
-- ** Tablespace Extent size (pages) = 32
-- ** Using automatic storage= No      
-- ** Total numberof pages = 1
-- *****************************************************************************
SET TABLESPACE CONTAINERSFOR 7
-- IGNORE ROLLFORWARD CONTAINER OPERATIONS
USING (
  PATH '/home/db2inst/TEMPSPACE2'
);

-- *****************************************************************************
-- ** start redirected restore
-- *****************************************************************************
RESTORE DATABASE SAMPLECONTINUE;
-- *****************************************************************************
-- ** endof file
-- *****************************************************************************
 
恢复期间可以使用db2 list utilities show detail来查看备份进度(COMPLETED WORK不断增大到备份集大小后完成恢复):
 
db2inst@linux11:~$ db2 list utilities show detail 

ID = 12
Type = RESTORE
Database Name = SAMPLE
Partition Number = 0
Description = db 
Start Time = 02/15/2012 00:39:32.536641
State = Executing
Invocation Type = User
Progress Monitoring:
      Completed Work = 73461760 bytes
      Start Time = 02/15/2012 00:39:32.536648
 
如果在恢复数据后需要数据表暂挂状态(查询报错:SQL0668N Operation not allowed for reason code "1" on table *****.SQLSTATE=57016),那么需要解除表暂挂:
db2 set integrity for dept immediate checked

OK,如果要查那些表有问题(status<>'N'),那么通过:
Select tabname from syscat.tables where status='C'
四、逻辑备份:通过db2move 与db2look完成
db2look命令的-e选项生成大部分对象的DDL语句,-td选项指定SQL语句之间的分隔符号(默认为;),-ct指DDL语句按照对象创建时间的先后顺序进行生成,-o选项指定生成SQL文件名。
如下:
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2look -d sample -e -td @ -ct -o sample_table.sql 
-- No userid was specified, db2look tries to use Environment variable USER
-- USER is: DB2INST
-- Creating DDL for table(s)
-- Output is sent to file: sample_table.sql
 
然后备份一下BUFFERPOOL,TBS等数据库结构信息定义:
db2inst@linux11:/tmp/db_backup_sample_20120214$ db2look -d sample -l -o sample_db_tbs.sql 
-- No userid was specified, db2look tries to use Environment variable USER
-- USER is: DB2INST
-- Output is sent to file: sample_db_tbs.sql
db2inst@linux11:/tmp/db_backup_sample_20120214$ cat sample_db_tbs.sql
-- This CLP file was created using DB2LOOK Version"9.7" 
-- Timestamp: Wed15 Feb 201212:11:14 AM CST
-- Database Name: SAMPLE         
-- Database Manager Version: DB2/LINUX Version9.7.1       
-- Database Codepage:1208
-- Database Collating Sequence is: IDENTITY

CONNECT TO SAMPLE;
------------------------------------
-- DDL Statements for BUFFERPOOLS --
------------------------------------
CREATE BUFFERPOOL "BP2" SIZE 1000 PAGESIZE 8192 NUMBLOCKPAGES 900 BLOCKSIZE 32;
CONNECT RESET;
CONNECT TO SAMPLE;
------------------------------------
-- DDL Statements for TABLESPACES --
------------------------------------
CREATE LARGE TABLESPACE "IBMDB2SAMPLEREL" IN DATABASE PARTITION GROUP IBMDEFAULTGROUP 
         PAGESIZE 8192 MANAGED BY AUTOMATIC STORAGE 
         AUTORESIZE YES 
         INITIALSIZE 32
         MAXSIZE NONE 
         EXTENTSIZE 32
         PREFETCHSIZE AUTOMATIC
         BUFFERPOOL IBMDEFAULTBP
         OVERHEAD 7.500000
         TRANSFERRATE 0.060000 
         NO FILE SYSTEM CACHING  
         DROPPED TABLE RECOVERY ON;

CREATE LARGE TABLESPACE "IBMDB2SAMPLEXML" IN DATABASE PARTITION GROUP IBMDEFAULTGROUP 
         PAGESIZE 8192 MANAGED BY AUTOMATIC STORAGE 
         AUTORESIZE YES 
         INITIALSIZE 32
         MAXSIZE NONE 
         EXTENTSIZE 32
         PREFETCHSIZE AUTOMATIC
         BUFFERPOOL IBMDEFAULTBP
         OVERHEAD 7.500000
         TRANSFERRATE 0.060000 
         NO FILE SYSTEM CACHING  
         DROPPED TABLE RECOVERY ON;

CREATE LARGE TABLESPACE "SYSTOOLSPACE" IN DATABASE PARTITION GROUP IBMCATGROUP 
         PAGESIZE 8192 MANAGED BY AUTOMATIC STORAGE 
         AUTORESIZE YES 
         INITIALSIZE 32
         MAXSIZE NONE 
         EXTENTSIZE 4
         PREFETCHSIZE AUTOMATIC
         BUFFERPOOL IBMDEFAULTBP
         OVERHEAD 7.500000
         TRANSFERRATE 0.060000 
         NO FILE SYSTEM CACHING  
         DROPPED TABLE RECOVERY ON;

CREATE USER TEMPORARY TABLESPACE "SYSTOOLSTMPSPACE" IN DATABASE PARTITION GROUP IBMCATGROUP 
         PAGESIZE 8192 MANAGED BY AUTOMATIC STORAGE 
         EXTENTSIZE 4
         PREFETCHSIZE AUTOMATIC
         BUFFERPOOL IBMDEFAULTBP
         OVERHEAD 7.500000
         TRANSFERRATE 0.060000 
         FILE SYSTEM CACHING  
         DROPPED TABLE RECOVERY OFF;

CREATE REGULAR TABLESPACE "TEMPSPACE2" IN DATABASE PARTITION GROUP IBMDEFAULTGROUP PAGESIZE8192 MANAGED BY SYSTEM 
         USING ('/home/db2inst/TEMPSPACE2')
         EXTENTSIZE 32
         PREFETCHSIZE AUTOMATIC
         BUFFERPOOL IBMDEFAULTBP
         OVERHEAD 7.500000
         TRANSFERRATE 0.060000 
         NO FILE SYSTEM CACHING  
         DROPPED TABLE RECOVERY ON;

-- Mimic tablespace
ALTER TABLESPACE SYSCATSPACE
      PREFETCHSIZE AUTOMATIC
      OVERHEAD 7.500000
      NO FILE SYSTEM CACHING 
      AUTORESIZE YES 
      TRANSFERRATE 0.060000;

ALTER TABLESPACE TEMPSPACE1
      PREFETCHSIZE AUTOMATIC
      OVERHEAD 7.500000
      FILE SYSTEM CACHING 
      TRANSFERRATE 0.060000;

ALTER TABLESPACE USERSPACE1
      PREFETCHSIZE AUTOMATIC
      OVERHEAD 7.500000
      NO FILE SYSTEM CACHING 
      AUTORESIZE YES 
      TRANSFERRATE 0.060000;

COMMIT WORK;
CONNECT RESET;
TERMINATE;
 
db2move用来导出数据,如下:
db2inst@linux11:~/db2move_files$ db2move sample export -u db2inst -p db2inst  
***** DB2MOVE*****
Action: EXPORT
Start time: Wed Feb 15 01:11:532012

Connecting to database SAMPLE ... successful! Server: DB2 Common Server V9.7.1

EXPORT: 18 rows from table"DB2INST "."ACT"
... ...
EXPORT: 151 rows from table"DB2INST "."X_JNRWJG_CODE_INF"
EXPORT: 95 rows from table"DB2INST "."X_RSP_CODE_INF"

Disconnecting from database ... successful!

End time: Wed Feb 15 01:12:142012
db2inst@linux11:~/db2move_files$ ls
db2move.lst tab16.ixf tab21.msg tab28.ixf tab33.msg tab3.msg tab45.msg tab51.msg tab58.msg tab63.msg tab6.ixf tab75.msg
... ...
tab15.msg tab21.ixf tab28a.001.lob tab33.ixf tab3.ixf tab45.ixf tab51.ixf tab58.ixf tab63.ixf tab69.msg tab75.ixf
 
五、重建数据库实例与库环境
首先需要明确的一点是,测试是完成:在同一台机器上创建一个用户并在此用户下重建实例与数据库。
另外,查看当前数据库环境的方法如下:
  1. 数据库程序安装目录:一般默认在/opt/ibm下安装,另外也可以在现有环境下which db2来看看调用路径(当然你打db2level或者db2ls,我都不反对)
  2. 数据库实例安装目录:系统在当前运行db2icrt指定的用户$HOME/sqllib目录下创建
  3. 数据库创建目录:默认在dbm参数DFTDBPATH指定路径下,可以通过db2 list db directory来查看
$ db2level 
DB21085I Instance "dbonl" uses "32" bits and DB2 code release "SQL09071" 
with level identifier "08020107".
Informational tokens are "DB2 v9.7.0.1", "s091114", "IP23033", and Fix Pack 
"1".
Product is installed at "/opt/ibm/db2/V9.7".

$ db2ls

Install Path Level Fix Pack Special Install Number Install Date Installer UID 
---------------------------------------------------------------------------------------------------------------------
/opt/ibm/db2/V9.79.7.0.11 Wed Dec 2917:03:242010 CST 0 
$ db2licm -l
Product name: "DB2 Express-C"
License type: "Unwarranted"
Expiry date:"Permanent"
Product identifier: "db2expc"
Version information: "9.7"
Max number of CPUs: "2"
Max amount of memory (GB): "2"
 
5.1 安装DB2 9.7数据库程序
因本机已经安装过,因此无需安装。安装过程相当简单,解压对应安装tar文件后,运行precheck程序检查后即可通过db2_install程序安装,指定目录和数据库类型(ESE等)。
5.2 创建数据库实例
首先需要创建对应DB2用户,这里创建dbonl用户,并用root运行db2icrt -n dbonl dbonl。
此时在$HOME下创建一个sqllib目录作为实例所在信息目录。
安装后的目录:
$ ls sqllib 
adm bin conv db2cshrc db2systm function include lib misc profile.env samples sqldbdir uif
adsm bnd ctrl db2dump db2tss gskit infopop lib32 msg Readme security tmp usercshrc
backup cfg dasfcn db2profile doc hmonCache java log php32 ruby32 security32 tools userprofile
$ pwd
/home/dbonl
 
HA环境如果实例创建在了共享盘上,$HOME/sqllib/db2nodes.cfg文件需要进行处理,因实例启动时需要读取此文件,含主机名称信息。HA脚本需要将此文件修改为对应正确主机名的文件。
5.3 创建数据库
通过create database命令来创建数据库。su - dbonl用户后,在db2内创建指定样式的数据库如下:
 
db2 => create database DBONL automatic storage no on '/dbonl' alias DBONL \ 
db2 (cont.) => using codeset UTF-8 territory us pagesize 8192 \
db2 (cont.) => CATALOG TABLESPACE MANAGED BY DATABASE USING ( FILE '/dbonl/db2catalog01.dbf' 25600 ) \
db2 (cont.) => USER TABLESPACE MANAGED BY DATABASE USING ( FILE '/dbonl/db2user01.dbf' 25600 ) \
db2 (cont.) => TEMPORARY TABLESPACE MANAGED BY DATABASE USING ( FILE '/dbonl/db2temp01.dbf' 5120 ) \
db2 (cont.) => WITH 'DBONL'


SQL0289N Unable to allocate new pages in table space"SYSCATSPACE". LINE 
NUMBER=1. SQLSTATE=57011
 
此问题是由于/dbonl/db2catalog01.dbf文件没有设置正确的大小(增加当前配置)。
重新创建:
 
db2 => create database DBONL automatic storage no on '/dbonl' alias DBONL \ 
using codeset UTF-8 territory us pagesize 8192 \
CATALOG TABLESPACE MANAGED BY DATABASE USING ( FILE '/dbonl/db2catalog01.dbf' 38400 ) \
USER TABLESPACE MANAGED BY DATABASE USING ( FILE '/dbonl/db2user01.dbf' 25600 ) \
TEMPORARY TABLESPACE MANAGED BY DATABASE USING ( FILE '/dbonl/db2temp01.dbf' 5120 ) \
WITH 'DBONL'

DB20000I The CREATE DATABASE command completed successfully.

 
 
 
转自:http://www.db2china.net/home/space.php?uid=3431&do=blog&id=26317