DB2 9.5.0.0升级至9.5.0.9(小版本升级)

0.升级前DB2版本

[db2inst1@xifenfei ~]$ db2level
DB21085I  Instance "db2inst1" uses "32" bits and DB2 code release "SQL09050" 
with level identifier "03010107".
Informational tokens are "DB2 v9.5.0.0", "s071001", "LINUXIA3295", and Fix Pack 
"0".
Product is installed at "/opt/db2/V9.5".

1.查看哪些实例

[root@xifenfei ~]# su - db2inst1
[db2inst1@xifenfei ~]$ db2ilist
db2inst1
db2inst2

2.关闭数据库

[db2inst1@xifenfei ~]$ db2 force applications all
SQL1032N  No start database manager command was issued.  SQLSTATE=57019
[db2inst1@xifenfei ~]$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
[db2inst1@xifenfei ~]$ db2stop
04/05/2012 09:17:13     0   0   SQL1032N  No start database manager command was issued.
SQL1064N  DB2STOP processing was successful.
[db2inst1@xifenfei ~]$ su - db2inst2
Password: 
[db2inst2@xifenfei ~]$ db2 force applications all
DB20000I  The FORCE APPLICATION command completed successfully.
DB21024I  This command is asynchronous and may not be effective immediately.
[db2inst2@xifenfei ~]$ db2 terminate
DB20000I  The TERMINATE command completed successfully.
[db2inst2@xifenfei ~]$ db2stop
04/05/2012 09:20:00     0   0   SQL1064N  DB2STOP processing was successful.
SQL1064N  DB2STOP processing was successful.

3.关闭管理服务器(DAS)

[root@xifenfei ~]# su - dasusr1
[dasusr1@xifenfei ~]$ db2admin stop
SQL4407W  The DB2 Administration Server was stopped successfully.

4.卸装未使用的共享库

[db2inst1@xifenfei ~]$  $HOME/sqllib/bin/ipclean
/home/db2inst1/sqllib/bin/ipclean: Removing DB2 engine and client's IPC resources for db2inst1.
[db2inst2@xifenfei ~]$  $HOME/sqllib/bin/ipclean
/home/db2inst2/sqllib/bin/ipclean: Removing DB2 engine and client's IPC resources for db2inst2.

5.升级数据库软件和组件

[root@xifenfei ~]# cd server/
[root@xifenfei server]# ./installFixPack -b /opt/db2/V9.5/
DBI1017I  installFixPack is updating the DB2 product(s) installed in
      location /opt/db2/V9.5/.


DB2 installation is being initialized.

 Total number of tasks to be performed: 36 
Total estimated time for all tasks to be performed: 1165 

Task #1 start
Description: Stopping DB2 Fault Monitor 
Estimated time 10 second(s) 
Task #1 end 

Task #2 start
Description: Preparing the system 
Estimated time 120 second(s) 
A major error occurred during the execution that caused this program to
terminate prematurely. If the problem persists, contact your technical service
representative.

For more information see the DB2 installation log at
"/tmp/installFixPack.log.9890".

--发生错误,通过日志文件寻找错误
[root@xifenfei server]# more /tmp/installFixPack.log.9890
Stopping DB2 Fault Monitor :.......Success 
ERROR: The installFixPack command detected some DB2 libraries are still loaded
in memory and some applications might still be running in the current
installation copy.  All applications must be stopped. See the fix pack readme
for pre-installation instructions, and re-run the installFixPack command.
Alternatively, to override automatic checking, you can re-issue the
installFixPack command with the '-f db2lib' parameter. Note: If you re-issue
the installFixPack command with the '-f db2lib' parameter, after the DB2
instances are updated, some applications might not work properly and might need
to be restarted to function properly against the updated DB2 instance.

Preparing the system :.......Failure 
--发现是some DB2 libraries are still loaded,导致升级不能进行

--使用-f db2lib参数
[root@xifenfei server]# ./installFixPack -b /opt/db2/V9.5/ -f db2lib
DBI1017I  installFixPack is updating the DB2 product(s) installed in
      location /opt/db2/V9.5/.


DB2 installation is being initialized.

 Total number of tasks to be performed: 36 
Total estimated time for all tasks to be performed: 1165 

Task #1 start
Description: Stopping DB2 Fault Monitor 
Estimated time 10 second(s) 
Task #1 end 

Task #2 start
Description: Preparing the system 
Estimated time 120 second(s) 
Task #2 end 

Task #3 start
Description: Base Client Support for installation with root privileges 
Estimated time 3 second(s) 
Task #3 end 

Task #4 start
Description: Product Messages - English 
Estimated time 11 second(s) 
Task #4 end 

Task #5 start
Description: Base client support 
Estimated time 86 second(s) 
Task #5 end 

Task #6 start
Description: The DB2 required component. 
Estimated time 78 second(s) 
Task #6 end 

Task #7 start
Description: Java Help (HTML) - English 
Estimated time 7 second(s) 
Task #7 end 

Task #8 start
Description: Base server support for installation with root privileges 
Estimated time 7 second(s) 
Task #8 end 

Task #9 start
Description: Global Secure ToolKit 
Estimated time 14 second(s) 
Task #9 end 

Task #10 start
Description: Java support 
Estimated time 11 second(s) 
Task #10 end 

Task #11 start
Description: SQL procedures 
Estimated time 3 second(s) 
Task #11 end 

Task #12 start
Description: ICU Utilities 
Estimated time 54 second(s) 
Task #12 end 

Task #13 start
Description: Java Common files 
Estimated time 20 second(s) 
Task #13 end 

Task #14 start
Description: Base server support 
Estimated time 197 second(s) 
Task #14 end 

Task #15 start
Description: IBM Software Development Kit (SDK) for Java(TM) 
Estimated time 32 second(s) 
Task #15 end 

Task #16 start
Description: Control Center Help (HTML) - English 
Estimated time 13 second(s) 
Task #16 end 

Task #17 start
Description: Connect support 
Estimated time 3 second(s) 
Task #17 end 

Task #18 start
Description: Communication support - TCP/IP 
Estimated time 3 second(s) 
Task #18 end 

Task #19 start
Description: Parallel Extension 
Estimated time 3 second(s) 
Task #19 end 

Task #20 start
Description: Replication tools 
Estimated time 16 second(s) 
Task #20 end 

Task #21 start
Description: Control Center 
Estimated time 40 second(s) 
Task #21 end 

Task #22 start
Description: DB2 data source support 
Estimated time 4 second(s) 
Task #22 end 

Task #23 start
Description: DB2 LDAP support 
Estimated time 3 second(s) 
Task #23 end 

Task #24 start
Description: DB2 Instance Setup wizard 
Estimated time 4 second(s) 
Task #24 end 

Task #25 start
Description: First Steps 
Estimated time 3 second(s) 
Task #25 end 

Task #26 start
Description: Product Signature for DB2 Enterprise Server Edition 
Estimated time 5 second(s) 
Task #26 end 

Task #27 start
Description: Sample database source 
Estimated time 4 second(s) 
Task #27 end 

Task #28 start
Description: Installing or updating SA MP Base Component 
Estimated time 40 second(s) 
Task #28 end 

Task #29 start
Description: Installing or updating DB2 HA scripts for SA MP Base Component 
Estimated time 40 second(s) 
Task #29 end 

Task #30 start
Description: Setting DB2 library path 
Estimated time 180 second(s) 
Task #30 end 

Task #31 start
Description: Executing control tasks 
Estimated time 20 second(s) 
Task #31 end 

Task #32 start
Description: Updating global registry 
Estimated time 20 second(s) 
Task #32 end 

Task #33 start
Description: Starting DB2 Fault Monitor 
Estimated time 10 second(s) 
Task #33 end 

Task #34 start
Description: Updating the db2ls link 
Estimated time 1 second(s) 
Task #34 end 

Task #35 start
Description: Updating the DB2 Administration Server 
Estimated time 40 second(s) 
Task #35 end 

Task #36 start
Description: Updating existing DB2 instances 
Estimated time 60 second(s) 
Task #36 end 

A minor error occurred during the execution.

For more information see the DB2 installation log at
"/tmp/installFixPack.log.15581".
--提示升级有错误发生

--检查日志文件
[root@xifenfei server]# more /tmp/installFixPack.log.15581
TSAMP_VERSION=3.2.1.2
 DBI1130E  The SA MP Base Component could not be installed or updated
      because system prerequisites were not met. See the log file
      /tmp/prereqSAM.log.17293 for details.
--发现是samp组件没有安装导致该错误,忽略

6.升级数据库

[root@xifenfei server]# su - db2inst1
[db2inst1@xifenfei ~]$ db2level  -a
DB21085I  Instance "db2inst1" uses "32" bits and DB2 code release "SQL09059" 
with level identifier "060A0107".
Informational tokens are "DB2 v9.5.0.9", "s120228", "IP23310", and Fix Pack 
"9".
Product is installed at "/opt/db2/V9.5".
[db2inst1@xifenfei ~]$ db2ilist 
db2inst1
db2inst2
[db2inst1@xifenfei ~]$ db2start
04/05/2012 09:39:45     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@xifenfei ~]$ db2 list database DIRECTORY

 System Database Directory

 Number of entries in the directory = 3

Database 1 entry:

 Database alias                       = XFF
 Database name                        = XIFENFEI
 Local database directory             = /home/db2inst1
 Database release level               = c.00
 Comment                              = XIFENFEI TEST DATABASE
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

Database 2 entry:

 Database alias                       = TOOLSDB
 Database name                        = TOOLSDB
 Local database directory             = /home/db2inst1
 Database release level               = c.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

Database 3 entry:

 Database alias                       = SAMPLE
 Database name                        = SAMPLE
 Local database directory             = /home/db2inst1
 Database release level               = c.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

[db2inst1@xifenfei ~]$ db2updv95 -d toolsdb


_________________________________________________________________________     
                                                                              
                    _____   DB2 Service Tools   _____                         
                                                                              
                            I      B      M                                   
                                                                              
                               db2updv95                                      
                                                                              
   This tool is a service utility designed to update a DB2 Version 9.5        
   database to the current fixpak level.                                      
                                                                              
_________________________________________________________________________     


DB2 Universal Database Version 9.5, 5622-044 (c) Copyright IBM Corp. 2007
Licensed Material - Program Property of IBM
IBM DATABASE 2 Database update to current fix pack tool

db2updv95 completed successfully for database 'toolsdb'. 
[db2inst1@xifenfei ~]$ db2updv95 -d SAMPLE


_________________________________________________________________________     
                                                                              
                    _____   DB2 Service Tools   _____                         
                                                                              
                            I      B      M                                   
                                                                              
                               db2updv95                                      
                                                                              
   This tool is a service utility designed to update a DB2 Version 9.5        
   database to the current fixpak level.                                      
                                                                              
_________________________________________________________________________     


DB2 Universal Database Version 9.5, 5622-044 (c) Copyright IBM Corp. 2007
Licensed Material - Program Property of IBM
IBM DATABASE 2 Database update to current fix pack tool

db2updv95 completed successfully for database 'SAMPLE'.

--指定数据库别名 
[db2inst1@xifenfei ~]$ db2updv95 -d Xff


_________________________________________________________________________     
                                                                              
                    _____   DB2 Service Tools   _____                         
                                                                              
                            I      B      M                                   
                                                                              
                               db2updv95                                      
                                                                              
   This tool is a service utility designed to update a DB2 Version 9.5        
   database to the current fixpak level.                                      
                                                                              
_________________________________________________________________________     


DB2 Universal Database Version 9.5, 5622-044 (c) Copyright IBM Corp. 2007
Licensed Material - Program Property of IBM
IBM DATABASE 2 Database update to current fix pack tool

db2updv95 completed successfully for database 'Xff'. 

[db2inst1@xifenfei ~]$ su - db2inst2
Password: 
[db2inst2@xifenfei ~]$ db2 list database DIRECTORY

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = XIFENFEI
 Database name                        = XIFENFEI
 Local database directory             = /home/db2inst2/xifenfei
 Database release level               = c.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

[db2inst2@xifenfei ~]$ db2start
04/05/2012 09:46:47     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst2@xifenfei ~]$ db2updv95 -d  xifenfei


_________________________________________________________________________     
                                                                              
                    _____   DB2 Service Tools   _____                         
                                                                              
                            I      B      M                                   
                                                                              
                               db2updv95                                      
                                                                              
   This tool is a service utility designed to update a DB2 Version 9.5        
   database to the current fixpak level.                                      
                                                                              
_________________________________________________________________________     


DB2 Universal Database Version 9.5, 5622-044 (c) Copyright IBM Corp. 2007
Licensed Material - Program Property of IBM
IBM DATABASE 2 Database update to current fix pack tool

db2updv95 completed successfully for database 'xifenfei'. 

7.补充说明
1)在升级数据库前需要做好数据库和软件备份
2)升级过程时先关闭所有db2相关进程,如果不能正常关闭(非本文上面列举操作相关进程),直接kill
3)升级过程中,如果实例,DAS等升级失败,需要后续手工升级
4)检查相关进程,如果没有正常启动,需要手工给予启动
5)一些工具进行绑定和重新绑定packages

db2 terminate
db2 connect to dbname
db2 BIND /home/db2inst2/sqllib/bnd/db2schema.bnd BLOCKING ALL GRANT PUBLIC SQLERROR CONTINUE
db2 BIND /home/db2inst2/sqllib/bnd/@db2ubind.lst BLOCKING ALL GRANT PUBLIC ACTION ADD
db2 BIND /home/db2inst2/sqllib/bnd/@db2cli.lst BLOCKING ALL GRANT PUBLIC ACTION ADD
db2 terminate
db2rbind xifenfei -l logfile all
发表在 DB2 | 一条评论

记录一次ORA-00600[kdsgrp1]分析

数据库版本

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
NLSRTL Version 10.2.0.4.0 - Production

找出报错对象

--方法1
*** SESSION ID:(795.16405) 2012-04-05 09:36:11.958
            row 080095ee.26 continuation at
            file# 32 block# 38382 slot 39 not found
**************************************************
KDSTABN_GET: 0 ..... ntab: 1
curSlot: 39 ..... nrows: 19
**************************************************

SQL> SELECT OWNER, SEGMENT_NAME, SEGMENT_TYPE, TABLESPACE_NAME, A.PARTITION_NAME
  2    FROM DBA_EXTENTS A
  3   WHERE FILE_ID = &FILE_ID
  4     AND &BLOCK_ID BETWEEN BLOCK_ID AND BLOCK_ID + BLOCKS - 1;
Enter value for file_id: 32
old   3:  WHERE FILE_ID = &FILE_ID
new   3:  WHERE FILE_ID = 32
Enter value for block_id: 38382
old   4:    AND &BLOCK_ID BETWEEN BLOCK_ID AND BLOCK_ID + BLOCKS - 1
new   4:    AND 38382 BETWEEN BLOCK_ID AND BLOCK_ID + BLOCKS - 1

OWNER
------------------------------
SEGMENT_NAME
--------------------------------------------------------------------------------
SEGMENT_TYPE       TABLESPACE_NAME                PARTITION_NAME
------------------ ------------------------------ ------------------------------
AHV8
TBL_IVR_LOG
TABLE PARTITION    CSS_PARTITION                  IVR_LOG_2012_MONTH04

--方法2
*** 2012-04-05 09:36:11.965
ksedmp: internal or fatal error
ORA-00600: internal error code, arguments: [kdsgrp1], [], [], [], [], [], [], []
Current SQL statement for this session:
INSERT INTO TBL_CONTACT_INFO_FAILED_TMP 
select * from TBL_IVR_LOG

SO: 70000017f954f50, type: 4, owner: 70000017f65a840, flag: INIT/-/-/0x00
(session) sid: 795 trans: 70000017464a1e8, creator: 70000017f65a840, flag: (40110041) USR/- BSY/-/-/-/-/-
              DID: 0002-0067-000305BD, short-term DID: 0002-0067-000305BE
              txn branch: 0
              oct: 2, prv: 0, sql: 70000015180ee98, psql: 700000180d67550, user: 49/AHV8
service name: SYS$USERS
O/S info: user: oracle10, term: UNKNOWN, ospid: 12976218, machine: zwq_kfdb2
              program: oracle@zwq_kfdb2 (J002)
last wait for 'db file sequential read' blocking sess=0x0 seq=226 wait_time=17071 seconds since wait started=1
                file#=20, block#=95ee, blocks=1

--方法3
Block header dump:  0x080095ee
 Object id on Block? Y
 seg/obj: 0x11eeb  csc: 0x6f2.848e814  itc: 2  flg: E  typ: 1 - DATA
     brn: 1  bdba: 0x7c09c89 ver: 0x01 opc: 0
     inc: 0  exflg: 0


SQL> select to_number('11eeb','xxxxxxxx') from dual;

TO_NUMBER('11EEB','XXXXXXXX')
-----------------------------
                        73451

SQL> select owner,object_name,subobject_name,object_type from dba_objects where data_object_id='73451';

OWNER
------------------------------
OBJECT_NAME
--------------------------------------------------------------------------------
SUBOBJECT_NAME                 OBJECT_TYPE
------------------------------ -------------------
AHV8
TBL_IVR_LOG
IVR_LOG_2012_MONTH04           TABLE PARTITION

验证是否真的坏块

SQL> select name from v$datafile where file#=32;

NAME
------------------------------------------------------
/dev/rdb1_data27

[zwq_kfdb2:/home/oraeye]dbv file='/dev/rdb1_data27' blocksize=8192

DBVERIFY: Release 10.2.0.4.0 - Production on Fri Apr 13 15:33:10 2012

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

DBVERIFY - Verification starting : FILE = /dev/rdb1_data27
  

DBVERIFY - Verification complete

Total Pages Examined         : 1048448
Total Pages Processed (Data) : 947357
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 4756
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 96335
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Highest block SCN            : 297329920 (1778.297329920)

SQL> select count(*) from AHV8.TBL_IVR_LOG partition(IVR_LOG_2012_MONTH04);

  COUNT(*)
----------
   8798030

总结:很明显这次出现这个问题,因为内存中出现坏块导致,经过一段时间buffer cache中的坏块内容已经被老化,所以现在不能重现(甚至不用做任何操作)。如果内存中出现了坏块,而且还没有被老化掉,可以刷新data buffer;如果是数据块出现坏块,根据实际情况决定处理

发表在 ORA-xxxxx | 标签为 | 一条评论

DB2中schema管理

0.DB2版本信息

[db2inst1@xifenfei ~]$ db2level
DB21085I  Instance "db2inst1" uses "32" bits and DB2 code release "SQL09050" 
with level identifier "03010107".
Informational tokens are "DB2 v9.5.0.0", "s071001", "LINUXIA3295", and Fix Pack 
"0".
Product is installed at "/opt/db2/V9.5".

1.显示syscat.schemata视图结构

[db2inst1@xifenfei ~]$ db2 "describe table syscat.schemata"

                                Data type                     Column
Column name                     schema    Data type name      Length     Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
SCHEMANAME                      SYSIBM    VARCHAR                    128     0 No    
OWNER                           SYSIBM    VARCHAR                    128     0 No    
OWNERTYPE                       SYSIBM    CHARACTER                    1     0 No    
DEFINER                         SYSIBM    VARCHAR                    128     0 No    
DEFINERTYPE                     SYSIBM    CHARACTER                    1     0 No    
CREATE_TIME                     SYSIBM    TIMESTAMP                   10     0 No    
REMARKS                         SYSIBM    VARCHAR                    254     0 Yes 

2.查询当前存在schema

[db2inst1@xifenfei ~]$ db2 "select SCHEMANAME,owner,CREATE_TIME from syscat.schemata"

SCHEMANAME                 OWNER                      CREATE_TIME               
------------            ------------                   ----------------------------
SYSIBM                     SYSIBM                     2012-03-25-15.07.07.196612
SYSCAT                     SYSIBM                     2012-03-25-15.07.07.196612
SYSFUN                     SYSIBM                     2012-03-25-15.07.07.196612
SYSSTAT                    SYSIBM                     2012-03-25-15.07.07.196612
SYSPROC                    SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMADM                  SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMINTERNAL             SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMTS                   SYSIBM                     2012-03-25-15.07.07.196612
NULLID                     SYSIBM                     2012-03-25-15.07.23.011671
SQLJ                       SYSIBM                     2012-03-25-15.07.54.575637
SYSTOOLS                   DB2INST1                   2012-03-25-15.09.01.964744

  11 record(s) selected.

3.显示创建schema

[db2inst1@xifenfei ~]$  db2 "create schema xifenfei"
DB20000I  The SQL command completed successfully.

[db2inst1@xifenfei ~]$ db2 "select SCHEMANAME,owner,CREATE_TIME from syscat.schemata"

SCHEMANAME                 OWNER                      CREATE_TIME               
------------            ------------                  ----------------------------
SYSIBM                     SYSIBM                     2012-03-25-15.07.07.196612
SYSCAT                     SYSIBM                     2012-03-25-15.07.07.196612
SYSFUN                     SYSIBM                     2012-03-25-15.07.07.196612
SYSSTAT                    SYSIBM                     2012-03-25-15.07.07.196612
SYSPROC                    SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMADM                  SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMINTERNAL             SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMTS                   SYSIBM                     2012-03-25-15.07.07.196612
NULLID                     SYSIBM                     2012-03-25-15.07.23.011671
SQLJ                       SYSIBM                     2012-03-25-15.07.54.575637
SYSTOOLS                   DB2INST1                   2012-03-25-15.09.01.964744
XIFENFEI                   DB2INST1                   2012-04-03-12.01.12.724932

  12 record(s) selected.

4.隐式创建schema

[db2inst1@xifenfei ~]$ db2 "create table xff.t_xifenfei(id int,name varchar(100))"
DB20000I  The SQL command completed successfully.
[db2inst1@xifenfei ~]$ db2 "select SCHEMANAME,owner,CREATE_TIME from syscat.schemata"

SCHEMANAME                 OWNER                      CREATE_TIME               
------------            ------------                 ----------------------------
SYSIBM                     SYSIBM                     2012-03-25-15.07.07.196612
SYSCAT                     SYSIBM                     2012-03-25-15.07.07.196612
SYSFUN                     SYSIBM                     2012-03-25-15.07.07.196612
SYSSTAT                    SYSIBM                     2012-03-25-15.07.07.196612
SYSPROC                    SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMADM                  SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMINTERNAL             SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMTS                   SYSIBM                     2012-03-25-15.07.07.196612
NULLID                     SYSIBM                     2012-03-25-15.07.23.011671
SQLJ                       SYSIBM                     2012-03-25-15.07.54.575637
SYSTOOLS                   DB2INST1                   2012-03-25-15.09.01.964744
XIFENFEI                   DB2INST1                   2012-04-03-12.01.12.724932
XFF                        SYSIBM                     2012-04-03-12.03.12.581260

  13 record(s) selected.

隐式创建schema的所属用户会是SYSIBM(存放系统数据字典表SCHEMA)

5.删除schema

[db2inst1@xifenfei ~]$ db2 "drop schema xff"
DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0104N  An unexpected token "END-OF-STATEMENT" was found following "drop 
schema xff".  Expected tokens may include:  "RESTRICT".  SQLSTATE=42601

[db2inst1@xifenfei ~]$  db2 drop schema xff restrict 
DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0478N  DROP, ALTER, TRANSFER OWNERSHIP or REVOKE on object type "SCHEMA" 
cannot be processed because there is an object "XFF.T_XIFENFEI", of type 
"TABLE", which depends on it.  SQLSTATE=42893

[db2inst1@xifenfei ~]$ db2 "drop table xff.t_xifenfei"
DB20000I  The SQL command completed successfully.

[db2inst1@xifenfei ~]$  db2 drop schema xff restrict 
DB20000I  The SQL command completed successfully.

[db2inst1@xifenfei ~]$ db2 "select SCHEMANAME,owner,CREATE_TIME from syscat.schemata"

SCHEMANAME                 OWNER                      CREATE_TIME               
------------            ------------                 ----------------------------
SYSIBM                     SYSIBM                     2012-03-25-15.07.07.196612
SYSCAT                     SYSIBM                     2012-03-25-15.07.07.196612
SYSFUN                     SYSIBM                     2012-03-25-15.07.07.196612
SYSSTAT                    SYSIBM                     2012-03-25-15.07.07.196612
SYSPROC                    SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMADM                  SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMINTERNAL             SYSIBM                     2012-03-25-15.07.07.196612
SYSIBMTS                   SYSIBM                     2012-03-25-15.07.07.196612
NULLID                     SYSIBM                     2012-03-25-15.07.23.011671
SQLJ                       SYSIBM                     2012-03-25-15.07.54.575637
SYSTOOLS                   DB2INST1                   2012-03-25-15.09.01.964744
XIFENFEI                   DB2INST1                   2012-04-03-12.01.12.724932

  12 record(s) selected.

删除schema需要使用restrict关键字,而且该schema中无对象存在.

在DB2中的schema的概念和ORACLE中的概念有着本质的区别:在ORACLE中schema和用户是同一个;在DB2中schema不一定是用户,因为db2内部没有用户的概念,连接用户必须是操作系统用户.

发表在 DB2 | 评论关闭