Oracle诊断案例-Sql_trace之一-eygle.com

Oracle诊断案例-Sql_trace之一

问题描述:

这是帮助一个公司的诊断案例.
应用是一个后台新闻发布系统.

症状是,通过连接访问新闻页是极其缓慢
通常需要十数秒才能返回.

这种性能是用户不能忍受的.

操作系统:SunOS 5.8
数据库版本:8.1.7

1.检查并跟踪数据库进程

诊断时是晚上,无用户访问
在前台点击相关页面,同时进行进程跟踪

查询v$session视图,获取进程信息

SQL> select sid,serial#,username from v$session;

       SID    SERIAL# USERNAME
---------- ---------- ------------------------------
         1          1
         2          1
         3          1
         4          1
         5          1
         6          1
         7        284 IFLOW
        11        214 IFLOW
        12        164 SYS
        16       1042 IFLOW

10 rows selected.

启用相关进程sql_trace

SQL> exec dbms_system.set_sql_trace_in_session(7,284,true)

PL/SQL procedure successfully completed.

SQL> exec dbms_system.set_sql_trace_in_session(11,214,true)

PL/SQL procedure successfully completed.

SQL> exec dbms_system.set_sql_trace_in_session(16,1042,true)

PL/SQL procedure successfully completed.

SQL> select sid,serial#,username from v$session;

       SID    SERIAL# USERNAME
---------- ---------- ------------------------------
         1          1
         2          1
         3          1
         4          1
         5          1
         6          1
         7        284 IFLOW
        11        214 IFLOW
        12        164 SYS
        16       1042 IFLOW

10 rows selected.

等候一段时间,关闭sql_trace

SQL> exec dbms_system.set_sql_trace_in_session(7,284,false)

PL/SQL procedure successfully completed.

SQL> exec dbms_system.set_sql_trace_in_session(11,214,false)

PL/SQL procedure successfully completed.

SQL> exec dbms_system.set_sql_trace_in_session(16,1042,false)

PL/SQL procedure successfully completed.

2.检查trace文件

检查发现以下语句是可疑的

********************************************************************************

select auditstatus,categoryid,auditlevel
from
 categoryarticleassign a,category b where b.id=a.categoryid and articleId=
  20030700400141 and auditstatus>0

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute    1      0.00       0.00          0          0          0           0
Fetch        1      0.81       0.81          0       3892          0           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.81       0.81          0        3892           0         1
********************************************************************************

这里显然是根据articleId进行新闻读取的.
很可疑的是query读取有3892

这个内容引起了我的注意.
如果遇到过类似的问题，大家在这里就应该知道是怎么回事情了.
如果没有遇到过的朋友，可以在这里思考一下再往下看.

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 41

Rows     Row Source Operation
-------  ---------------------------------------------------
      1  NESTED LOOPS
      2   INDEX RANGE SCAN (object id 25062)
      1   TABLE ACCESS BY INDEX ROWID CATEGORY
      2    INDEX UNIQUE SCAN (object id 25057)

********************************************************************************

select auditstatus,categoryid
from
 categoryarticleassign where articleId=20030700400138 and categoryId in ('63',
  '138','139','140','141','142','143','144','168','213','292','341','346',
  '347','348','349','350','351','352','353','354','355','356','357','358',
  '359','360','361','362','363','364','365','366','367','368','369','370',
  '371','372','383','460','461','462','463','621','622','626','629','631',
  '634','636','643','802','837','838','849','850','851','852','853','854',
  '858','859','860','861','862','863','-1')

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      4.91       4.91          0       2835          7           1
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      4.91       4.91          0       2835          7           1

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 41

Rows     Row Source Operation
-------  ---------------------------------------------------
      1 'TABLE ACCESS FULL CATEGORYARTICLEASSIGN'

我们注意到，这里有一个全表扫描存在

********************************************************************************

3.登陆数据库,检查相应表结构

SQL> select index_name,table_name,column_name from user_ind_columns
  2  where table_name=upper('categoryarticleassign');

INDEX_NAME                     TABLE_NAME                     COLUMN_NAME
------------------------------ ------------------------------ --------------------
IDX_ARTICLEID                              CATEGORYARTICLEASSIGN          ARTICLEID
IND_ARTICLEID_CATEG                  CATEGORYARTICLEASSIGN          ARTICLEID
IND_ARTICLEID_CATEG                  CATEGORYARTICLEASSIGN          CATEGORYID
IDX_SORTID                                   CATEGORYARTICLEASSIGN          SORTID
PK_CATEGORYARTICLEASSIGN       CATEGORYARTICLEASSIGN          ARTICLEID
PK_CATEGORYARTICLEASSIGN       CATEGORYARTICLEASSIGN          CATEGORYID
PK_CATEGORYARTICLEASSIGN       CATEGORYARTICLEASSIGN          ASSIGNTYPE
IDX_CAT_ARTICLE                          CATEGORYARTICLEASSIGN          AUDITSTATUS
IDX_CAT_ARTICLE                          CATEGORYARTICLEASSIGN          ARTICLEID
IDX_CAT_ARTICLE                          CATEGORYARTICLEASSIGN          CATEGORYID
IDX_CAT_ARTICLE                          CATEGORYARTICLEASSIGN          ASSIGNTYPE

11 rows selected.

我们注意到,IDX_ARTICLEID索引在以上查询中都没有被用到.

检查表结构:

SQL> desc categoryarticleassign
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 CATEGORYID                                NOT NULL NUMBER
 ARTICLEID                                 NOT NULL VARCHAR2(14)
 ASSIGNTYPE                                NOT NULL VARCHAR2(1)
 AUDITSTATUS                               NOT NULL NUMBER
 SORTID                                    NOT NULL NUMBER
 UNPASS                                             VARCHAR2(255)

问题发现:
因为ARTICLEID是个字符型数据,查询中给入的articleId= 20030700400141 是一个数字值
Oracle发生潜在的数据类型转换,从而导致了索引失效

SQL>  select auditstatus,categoryid
  2   from
  3    categoryarticleassign where articleId=20030700400132;

AUDITSTATUS CATEGORYID
----------- ----------
          9         94
          0        383
          0        695

Elapsed: 00:00:02.62

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=110 Card=2 Bytes=38)
   1    0   TABLE ACCESS (FULL) OF 'CATEGORYARTICLEASSIGN' (Cost=110 Card=2 Bytes=38)

4.解决方法

简单的在参数两侧各增加一个',既可解决这个问题.

对于类似的查询,我们发现Query模式读取降低为2
几乎不需要花费CPU时间了

********************************************************************************

select unpass
from
 categoryarticleassign where articleid='20030320000682' and categoryid='113'

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute    1      0.00       0.00          0          0          0           0
Fetch        1      0.00       0.00          0          2          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.00       0.00          0          2          0           0

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 20

Rows     Row Source Operation
-------  ---------------------------------------------------
      0  TABLE ACCESS BY INDEX ROWID CATEGORYARTICLEASSIGN
      1   INDEX RANGE SCAN (object id 3080)

********************************************************************************

至此,这个问题得到了完满的解决.

2004年6月26日 星期六 11:57

If you have any question,please mail to eygle@itpub.net .


Oracle诊断案例-Sql_trace之二-eygle.com

Oracle诊断案例-Sql_trace之二

问题说明:

很多时候
在我们进行数据库操作时
比如drop user,drop table等，经常会遇到这样的错误

ORA-00604: error occurred at recursive SQL level 1 .

这样的提示，很多时候是没有丝毫用处的.
本案例就这一类问题提供一个思路及方法供大家参考.

1. drop user出现问题

报出以下错误后退出

ORA-00604: error occurred at recursive SQL level 1
ORA-00942: table or view does not exist .

关于 recursive SQL 错误
我们有必要做个简单说明.

我们知道，当我们发出一条简单的命令以后
Oracle数据库要在后台解析这条命令，并转换为Oracle数据库的一系列后台操作.
这些后台操作统称为递归sql

比如create table这样一条简单的DDL命令
Oracle数据库在后台，实际上要把这个命令转换为
对于obj$,tab$,col$等底层表的插入操作.

Oracle所作的工作可能比我们有时候想的要复杂的多.

2.跟踪问题

我们知道Oracle提供sql_trace的功能
可以用于跟踪Oracle数据库的后台递归操作.

通过跟踪文件，我们可以找到问题的所在
以下是格式化(tkprof)后的输出:

********************************************************************************

The following statement encountered a error during parse:

DELETE FROM SDO_GEOM_METADATA_TABLE WHERE SDO_OWNER = 'WAPCOMM'

Error encountered: ORA-00942

********************************************************************************

Oracle把错误信息首先呈现出来
我们看到ORA-00942错误是由于SDO_GEOM_METADATA_TABLE表/视图不存在所致

问题由此可以定位

对于这一类的错误，定位问题以后解决的方法就要依据具体问题原因而定了。

3.问题定位

对于本案例，通过Metalink获得以下解释:

Problem Description
-------------------
The Oracle Spatial Option has been installed and you are encountering
the following errors while trying to drop a user, who has no spatial tables,
connected as SYSTEM:

ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-00942: table or view does not exist
ORA-06512: at line 7

A 942 error trace shows the failing SQL statement as:

DELETE FROM SDO_GEOM_METADATA_TABLE WHERE SDO_OWNER = '<user>'

Solution Description

--------------------

(1) Create a synonym for SDO_GEOM_METADATA_TABLE under SYSTEM which points to

MDSYS.SDO_GEOM_METADATA_TABLE.

对于本例，为MDSYS.SDO_GEOM_METADATA_TABLE创建一个同义词即可解决.
是相对简单的情况.

(2) Now the user can be dropped connected as SYSTEM.

Related Documents

-----------------
<Note.159776.1> ORA-604 and ORA-942 Reported During DROP USER CASCA

4.实际处理

MDSYS.SDO_GEOM_METADATA_TABLE为Spatial对象
如果未使用Spatial选项，可以删除

SQL> connect / as sysdba
Connected.

SQL> select * from dba_sdo_geom_metadata order by owner;
select * from dba_sdo_geom_metadata order by owner
*
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-04063: view "MDSYS.DBA_SDO_GEOM_METADATA" has errors

SQL> select object_name from dba_objects where object_name like '%SDO%';

OBJECT_NAME
--------------------------------------------------------------------------------
ALL_SDO_GEOM_METADATA
ALL_SDO_INDEX_INFO
ALL_SDO_INDEX_METADATA
DBA_SDO_GEOM_METADATA
DBA_SDO_INDEX_INFO
DBA_SDO_INDEX_METADATA
....
DBA_SDO_GEOM_METADATA
DBA_SDO_INDEX_INFO
...
SDO_WITHIN_DISTANCE
USER_SDO_GEOM_METADATA
USER_SDO_INDEX_INFO
USER_SDO_INDEX_METADATA

88 rows selected.

SQL> drop user MDSYS cascade;

User dropped.

SQL> select owner,type_name from dba_types where type_name like 'SDO%';

no rows selected

SQL>

SQL> alter session set sql_trace=true;

Session altered.

SQL> drop user wapcomm;

User dropped.

SQL> alter session set sql_trace=false;

Session altered.

SQL> exit
Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - 64bit Production
With the Partitioning option
JServer Release 8.1.7.4.0 - 64bit Production

这时用户得以顺利drop

5.一点总结

使用sql_trace可以跟踪数据库的很多后台操作
有利于我们发现问题的所在

很多时候，我们想要研究Oracle的内部活动或后台操作
也可以通过sql_trace跟踪

sql_trace/10046 是Oracle提供的最为有效的诊断工具之一.

04/6/26 星期六 22:07

If you have any question,please mail to eygle@itpub.net .


Oracle诊断案例-SGA与Swap之一-www.eygle.com

Oracle诊断案例-SGA与Swap之一

Thursday, 2004-10-07 15:54 Eygle

itpub link:

http://www.itpub.net/showthread.php?s=&threadid=213582

案例描述:

用户报告，服务器启动一段时间以后，无法建立数据库连接
重新启动几分钟以后，再次无法连接

系统无法正常使用.

1.登陆系统

SunOS 5.8

login: root
Password:
Last login: Tue Mar 23 13:56:59 from 172.16.31.41
Sun Microsystems Inc. SunOS 5.8 Generic Patch October 2001
You have new mail.

2.su 为Oracle用户
检查启动的Oracle进程

发现后台进程正常，有一定量的用户连接

wapplatform:/>su - oracle
Sun Microsystems Inc. SunOS 5.8 Generic Patch October 2001
You have new mail.
/export/home1/oracle>ls
admin codesyndealt31 exp.sh local.cshrc local.profile oraclebak oui v6_database
app exp.log jre local.login nsmail oradata swan
export/home1/oracle>cd admin
/export/home1/oracle/admin>ps -ef|grep ora
oracle 25269 25258 0 13:58:36 pts/3 0:00 grep ora
oracle 25257 24906 0 13:58:31 pts/4 0:00 vi alert_HSWAPDB.log
oracle 25267 1 1 13:58:34 ? 0:00 oracleHSWAPDB (LOCAL=NO)
oracle 25184 1 0 13:56:57 ? 0:00 ora_p007_HSWAPDB
oracle 25182 1 0 13:56:57 ? 0:00 ora_p006_HSWAPDB
oracle 25193 1 0 13:57:03 ? 0:01 oracleHSWAPDB (LOCAL=NO)
oracle 25209 1 0 13:57:09 ? 0:00 oracleHSWAPDB (LOCAL=NO)
oracle 25176 1 0 13:56:57 ? 0:00 ora_p003_HSWAPDB
oracle 25180 1 0 13:56:57 ? 0:00 ora_p005_HSWAPDB
oracle 25172 1 0 13:56:56 ? 0:00 ora_p001_HSWAPDB
oracle 25178 1 0 13:56:57 ? 0:00 ora_p004_HSWAPDB
oracle 25170 1 0 13:56:56 ? 0:00 ora_p000_HSWAPDB
oracle 24254 24240 0 12:08:25 pts/2 0:00 -ksh
oracle 25174 1 0 13:56:56 ? 0:00 ora_p002_HSWAPDB
oracle 25244 1 1 13:58:23 ? 0:00 oracleHSWAPDB (LOCAL=NO)
oracle 25218 1 0 13:57:23 ? 0:00 oracleHSWAPDB (LOCAL=NO)
oracle 25159 1 0 13:56:42 ? 0:02 ora_qmn0_HSWAPDB
oracle 25230 1 0 13:57:40 ? 0:01 oracleHSWAPDB (LOCAL=NO)
oracle 25161 1 0 13:56:42 ? 0:00 ora_s000_HSWAPDB
oracle 25149 1 0 13:56:41 ? 0:01 ora_lgwr_HSWAPDB
oracle 25157 1 0 13:56:42 ? 0:00 ora_cjq0_HSWAPDB
oracle 24906 3698 0 13:47:47 pts/4 0:00 -ksh
oracle 25153 1 0 13:56:42 ? 0:01 ora_smon_HSWAPDB
oracle 25058 7464 0 13:55:14 pts/1 0:00 -ksh
oracle 25163 1 0 13:56:42 ? 0:00 ora_d000_HSWAPDB
oracle 25155 1 0 13:56:42 ? 0:00 ora_reco_HSWAPDB
oracle 25151 1 0 13:56:41 ? 0:00 ora_ckpt_HSWAPDB
oracle 25145 1 0 13:56:41 ? 0:00 ora_dbw0_HSWAPDB
oracle 25199 1 15 13:57:04 ? 0:49 ora_j000_HSWAPDB
oracle 4149 4146 0 12:05:11 pts/5 0:00 -ksh
oracle 25232 1 0 13:57:41 ? 0:00 oracleHSWAPDB (LOCAL=NO)
oracle 25119 1 0 13:56:29 ? 0:00 oraclehswapdb (LOCAL=NO)
oracle 25075 1 0 13:55:34 ? 0:00 /export/home1/oracle/app/bin/tnslsnr LISTENER -inherit
oracle 24374 4149 0 12:21:56 pts/5 0:00 sqlplus /nolog
oracle 25143 1 0 13:56:41 ? 0:00 ora_pmon_HSWAPDB
oracle 25258 25242 0 13:58:31 pts/3 0:00 -ksh
/export/home1/oracle/admin>ps -ef|grep ora_
oracle 25275 25258 0 13:58:42 pts/3 0:00 grep ora_
oracle 25184 1 0 13:56:57 ? 0:00 ora_p007_HSWAPDB
oracle 25182 1 0 13:56:57 ? 0:00 ora_p006_HSWAPDB
oracle 25176 1 0 13:56:57 ? 0:00 ora_p003_HSWAPDB
oracle 25180 1 0 13:56:57 ? 0:00 ora_p005_HSWAPDB
oracle 25172 1 0 13:56:56 ? 0:00 ora_p001_HSWAPDB
oracle 25178 1 0 13:56:57 ? 0:00 ora_p004_HSWAPDB
oracle 25170 1 0 13:56:56 ? 0:00 ora_p000_HSWAPDB
oracle 25174 1 0 13:56:56 ? 0:00 ora_p002_HSWAPDB
oracle 25159 1 0 13:56:42 ? 0:02 ora_qmn0_HSWAPDB
oracle 25161 1 0 13:56:42 ? 0:00 ora_s000_HSWAPDB
oracle 25149 1 0 13:56:41 ? 0:01 ora_lgwr_HSWAPDB
oracle 25157 1 0 13:56:42 ? 0:00 ora_cjq0_HSWAPDB
oracle 25153 1 0 13:56:42 ? 0:01 ora_smon_HSWAPDB
oracle 25163 1 0 13:56:42 ? 0:00 ora_d000_HSWAPDB
oracle 25155 1 0 13:56:42 ? 0:00 ora_reco_HSWAPDB
oracle 25151 1 0 13:56:41 ? 0:00 ora_ckpt_HSWAPDB
oracle 25145 1 0 13:56:41 ? 0:00 ora_dbw0_HSWAPDB
oracle 25199 1 13 13:57:04 ? 0:51 ora_j000_HSWAPDB
oracle 25143 1 0 13:56:41 ? 0:00 ora_pmon_HSWAPDB

3.检查Alert.log警报日志文件

/export/home1/oracle/admin>ls
hswapdb
/export/home1/oracle/admin>cd *
/export/home1/oracle/admin/hswapdb>ls
bdump cdump create pfile udump
/export/home1/oracle/admin/hswapdb>cd bdump
/export/home1/oracle/admin/hswapdb/bdump>

/export/home1/oracle/admin/hswapdb/bdump>ls -l *.log

-rw-r--r-- 1 oracle dba 813396 Mar 23 13:57 alert_HSWAPDB.log
/export/home1/oracle/admin/hswapdb/bdump>vi *.log
"alert_HSWAPDB.log" 18888 lines, 813396 characters (115 null)
Tue Jun 24 21:17:14 2003
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
SCN scheme 3
Using log_archive_dest parameter default value
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up ORACLE RDBMS Version: 9.2.0.3.0.
System parameters with non-default values:
processes = 400
timed_statistics = TRUE
shared_pool_size = 117440512
large_pool_size = 83886080
java_pool_size = 33554432
control_files = /export/home1/oracle/oradata/hswapdb/control01.ctl,

/export/home1/oracle/oradata/hswapdb/control02.ctl,
/export/home1/oracle/oradata/hswapdb/control03.ctl
db_block_size = 8192
db_cache_size = 352321536
compatible = 9.2.0.0.0
db_file_multiblock_read_count= 16
fast_start_mttr_target = 300
undo_management = AUTO
undo_tablespace = UNDOTBS1
undo_retention = 10800
remote_login_passwordfile= EXCLUSIVE
db_domain = eygle.com
instance_name = hswapdb
dispatchers = (PROTOCOL=TCP) (SERVICE=hswapdbXDB)
job_queue_processes = 10
hash_join_enabled = TRUE
background_dump_dest = /export/home1/oracle/admin/hswapdb/bdump
user_dump_dest = /export/home1/oracle/admin/hswapdb/udump
core_dump_dest = /export/home1/oracle/admin/hswapdb/cdump
sort_area_size = 524288
db_name = hswapdb
open_cursors = 300
star_transformation_enabled= FALSE
query_rewrite_enabled = FALSE
pga_aggregate_target = 154140672
aq_tm_processes = 1

.................

Tue Mar 23 13:40:45 2004
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 11, op = fork, loc = skgpspawn5
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
Tue Mar 23 13:42:02 2004
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
Tue Mar 23 13:55:38 2004
Starting ORACLE instance (normal)
Shutting down instance: further logons disabled
Tue Mar 23 13:56:20 2004
Shutting down instance (abort)
License high water mark = 26
Instance terminated by USER, pid = 25112
Tue Mar 23 13:56:37 2004
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
SCN scheme 3
Using log_archive_dest parameter default value
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up ORACLE RDBMS Version: 9.2.0.3.0.
System parameters with non-default values:
processes = 400
timed_statistics = TRUE
shared_pool_size = 117440512
large_pool_size = 83886080
java_pool_size = 33554432
control_files = /export/home1/oracle/oradata/hswapdb/control01.ctl,

/export/home1/oracle/oradata/hswapdb/control02.ctl,
/export/home1/oracle/oradata/hswapdb/control03.ctl
db_block_size = 8192
db_cache_size = 352321536
compatible = 9.2.0.0.0
db_file_multiblock_read_count= 16
fast_start_mttr_target = 300
undo_management = AUTO
undo_tablespace = UNDOTBS1
undo_retention = 10800
remote_login_passwordfile= EXCLUSIVE
db_domain = eygle.com
instance_name = hswapdb
dispatchers = (PROTOCOL=TCP) (SERVICE=hswapdbXDB)
remote_dependencies_mode = SIGNATURE
job_queue_processes = 10
hash_join_enabled = TRUE
background_dump_dest = /export/home1/oracle/admin/hswapdb/bdump
user_dump_dest = /export/home1/oracle/admin/hswapdb/udump
core_dump_dest = /export/home1/oracle/admin/hswapdb/cdump
sort_area_size = 524288
db_name = hswapdb
open_cursors = 300
star_transformation_enabled= FALSE
parallel_automatic_tuning= TRUE
query_rewrite_enabled = FALSE
pga_aggregate_target = 154140672
aq_tm_processes = 1
PMON started with pid=2
DBW0 started with pid=3
LGWR started with pid=4
CKPT started with pid=5
SMON started with pid=6
RECO started with pid=7
CJQ0 started with pid=8
QMN0 started with pid=9
Tue Mar 23 13:56:42 2004
starting up 1 shared server(s) ...
Tue Mar 23 13:56:42 2004
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
Tue Mar 23 13:56:43 2004
ALTER DATABASE MOUNT
Tue Mar 23 13:56:47 2004
Successful mount of redo thread 1, with mount id 3253076635.
Tue Mar 23 13:56:47 2004
Database mounted in Exclusive Mode.
Completed: ALTER DATABASE MOUNT
Tue Mar 23 13:56:47 2004
Current log# 2 seq# 2136 mem# 0: /export/home1/oracle/oradata/hswapdb/redo02.log
Successful open of redo thread 1.
Tue Mar 23 12:24:54 2004
SMON: enabling cache recovery
Tue Mar 23 12:24:56 2004
Undo Segment 1 Onlined
Undo Segment 2 Onlined
Undo Segment 3 Onlined
Undo Segment 4 Onlined
Undo Segment 5 Onlined
Undo Segment 6 Onlined
Undo Segment 7 Onlined
Undo Segment 8 Onlined
Undo Segment 9 Onlined
Undo Segment 10 Onlined
Successfully onlined Undo Tablespace 1.
Tue Mar 23 12:24:56 2004
SMON: enabling tx recovery
Tue Mar 23 12:24:56 2004
Database Characterset is ZHS16GBK
Tue Mar 23 12:25:01 2004
SMON: Parallel transaction recovery tried
Tue Mar 23 12:25:01 2004
replication_dependency_tracking turned off (no async multimaster replication found)
Completed: ALTER DATABASE OPEN
Tue Mar 23 12:28:26 2004
/* OracleOEM */ ALTER DATABASE DATAFILE '/export/home1/oracle/oradata/hswapdb/users01.dbf' RESIZE 2501760K
Tue Mar 23 12:28:26 2004
ORA-3297 signalled during: /* OracleOEM */ ALTER DATABASE DATAFILE '/export/h...
Tue Mar 23 12:28:32 2004
/* OracleOEM */ ALTER DATABASE DATAFILE '/export/home1/oracle/oradata/hswapdb/users01.dbf' RESIZE 2501760K
ORA-3297 signalled during: /* OracleOEM */ ALTER DATABASE DATAFILE '/export/h...
Tue Mar 23 12:28:53 2004
/* OracleOEM */ ALTER DATABASE DATAFILE '/export/home1/oracle/oradata/hswapdb/users01.dbf' RESIZE 3501760K
Tue Mar 23 12:28:53 2004
ORA-3297 signalled during: /* OracleOEM */ ALTER DATABASE DATAFILE '/export/h...
Tue Mar 23 13:40:45 2004
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 11, op = fork, loc = skgpspawn5
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
Tue Mar 23 13:42:02 2004
skgpspawn failed:category = 27142, depinfo = 12, op = fork, loc = skgpspawn3
:q

发现数据库多次重起，并记录了部分错误信息

该提示说明数据库无法spawn a new session.

quote Yong Huang's comment:

The number in "skgpspawn failed:category = 27142" is probably ORA error:

$ oerr ora 27142
27142, 0000, "could not create new process"
// *Cause: OS system call
// *Action: check errno and if possible increase the number of processes

OSD (OS-dependent) errors are almost always shown as an skg... error (probably means "system, kernel generic").

I don't know what "depinfo = 12" means.

4.尝试连接数据库

收到错误信息，无法连接数据库

$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on 星期二 3月 23 14:14:06 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

ERROR:
ORA-12540: TNS: 超出内部限制

请输入用户名:
ERROR:
ORA-12540: TNS: 超出内部限制

请输入用户名:
ERROR:
ORA-12540: TNS: 超出内部限制

SP2-0157: 在3次尝试之后无法 CONNECT 到 ORACLE, 退出 SQL*Plus

内部限制超过，通常说明某些系统资源不足.

5.检查监听器

发现部分连接被拒绝

/export/home1/oracle>lsnrctl services

LSNRCTL for Solaris: Version 9.2.0.3.0 - Production on 23-3月 -2004 14:37:23

Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.

正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC)))
服务摘要..
服务 "PLSExtProc" 包含 1 个例程。
例程 "PLSExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
处理程序:
"DEDICATED" 已建立:0 已被拒绝:0
LOCAL SERVER
服务 "hswapdb.eygle.com" 包含 2 个例程。
例程 "hswapdb", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
处理程序:
"DEDICATED" 已建立:6 已被拒绝:0
LOCAL SERVER
例程 "hswapdb", 状态 READY, 包含此服务的 1 个处理程序...
处理程序:
"DEDICATED" 已建立:21 已拒绝:6 状态:ready
LOCAL SERVER
服务 "hswapdbXDB.eygle.com" 包含 1 个例程。
例程 "hswapdb", 状态 READY, 包含此服务的 1 个处理程序...
处理程序:
"D000" 已建立:0 已被拒绝:0 当前: 0 最大: 972 状态: ready
DISPATCHER <machine: wapplatform, pid: 25839>
(ADDRESS=(PROTOCOL=tcp)(HOST=wapplatform)(PORT=32869))
命令执行成功

在listener.log中找到了相关错误信息

23-3\324\302 -2004 12:19:40 * (CONNECT_DATA=(SID=hswapdb)(CID=(PROGRAM=C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.e
xe)(HOST=SWAN)(USER=SYSTEM))) * (ADDRESS=(PROTOCOL=tcp)(HOST=172.16.30.125)(PORT=1291)) * establish * hswapdb * 12500
TNS-12500: TNS\243\272\274\340\314\375\306\367\316\264\304\334\306\364\266\257\327\250\323\303\265\304\267\376\316\361\306\36
7\275\370\263\314
TNS-12540: TNS\243\272\263\254\263\366\304\332\262\277\274\253\317\336\317\336\326\306
TNS-12560: TNS: \320\255\322\351\312\312\305\344\306\367\264\355\316\363
TNS-00510: \263\254\263\366\304\332\262\277\274\253\317\336\317\336\326\306
Solaris Error: 12: Not enough space
23-3\324\302 -2004 12:19:50 * (CONNECT_DATA=(SID=hswapdb)(CID=(PROGRAM=C:\Program Files\PLSQL Developer\PLSQLDev.exe)(HOST=SW
AN)(USER=Administrator))) * (ADDRESS=(PROTOCOL=tcp)(HOST=172.16.30.125)(PORT=1292)) * establish * hswapdb * 12500
TNS-12500: TNS\243\272\274\340\314\375\306\367\316\264\304\334\306\364\266\257\327\250\323\303\265\304\267\376\316\361\306\36
7\275\370\263\314
TNS-12540: TNS\243\272\263\254\263\366\304\332\262\277\274\253\317\336\317\336\326\306
TNS-12560: TNS: \320\255\322\351\312\312\305\344\306\367\264\355\316\363
TNS-00510: \263\254\263\366\304\332\262\277\274\253\317\336\317\336\326\306
Solaris Error: 12: Not enough space

/export/home1/oracle/app/network/log>grep -w 12 /usr/include/sys/errno.h
#define ENOMEM 12 /* Not enough core

quote Yong Huang's comment:

$ grep -w 12 /usr/include/sys/errno.h
#define ENOMEM 12 /* Not enough core */

Here "core" means memory, including real RAM memory and swap space.

6.退出Oracle用户检查

检查系统日志信息，发现大量失败的su操作
有swap区不足的报告

/export/home1/oracle/admin/hswapdb/bdump>exit

            wapplatform:/>dmesg

2004年03月23日 星期二 14时00分32秒 CST
Mar 22 22:52:36 wapplatform elfexec: [ID 700856 kern.notice] ps: Cannot find ^?ELF^A^B^A
Mar 22 22:53:00 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 22:53:09 wapplatform elfexec: [ID 700856 kern.notice] w: Cannot find ^?ELF^A^B^A
Mar 22 22:53:53 wapplatform last message repeated 4 times
Mar 22 22:56:28 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 22:58:00 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 22:59:54 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 23:02:26 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:03:00 wapplatform last message repeated 1 time
Mar 22 23:08:00 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:08:34 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 23:10:27 wapplatform last message repeated 3 times
Mar 22 23:11:49 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 23:11:52 wapplatform last message repeated 1 time
Mar 22 23:13:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:18:01 wapplatform last message repeated 1 time
Mar 22 23:23:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:28:01 wapplatform last message repeated 1 time
Mar 22 23:33:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:38:01 wapplatform last message repeated 1 time
Mar 22 23:43:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:48:01 wapplatform last message repeated 1 time
Mar 22 23:53:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:58:01 wapplatform last message repeated 1 time
Mar 23 00:00:00 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 00:00:00 wapplatform sendmail[3075]: [ID 702911 mail.crit] My unqualified host name (wapplatform) unknown; sleeping

for retry
Mar 23 00:01:00 wapplatform sendmail[3075]: [ID 702911 mail.alert] unable to qualify my own domain name (wapplatform) --

using short name
Mar 23 00:02:36 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 23 00:03:02 wapplatform last message repeated 1 time
Mar 23 00:08:02 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
....

Mar 23 10:18:15 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 23 10:20:41 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 10:20:47 wapplatform last message repeated 1 time
Mar 23 10:23:15 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 23 10:24:38 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 10:24:43 wapplatform last message repeated 1 time
Mar 23 10:24:55 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 10:25:06 wapplatform last message repeated 2 times
Mar 23 11:09:31 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3118 (su)
Mar 23 11:09:39 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3121 (su)
Mar 23 11:10:48 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3137 (su)
Mar 23 11:18:02 wapplatform sshd[3620]: [ID 800047 auth.error] error: grantpt: Not enough space
Mar 23 11:18:02 wapplatform sshd[3620]: [ID 800047 auth.error] error: session_pty_req: session 0 alloc failed
Mar 23 11:18:43 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3636 (su)
Mar 23 11:19:47 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3672 (su)
Mar 23 11:20:20 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3694 (su)
Mar 23 11:22:23 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3736 (sshd)
Mar 23 11:23:17 wapplatform tmpfs: [ID 518458 kern.warning] WARNING: /tmp: File system full, swap space limit exceeded
Mar 23 11:23:40 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3804 (su)
Mar 23 11:23:40 wapplatform last message repeated 8 times
Mar 23 11:23:56 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3806 (ps)
Mar 23 11:23:56 wapplatform last message repeated 12 times
Mar 23 11:24:01 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3808 (w)
Mar 23 11:24:01 wapplatform last message repeated 8 times
Mar 23 13:40:56 wapplatform su: [ID 810491 auth.crit] 'su root' failed for root on /dev/pts/2
Mar 23 13:46:26 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 24888

(sqlplus)
Mar 23 13:49:18 wapplatform su: [ID 810491 auth.crit] 'su oracle' failed for root on /dev/pts/6
Mar 23 13:54:03 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 25035 (su)
Mar 23 13:54:08 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 25036 (su)

现在基本可以判断是交换区的问题，当然和Oracle SGA设置有关.

7.检查系统内存及交换区使用

/export/home1/oracle/admin/hswapdb/bdump>exit

            wapplatform:/>dmesg

2004年03月23日 星期二 14时00分32秒 CST
Mar 22 22:52:36 wapplatform elfexec: [ID 700856 kern.notice] ps: Cannot find ^?ELF^A^B^A
Mar 22 22:53:00 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 22:53:09 wapplatform elfexec: [ID 700856 kern.notice] w: Cannot find ^?ELF^A^B^A
Mar 22 22:53:53 wapplatform last message repeated 4 times
Mar 22 22:56:28 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 22:58:00 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 22:59:54 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 23:02:26 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:03:00 wapplatform last message repeated 1 time
Mar 22 23:08:00 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:08:34 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 23:10:27 wapplatform last message repeated 3 times
Mar 22 23:11:49 wapplatform elfexec: [ID 700856 kern.notice] ipnat: Cannot find ^?ELF^B^B^A
Mar 22 23:11:52 wapplatform last message repeated 1 time
Mar 22 23:13:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:18:01 wapplatform last message repeated 1 time
Mar 22 23:23:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:28:01 wapplatform last message repeated 1 time
Mar 22 23:33:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:38:01 wapplatform last message repeated 1 time
Mar 22 23:43:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:48:01 wapplatform last message repeated 1 time
Mar 22 23:53:01 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 22 23:58:01 wapplatform last message repeated 1 time
Mar 23 00:00:00 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 00:00:00 wapplatform sendmail[3075]: [ID 702911 mail.crit] My unqualified host name (wapplatform) unknown; sleeping

for retry
Mar 23 00:01:00 wapplatform sendmail[3075]: [ID 702911 mail.alert] unable to qualify my own domain name (wapplatform) --

using short name
Mar 23 00:02:36 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 23 00:03:02 wapplatform last message repeated 1 time
Mar 23 00:08:02 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
....

Mar 23 10:18:15 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 23 10:20:41 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 10:20:47 wapplatform last message repeated 1 time
Mar 23 10:23:15 wapplatform ufs: [ID 845546 kern.notice] NOTICE: alloc: /export/home1: file system full
Mar 23 10:24:38 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 10:24:43 wapplatform last message repeated 1 time
Mar 23 10:24:55 wapplatform ufs: [ID 213553 kern.notice] NOTICE: realloccg /export/home1: file system full
Mar 23 10:25:06 wapplatform last message repeated 2 times
Mar 23 11:09:31 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3118 (su)
Mar 23 11:09:39 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3121 (su)
Mar 23 11:10:48 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3137 (su)
Mar 23 11:18:02 wapplatform sshd[3620]: [ID 800047 auth.error] error: grantpt: Not enough space
Mar 23 11:18:02 wapplatform sshd[3620]: [ID 800047 auth.error] error: session_pty_req: session 0 alloc failed
Mar 23 11:18:43 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3636 (su)
Mar 23 11:19:47 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3672 (su)
Mar 23 11:20:20 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3694 (su)
Mar 23 11:22:23 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3736 (sshd)
Mar 23 11:23:17 wapplatform tmpfs: [ID 518458 kern.warning] WARNING: /tmp: File system full, swap space limit exceeded
Mar 23 11:23:40 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3804 (su)
Mar 23 11:23:40 wapplatform last message repeated 8 times
Mar 23 11:23:56 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3806 (ps)
Mar 23 11:23:56 wapplatform last message repeated 12 times
Mar 23 11:24:01 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 3808 (w)
Mar 23 11:24:01 wapplatform last message repeated 8 times
Mar 23 13:40:56 wapplatform su: [ID 810491 auth.crit] 'su root' failed for root on /dev/pts/2
Mar 23 13:46:26 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 24888

(sqlplus)
Mar 23 13:49:18 wapplatform su: [ID 810491 auth.crit] 'su oracle' failed for root on /dev/pts/6
Mar 23 13:54:03 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 25035 (su)
Mar 23 13:54:08 wapplatform genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 25036 (su)

现在基本可以判断是交换区的问题，当然和Oracle SGA设置有关.

7.检查系统内存及交换区使用

$ top

last pid: 25456; load averages: 0.67, 0.70, 0.69

14:10:03
93 processes: 91 sleeping, 2 on cpu
CPU states: 72.7% idle, 14.9% user, 2.7% kernel, 9.7% iowait, 0.0% swap
Memory: 1024M real, 34M free, 752M swap in use, 10M swap free

PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
25199 oracle 1 40 0 674M 631M cpu/2 8:03 16.32% oracle
25209 oracle 1 30 0 675M 630M sleep 0:03 0.13% oracle
25159 oracle 1 48 0 674M 628M sleep 0:03 0.06% oracle
25384 oracle 1 58 0 2632K 1736K cpu/0 0:01 0.05% top
25145 oracle 143 58 0 682M 630M sleep 0:01 0.03% oracle
25446 oracle 1 58 0 674M 628M sleep 0:00 0.03% oracle
25149 oracle 15 58 0 682M 626M sleep 0:00 0.02% oracle
25075 oracle 1 48 0 17M 7208K sleep 0:00 0.01% tnslsnr
25151 oracle 11 58 0 676M 624M sleep 0:00 0.01% oracle
25366 oracle 1 10 0 674M 628M sleep 0:00 0.00% oracle
25356 oracle 1 18 0 674M 628M sleep 0:00 0.00% oracle
25360 oracle 1 20 0 674M 628M sleep 0:00 0.00% oracle
25364 oracle 1 20 0 674M 628M sleep 0:00 0.00% oracle
25362 oracle 1 20 0 674M 628M sleep 0:00 0.00% oracle
25330 oracle 1 28 0 674M 628M sleep 0:00 0.00% oracle

发现物理内存仅为1G，free部分为34M，交换区使用了752M，仅10M free
系统内存严重不足，Swap区不足

8. 检查数据库的SGA设置

发现SGA设置为: 622299344 bytes
接近600M

wapplatform:/>su - oracle
Sun Microsystems Inc. SunOS 5.8 Generic Patch October 2001
You have new mail.
/export/home1/oracle>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on 星期二 3月 23 14:02:30 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> show sga

Total System Global Area 622299344 bytes
Fixed Size 731344 bytes
Variable Size 268435456 bytes
Database Buffers 352321536 bytes
Redo Buffers 811008 bytes
SQL>

对于RAM小于1G的系统，Dedicated模式下,Oracle的SGA一般不应超过1/2物理内存.

9.第一步调整
减小SGA，为系统保留足够的内存.

10.增加swap区

wapplatform:/>df -k
文件系统 千字节 用了 可用 容量 挂接在
/dev/dsk/c0t1d0s0 3099093 105421 2931691 4% /
/dev/dsk/c0t2d0s0 10325760 8359637 1862866 82% /usr
/proc 0 0 0 0% /proc
fd 0 0 0 0% /dev/fd
mnttab 0 0 0 0% /etc/mnttab
/dev/dsk/c0t1d0s3 1018382 285914 671366 30% /var
swap 3904 24 3880 1% /var/run
swap 3936 56 3880 2% /tmp
/dev/dsk/c0t1d0s5 1671823 459202 1162467 29% /opt
/dev/dsk/c0t2d0s7 7087473 6068462 948137 87% /export/home
/dev/dsk/c2t1d0s7 17413250 15900222 1338896 93% /export/home2
/dev/dsk/c0t3d0s7 17413250 13749782 3489336 80% /export/home1
/dev/dsk/c0t1d0s1 771110 382410 334723 54% /usr/openwin
/export/home/wapgw/luke
7087473 6068462 948137 87% /home/wap

wapplatform:/var/swap>cd /export/home1
wapplatform:/export/home1>ls
TT_DB lost+found oracle oracli9
wapplatform:/export/home1>mkdir swap
wapplatform:/export/home1>cd swap
wapplatform:/export/home1/swap>mkfile -v 1g swapfile1
swapfile1 1073741824 bytes
wapplatform:/export/home1/swap>id
uid=0(root) gid=1(other)
wapplatform:/export/home1/swap>swap -a /export/home1/swap/swapfile1
wapplatform:/export/home1/swap>swap -s
总数：分配了 623160k 字节 + 保留 162704k = 已使用 785864k，1010936k 可用

11.连接测试

系统恢复正常，问题解决

wapplatform:/export/home1/swap>su - oracle
Sun Microsystems Inc. SunOS 5.8 Generic Patch October 2001
You have new mail.
/export/home1/oracle>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on 星期四 3月 25 11:56:28 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production中断开
/export/home1/oracle>top

last pid: 5372; load averages: 0.25, 0.22, 0.29

11:57:58
148 processes: 137 sleeping, 9 zombie, 2 on cpu
CPU states: 98.8% idle, 0.2% user, 0.7% kernel, 0.2% iowait, 0.0% swap
Memory: 1024M real, 17M free, 824M swap in use, 934M swap free

PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
5363 root 1 58 0 2680K 1736K sleep 0:00 0.24% top
5370 oracle 1 58 0 514M 469M sleep 0:00 0.18% oracle
5366 oracle 1 28 0 514M 469M sleep 0:00 0.11% oracle
5341 oracle 1 58 0 2680K 1736K cpu/2 0:00 0.10% top
5372 oracle 1 48 0 61M 3288K cpu/3 0:00 0.06% oracle
1288 oracle 1 48 0 514M 468M sleep 5:33 0.05% oracle
607 root 12 48 0 2768K 2312K sleep 1:48 0.03% mibiisa
25075 oracle 1 48 0 17M 7208K sleep 0:16 0.02% tnslsnr
1278 oracle 15 58 0 522M 466M sleep 0:49 0.02% oracle
374 root 11 53 0 3504K 2888K sleep 0:16 0.01% nscd
1280 oracle 19 58 0 518M 466M sleep 0:28 0.00% oracle
5361 root 1 46 0 1024K 680K sleep 0:00 0.00% sleep
5362 root 1 46 0 1024K 680K sleep 0:00 0.00% sleep
5469 root 1 36 0 1952K 1176K sleep 30:09 0.00% monithttp
4167 oracle 1 40 0 515M 471M sleep 29:38 0.00% oracle

问题总结:

Oracle数据库问题的解决从来就离不开操作系统

很多时候我们必须通过操作系统一级的手段来诊断并解决问题.

关于操作系统

一般Swap区的推荐值为2XRAM
如果Ram很大，不一定非要把Swap设置为2xSwap
但是通常至少设置Swap = Ram

如果Swap区过小，在系统繁忙期间
产生大量交换无法换到磁盘，就会出现问题.
如本案例就是这样。

另外，如果系统Ram较小
通常设置SGA < 1/2 Ram

要为Server process及OS保留足够的内存空间.

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

如欲转载,请注明作者与出处.并请保留本文的连接.

回首页


Oracle诊断案例-SGA与Swap之二-www.eygle.com

Oracle诊断案例-SGA与Swap之二

Last updated: Thursday, 2004-10-07 16:01 Eygle

itpub link:

http://www.itpub.net/showthread.php?s=&threadid=215452

案例描述:

这是一个大型生产系统
问题出现时系统累计大量用户进程
用户请求得不到及时响应，新的进程不断尝试建立连接
连接数很快被用完

数据库版本:9.2.0.3
操作系统:Solaris8

1.检查alert文件

日志中记录如下错误信息，说明磁盘异步IO出现问题:

WARNING: aiowait timed out 2 times
Tue Aug 26 15:33:32 2003
WARNING:
aiowait timed out 2 times
Tue Aug 26 15:33:34 2003
WARNING: aiowait timed
out 2 times
Tue Aug 26 15:33:36 2003
WARNING: aiowait timed out 2
times
Tue Aug 26 15:33:38 2003
WARNING: aiowait timed out 2 times
Tue
Aug 26 15:33:43 2003
WARNING: aiowait timed out 1 times
Tue Aug 26
15:33:46 2003
WARNING: aiowait timed out 1 times
Tue Aug 26 15:33:49
2003
WARNING: aiowait timed out 1 times
Tue Aug 26 15:33:51
2003
WARNING: aiowait timed out 1 times
Tue Aug 26 15:33:52
2003
WARNING: aiowait timed out 1 times
Tue Aug 26 15:33:53
2003
WARNING: aiowait timed out 1 times
.............

我们知道在SUN的某些版本上异步IO存在问题
而异步IO缺省是打开的

SQL> show parameter disk_a

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
disk_asynch_io boolean TRUE

针对此问题，我们停用了数据库的异步IO写入。

2.共享内存问题

alert文件中还记录了以下错误信息:

  Tue Aug 26 21:37:40 2003

  WARNING: EINVAL creating segment of size 0x0000000190400000

  fix shm parameters in /etc/system or equivalent

该信息说明内核参数设置过小或者和SGA不匹配

我们检查system配置文件

$ cat /etc/system
.......................
set shmsys:shminfo_shmmax=4096000000
set shmsys:shminfo_shmmin=1
set shmsys:shminfo_shmmni=200
set shmsys:shminfo_shmseg=200
set semsys:seminfo_semmap=1024
set semsys:seminfo_semmni=2048
set semsys:seminfo_semmns=2048
set semsys:seminfo_semmnu=2048
set semsys:seminfo_semume=200
set semsys:seminfo_semmsl=2048

我们发现最大共享内存设置仅有4G

3.检查SGA设置

SQL*Plus: Release 9.2.0.3.0 - Production on 星期二 8月 26 21:46:35 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> show sga

Total System Global Area 6695660272 bytes
Fixed Size 740080 bytes
Variable Size 2399141888 bytes
Database Buffers 4294967296 bytes
Redo Buffers 811008 bytes

我们发现SGA设置接近7G，这也就是步骤2中错误提示出现的原因

4.交换区问题

我们用top工具检查系统运行状况

# /usr/local/bin/top

last pid: 16899; load averages: 0.82, 0.81, 0.83 21:49:05
1230 processes:1228 sleeping, 1 running, 1 on cpu
CPU states: 50.1% idle, 7.4% user, 8.6% kernel, 33.9% iowait, 0.0% swap
Memory: 8192M real, 118M free, 12G swap in use, 11G swap free

PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
15751 oracle 11 44 0 6456M 6408M sleep 0:02 0.49% oracle
15725 oracle 11 58 0 6458M 6410M sleep 0:02 0.46% oracle
251 root 12 48 0 7096K 1944K sleep 126:00 0.45% picld
16540 oracle 11 58 0 6458M 6411M sleep 0:01 0.45% oracle
16766 root 1 43 0 3744K 2248K cpu/1 0:01 0.41% top
16408 oracle 11 58 0 6457M 6410M sleep 0:01 0.34% oracle
15989 oracle 11 58 0 6458M 6409M sleep 0:01 0.34% oracle
15919 oracle 11 58 0 6457M 6409M sleep 0:02 0.30% oracle
16404 oracle 11 58 0 6457M 6409M sleep 0:00 0.28% oracle
16327 oracle 11 55 0 6457M 6410M sleep 0:00 0.27% oracle
14870 oracle 11 58 0 6457M 6412M sleep 0:05 0.24% oracle
16851 oracle 11 35 0 6457M 6411M sleep 0:00 0.22% oracle
16467 oracle 11 58 0 6457M 6409M sleep 0:00 0.21% oracle
16163 oracle 11 58 0 6457M 6408M sleep 0:03 0.21% oracle
15159 oracle 11 58 0 6457M 6408M sleep 0:05 0.21% oracle

Memory: 8192M real, 118M free, 12G swap in use, 11G swap free

我们发现系统仅有8G RAM,物理内存仅有118M可用
现在SWAP区使用了12G

我们初步作出以下判断:

SGA设置过大(将近7G)导致运行时产生大量交换

大量SWAP交换进而引发磁盘问题
这也就应该是我们第一步看到
WARNING: aiowait timed out 1 times
的原因

大量交换导致数据库性能急剧下降
进而导致用户请求得不到快速响应，堵塞、累积，直至数据库失去响应

5.解决方案

此问题主要是由于SGA设置不当引起，我们马上缩小了SGA设置:

SQL> show sga

Total System Global Area 3591870848 bytes
Fixed Size 735616 bytes
Variable Size 1442840576 bytes
Database Buffers 2147483648 bytes
Redo Buffers 811008 bytes

此时，数据库减少了交换,达到了稳定运行,用户请求可以得到快速响应。

问题解决完成.

6.系统状态

调整后系统运行状况:

$ top

last pid: 12745;  load averages:  0.46,  0.79,  0.65           22:22:49
228 processes: 227 sleeping, 1 on cpu
CPU states: 92.3% idle,  5.0% user,  1.6% kernel,  1.1% iowait,  0.0% swap
Memory: 8192M real, 3817M free, 4015M swap in use, 15G swap free

   PID USERNAME THR PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
 12610 oracle     1  51    0 3511M   22M sleep    0:04  1.96% oracle
 12595 oracle     1  48    0 3511M   22M sleep    0:03  0.92% oracle
 12630 oracle     1  38    0 3511M   21M sleep    0:01  0.84% oracle
 12614 oracle     1  46    0 3511M   22M sleep    0:01  0.64% oracle
 12620 oracle     1  58    0 3511M   22M sleep    0:01  0.53% oracle
 12709 oracle     1  48    0 3511M   21M sleep    0:00  0.45% oracle
   265 root      11  38    0 7032K 1920K sleep    3:16  0.42% picld
 12729 oracle     1   0    0 3511M   20M sleep    0:00  0.26% oracle
 12741 oracle     1  58    0 2768K 1760K cpu/3    0:00  0.19% top
 12745 oracle     1  44    0 3506M   16M sleep    0:00  0.17% oracle
 12711 oracle     1  48    0 3506M   16M sleep    0:00  0.11% oracle
 12738 oracle     1  43    0 3506M   16M sleep    0:00  0.06% oracle
  7606 oracle     1  45    0   17M 6928K sleep    0:07  0.05% tnslsnr
 12721 oracle     1  34    0 3506M   16M sleep    0:00  0.05% oracle
 12723 oracle     1  53    0 3506M   16M sleep    0:00  0.05% oracle

该系统调整完以后，一直稳定运行至今.

一点总结:

这个案例和前面我提到的另外一个极其相似
同样都是SGA设置不当引起的数据库问题

本身并不复杂
这一类问题应该在数据库规划和建设阶段就避免掉.

其时，该问题对我更像是个心理测试
当所有老板都站在你背后的时候，你能否冷静快速的找到并解决问题.

关于SUN上的aiowait timed out 有很多总情况及诱因
我后面还有相应的案例说明 .

-Eygle

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.


Oracle诊断案例-Spfile案例一则-eygle.com

Oracle诊断案例-Spfile案例一则

itpub link:

http://www.itpub.net/showthread.php?s=&threadid=211984

情况说明:
系统：SUN Solaris8
数据库版本:9203
问题描述：工程人员报告，数据库在重新启动时无法正常启动.检查发现UNDO表空间丢失.
问题诊断及解决过程如下:

1. 登陆系统检查alert.log文件

检查alert.log文件是通常是我们诊断数据库问题的第一步

SunOS 5.8

login: root
Password:
Last login: Thu Apr 1 11:39:16 from 10.123.7.162
Sun Microsystems Inc. SunOS 5.8 Generic Patch October 2001
You have new mail.
# su - oracle
bash-2.03$ cd $ORACLE_BASE/admin/*/bdump
bash-2.03$ vi *.log

"alert_gzhs.log" 7438 lines, 283262 characters
Sat Feb 7 20:30:06 2004
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
SCN scheme 3
Using log_archive_dest parameter default value
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up ORACLE RDBMS Version: 9.2.0.3.0.
System parameters with non-default values:
processes = 150
timed_statistics = TRUE
shared_pool_size = 1157627904
large_pool_size = 16777216
java_pool_size = 637534208
control_files = /u01/oradata/gzhs/control01.ctl,
/u02/oradata/gzhs/control02.ctl,
/u03/oradata/gzhs/control03.ctl
db_block_size = 8192
db_cache_size = 2516582400
compatible = 9.2.0.0.0
log_archive_start = TRUE
log_archive_dest_1 = LOCATION=/u06/oradata/gzhs/arch
log_archive_format = %t_%s.dbf
db_file_multiblock_read_count= 16
fast_start_mttr_target = 300
undo_management = AUTO
undo_tablespace = UNDOTBS1
undo_retention = 10800
remote_login_passwordfile= EXCLUSIVE
db_domain =
instance_name = gzhs
dispatchers = (PROTOCOL=TCP) (SERVICE=gzhsXDB)
job_queue_processes = 10
hash_join_enabled = TRUE
background_dump_dest = /oracle/admin/gzhs/bdump
user_dump_dest = /oracle/admin/gzhs/udump
core_dump_dest = /oracle/admin/gzhs/cdump
sort_area_size = 524288
db_name = gzhs
open_cursors = 300
star_transformation_enabled= FALSE
query_rewrite_enabled = FALSE
pga_aggregate_target = 838860800
aq_tm_processes = 1
PMON started with pid=2
DBW0 started with pid=3
LGWR started with pid=4
CKPT started with pid=5
SMON started with pid=6
"alert_gzhs.log" 7438 lines, 283262 characters
USER: terminating instance due to error 30012
Instance terminated by USER, pid = 26433
ORA-1092 signalled during: ALTER DATABASE OPEN...
Thu Apr 1 11:11:08 2004
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
SCN scheme 3
Using log_archive_dest parameter default value
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up ORACLE RDBMS Version: 9.2.0.3.0.
System parameters with non-default values:
processes = 150
timed_statistics = TRUE
shared_pool_size = 1157627904
large_pool_size = 16777216
java_pool_size = 637534208
control_files = /u01/oradata/gzhs/control01.ctl, /u02/oradata/gzhs/control02.ctl, /u03/oradata/gzhs/control03.ctl
db_block_size = 8192
db_cache_size = 2516582400
compatible = 9.2.0.0.0
log_archive_start = TRUE
log_archive_dest_1 = LOCATION=/u06/oradata/gzhs/arch
log_archive_format = %t_%s.dbf
db_file_multiblock_read_count= 16
fast_start_mttr_target = 300
undo_management = AUTO
undo_tablespace = UNDOTBS1
undo_retention = 10800
remote_login_passwordfile= EXCLUSIVE
db_domain =
instance_name = gzhs
dispatchers = (PROTOCOL=TCP) (SERVICE=gzhsXDB)
job_queue_processes = 10
hash_join_enabled = TRUE
background_dump_dest = /oracle/admin/gzhs/bdump
user_dump_dest = /oracle/admin/gzhs/udump
core_dump_dest = /oracle/admin/gzhs/cdump
sort_area_size = 524288
db_name = gzhs
open_cursors = 300
star_transformation_enabled= FALSE
query_rewrite_enabled = FALSE
pga_aggregate_target = 838860800
aq_tm_processes = 1
PMON started with pid=2
DBW0 started with pid=3
LGWR started with pid=4
CKPT started with pid=5
SMON started with pid=6
RECO started with pid=7
CJQ0 started with pid=8
Thu Apr 1 11:11:13 2004
starting up 1 shared server(s) ...
QMN0 started with pid=9
Thu Apr 1 11:11:13 2004
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
ARCH: STARTING ARCH PROCESSES
ARC0 started with pid=12
ARC0: Archival started
ARC1 started with pid=13
Thu Apr 1 11:11:13 2004
ARCH: STARTING ARCH PROCESSES COMPLETE
Thu Apr 1 11:11:13 2004
ARC0: Thread not mounted
Thu Apr 1 11:11:13 2004
ARC1: Archival started
ARC1: Thread not mounted
Thu Apr 1 11:11:14 2004
ALTER DATABASE MOUNT
Thu Apr 1 11:11:18 2004
Successful mount of redo thread 1, with mount id 1088380178.
Thu Apr 1 11:11:18 2004
Database mounted in Exclusive Mode.
Completed: ALTER DATABASE MOUNT
Thu Apr 1 11:11:27 2004
alter database open
Thu Apr 1 11:11:27 2004
Beginning crash recovery of 1 threads
Thu Apr 1 11:11:27 2004
Started first pass scan
Thu Apr 1 11:11:28 2004
Completed first pass scan
1 redo blocks read, 0 data blocks need recovery
Thu Apr 1 11:11:28 2004
Started recovery at
Thread 1: logseq 177, block 2, scn 0.33104793
Recovery of Online Redo Log: Thread 1 Group 3 Seq 177 Reading mem 0
Mem# 0 errs 0: /u01/oradata/gzhs/redo03.log
Thu Apr 1 11:11:28 2004
Completed redo application
Thu Apr 1 11:11:28 2004
Ended recovery at
Thread 1: logseq 177, block 3, scn 0.33124794
0 data blocks read, 0 data blocks written, 1 redo blocks read
Crash recovery completed successfully
Thu Apr 1 11:11:28 2004
LGWR: Primary database is in CLUSTER CONSISTENT mode
Thread 1 advanced to log sequence 178
Thread 1 opened at log sequence 178
Current log# 1 seq# 178 mem# 0: /u01/oradata/gzhs/redo01.log
Successful open of redo thread 1.
Thu Apr 1 11:11:28 2004
ARC0: Evaluating archive log 3 thread 1 sequence 177
Thu Apr 1 11:11:28 2004
ARC0: Beginning to archive log 3 thread 1 sequence 177
Creating archive destination LOG_ARCHIVE_DEST_1: '/u06/oradata/gzhs/arch/1_177.dbf'
Thu Apr 1 11:11:28 2004
SMON: enabling cache recovery
ARC0: Completed archiving log 3 thread 1 sequence 177
Thu Apr 1 11:11:28 2004
Errors in file /oracle/admin/gzhs/udump/gzhs_ora_27781.trc:
ORA-30012: \263\267\317\373\261\355\277\325\274\344 'UNDOTBS1' \262\273\264\346\324\332\273\362\300\340\320\315\262\273\325\375\310\
267
Thu Apr 1 11:11:28 2004
Error 30012 happened during db open, shutting down database
USER: terminating instance due to error 30012
Instance terminated by USER, pid = 27781
ORA-1092 signalled during: alter database open...
:q

.............

在警报日志末尾显示了数据库在Open状态因为错误而异常终止.

2. 尝试重新启动数据库

bash-2.03$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on 星期四 4月 1 11:43:52 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

已连接到空闲例程。

SQL> startup
ORACLE 例程已经启动。

Total System Global Area 4364148184 bytes
Fixed Size 736728 bytes
Variable Size 1845493760 bytes
Database Buffers 2516582400 bytes
Redo Buffers 1335296 bytes
数据库装载完毕。
ORA-01092: ORACLE 例程终止。强行断开连接

.............

工程人员报告的问题重现.

3. 检查数据文件

bash-2.03$ cd /u01/ oradata/gzhs
bash-2.03$ ls -l
total 55702458
-rw-r----- 1 oracle dba 1073750016 Apr 1 11:44 UNDOTBS2.dbf
-rw-r----- 1 oracle dba 1073750016 Apr 1 11:44 WAP12_BILLINGDETAIL.dbf
-rw-r----- 1 oracle dba 1073750016 Apr 1 11:44 WAP12_MAIN.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN10.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN11.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN2.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN3.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN4.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN5.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN6.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN7.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN8.dbf
-rw-r----- 1 oracle dba 2097160192 Apr 1 11:44 WAP12_MAIN9.dbf
-rw-r----- 1 oracle dba 1073750016 Apr 1 11:44 WAP12_MVIEW.dbf
-rw-r----- 1 oracle dba 1073750016 Mar 24 17:15 WAP12_TEMP1.dbf
.........................
.............

发现存在文件UNDOTBS2.dbf

4. mount数据库，检查系统参数

  bash-2.03$ sqlplus "/ as sysdba"

  SQL*Plus: Release 9.2.0.3.0 - Production on 星期四 4月 1 11:46:20 2004
  Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
  已连接到空闲例程。

  SQL>
  SQL>
  SQL> startup mount;

  ORACLE 例程已经启动。

  Total System Global Area 4364148184 bytes
  Fixed Size 736728 bytes
  Variable Size 1845493760 bytes
  Database Buffers 2516582400 bytes
  Redo Buffers 1335296 bytes
  数据库装载完毕。

  SQL> select name from v$datafile;
  NAME
  --------------------------------------------------------------------------------
  /u01/oradata/gzhs/system01.dbf
  /u01/oradata/gzhs/cwmlite01.dbf
  /u01/oradata/gzhs/drsys01.dbf
  /u01/oradata/gzhs/example01.dbf
  /u01/oradata/gzhs/indx01.dbf
  /u01/oradata/gzhs/odm01.dbf
  /u01/oradata/gzhs/tools01.dbf
  /u01/oradata/gzhs/users01.dbf
  /u01/oradata/gzhs/xdb01.dbf
  .........................
  /u01/oradata/gzhs/UNDOTBS2.dbf

  已选择23行。

  SQL>
  SQL> show parameter undo
  NAME TYPE VALUE

  ------------------------------------ ----------- ------------------------------
  undo_management string AUTO
  undo_retention integer 10800
  undo_suppress_errors boolean FALSE
  undo_tablespace string UNDOTBS1

  SQL> show parameter spfile

  NAME TYPE VALUE

  ------------------------------------ ----------- ------------------------------
  spfile string

.........................
.............

发现系统没有使用spfile,而初始化参数设置的undo表空间为UNDOTBS1

5. 检查参数文件

  bash-2.03$ cd $ORACLE_HOME/dbs
  bash-2.03$ ls

  init.ora initgzhs.ora initgzhs.ora.old orapwgzhs
  initdw.ora initgzhs.ora.hurray lkGZHS snapcf_gzhs.f
  bash-2.03$ vi initgzhs.ora

"initgzhs.ora" [Incomplete last line] 105 lines, 3087 characters

  ####################################################
  # Copyright (c) 1991, 2001, 2002 by Oracle Corporation
  ####################################################

  ###########################################
  # Archive
  ###########################################
  log_archive_dest_1='LOCATION=/u06/oradata/gzhs/arch'
  log_archive_format=%t_%s.dbf
  log_archive_start=true
  ###########################################
  # Cache and I/O
  ###########################################
  db_block_size=8192
  db_cache_size=2516582400
  db_file_multiblock_read_count=16
  ###########################################
  # Cursors and Library Cache
  ###########################################
  open_cursors=300
  ......................

   ###########################################
  # System Managed Undo and Rollback Segments
  ###########################################
  undo_management=AUTO
  undo_retention=10800
  undo_tablespace=UNDOTBS1

  :q!
.............

这个设置是极其可疑的.
怀疑参数文件和实际数据库设置不符.

6. 再次检查alert文件
查找对于UNDO表空间的操作

第一部分，创建数据库时的信息:

  Sat Feb 7 20:30:12 2004
  CREATE DATABASE gzhs
  MAXINSTANCES 1
  MAXLOGHISTORY 1
  MAXLOGFILES 5
  MAXLOGMEMBERS 3
  MAXDATAFILES 100
  DATAFILE '/u01/oradata/gzhs/system01.dbf' SIZE 500M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
  EXTENT MANAGEMENT LOCAL
  DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u01/oradata/gzhs/temp01.dbf' SIZE 1000M REUSE AUTOEXTEND
  ON NEXT 250M MAXSIZE UNLIMITED
  UNDO TABLESPACE "UNDOTBS1" DATAFILE '/u01/oradata/gzhs/undotbs01.dbf' SIZE 1000M REUSE AUTOEXTEND ON
NEXT 100M MAXSIZE UNLIMITED
  CHARACTER SET ZHS16GBK
  NATIONAL CHARACTER SET AL16UTF16
  LOGFILE GROUP 1 ('/u01/oradata/gzhs/redo01.log') SIZE 256M,
  GROUP 2 ('/u01/oradata/gzhs/redo02.log') SIZE 256M,
  GROUP 3 ('/u01/oradata/gzhs/redo03.log') SIZE 256M
.............

注意，这也是OCP教材上提到的两种创建UNDO表空间的方式之一

第二部分,发现创建UNDOTBS2的记录信息:

      Wed Mar 24 20:20:58 2004
      /* OracleOEM */ CREATE UNDO TABLESPACE "UNDOTBS2"
DATAFILE '/u01/oradata/gzhs/UNDOTBS2.dbf' SIZE 1024M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED
  Wed Mar 24 20:22:37 2004
  Created Undo Segment _SYSSMU11$
  Created Undo Segment _SYSSMU12$
  Created Undo Segment _SYSSMU13$
  Created Undo Segment _SYSSMU14$
  Created Undo Segment _SYSSMU15$
  Created Undo Segment _SYSSMU16$
  Created Undo Segment _SYSSMU17$
  Created Undo Segment _SYSSMU18$
  Created Undo Segment _SYSSMU19$
  Created Undo Segment _SYSSMU20$
  Completed: /* OracleOEM */ CREATE UNDO TABLESPACE "UNDOTBS2"
  Wed Mar 24 20:24:25 2004
  Undo Segment 11 Onlined
  Undo Segment 12 Onlined
  Undo Segment 13 Onlined
  Undo Segment 14 Onlined
  Undo Segment 15 Onlined
  Undo Segment 16 Onlined
  Undo Segment 17 Onlined
  Undo Segment 18 Onlined
  Undo Segment 19 Onlined
  Undo Segment 20 Onlined
  Successfully onlined Undo Tablespace 15.
  Undo Segment 1 Offlined
  Undo Segment 2 Offlined
  Undo Segment 3 Offlined
  Undo Segment 4 Offlined
  Undo Segment 5 Offlined
  Undo Segment 6 Offlined
  Undo Segment 7 Offlined
  Undo Segment 8 Offlined
  Undo Segment 9 Offlined
  Undo Segment 10 Offlined
  Undo Tablespace 1 successfully switched out.
.............

第三部分，新的UNDO表空间被应用

Wed Mar 24 20:24:25 2004
ALTER SYSTEM SET undo_tablespace='UNDOTBS2' SCOPE=MEMORY;

我们发现问题就在这里,创建了新的UNDO表空间以后，因为使用的是pfile文件，修改的只对当前实例生效，操作人员忘记了修改pfile文件.

如果使用spfile，缺省的修改范围是both,会同时修改spfile文件，就可以避免以上问题的出现.

第四部分，删除了UNDOTBS1的信息

Wed Mar 24 20:25:01 2004
  /* OracleOEM */ DROP TABLESPACE "UNDOTBS1" INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS
  Wed Mar 24 20:25:03 2004
  Deleted file /u01/oradata/gzhs/undotbs01.dbf
  Completed: /* OracleOEM */ DROP TABLESPACE "UNDOTBS1" INCLUDI
.............

这样再次重新启动数据库的时候，问题出现了，pfile中定义的UNDOTBS1找不到了，而且操作实在很久以前，没人能回忆起来，甚至无法得知是什么人的操作。

7. 更改pfile，启动数据库

修改undo表空间

###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_retention=10800
undo_tablespace=UNDOTBS2

....

bash-2.03$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on 星期四 4月 1 11:55:11 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
PL/SQL Release 9.2.0.3.0 - Production
CORE 9.2.0.3.0 Production
TNS for Solaris: Version 9.2.0.3.0 - Production
NLSRTL Version 9.2.0.3.0 - Production

SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production中断开
bash-2.03$

在这里我们可以看到，使用spfile可以免去手工修改pfile文件的麻烦，减少了犯错的可能。

既然Oracle9i给我们提供了这个新特性，就值得我们学习使用它.

2004年6月26日 星期六 23:15

If you have any question,please mail to eygle@itpub.net .


如何诊断和解决CPU高度消耗(100%)的数据库问题-www.eygle.com

如何诊断和解决CPU高度消耗(100%)的数据库问题

Last updated: Thursday, 2004-10-07 15:52 Eygle

很多时候我们的服务器可能会经历CPU消耗100%的性能问题.
排除系统的异常，这类问题通常都是因为系统中存在性能低下甚至存在错误的SQL语句, 消耗了大量的CPU所致.

本文通过一个案例就如何捕获这样的SQL给出一个通用的方法.

问题描述:系统CPU高度消耗,系统运行缓慢
OS:Sun Solaris8
Oracle:Oracle9203

1.首先通过Top命令查看

$ top

load averages:  1.61,  1.28,  1.25                     HSWAPJSDB             10:50:44
172 processes: 160 sleeping, 1 running, 3 zombie, 6 stopped, 2 on cpu
CPU states:     % idle,     % user,     % kernel,     % iowait,     % swap
Memory: 4.0G real, 1.4G free, 1.9G swap in use, 8.9G swap free

   PID USERNAME THR PR NCE  SIZE   RES STATE   TIME FLTS    CPU COMMAND
 20521 oracle     1 40   0  1.8G  1.7G run     6:37    0 47.77% oracle
 20845 oracle     1 40   0  1.8G  1.7G cpu02   0:41    0 40.98% oracle
 20847 oracle     1 58   0  1.8G  1.7G sleep   0:00    0  0.84% oracle
 20780 oracle     1 48   0  1.8G  1.7G sleep   0:02    0  0.83% oracle
 15828 oracle     1 58   0  1.8G  1.7G sleep   0:58    0  0.53% oracle
 20867 root       1 58   0 4384K 2560K sleep   0:00    0  0.29% sshd2
 20493 oracle     1 58   0  1.8G  1.7G sleep   0:03    0  0.29% oracle
 20887 oracle     1 48   0  1.8G  1.7G sleep   0:00    0  0.13% oracle
 20851 oracle     1 58   0  1.8G  1.7G sleep   0:00    0  0.10% oracle
 20483 oracle     1 48   0  1.8G  1.7G sleep   0:00    0  0.09% oracle
 20875 oracle     1 45   0 1064K  896K sleep   0:00    0  0.07% sh
 20794 oracle     1 58   0  1.8G  1.7G sleep   0:00    0  0.06% oracle
 20842 jiankong   1 52   2 1224K  896K sleep   0:00    0  0.05% sadc
 20888 oracle     1 55   0 1712K 1272K cpu00   0:00    0  0.05% top
 19954 oracle     1 58   0  1.8G  1.7G sleep  84:25    0  0.04% oracle

我们发现在进城列表里，存在两个高CPU耗用的Oracle进城，分别消耗了47.77%和40.98%的CPU资源.

2.找到存在问题的进程信息

$ ps -ef|grep 20521
  oracle 20909 20875  0 10:50:53 pts/10   0:00 grep 20521
  oracle 20521     1 47 10:43:59 ?        6:45 oraclejshs (LOCAL=NO)
$ ps -ef|grep 20845
  oracle 20845     1 44 10:50:00 ?        0:55 oraclejshs (LOCAL=NO)
  oracle 20918 20875  0 10:50:59 pts/10   0:00 grep 20845

确认这是两个远程连接的用户进程.

3.熟悉一下我的getsql.sql脚本

SELECT   /*+ ORDERED */
         sql_text
    FROM v$sqltext a
   WHERE (a.hash_value, a.address) IN (
            SELECT DECODE (sql_hash_value,
                           0, prev_hash_value,
                           sql_hash_value
                          ),
                   DECODE (sql_hash_value, 0, prev_sql_addr, sql_address)
              FROM v$session b
             WHERE b.paddr = (SELECT addr
                                FROM v$process c
                               WHERE c.spid = '&pid'))
ORDER BY piece ASC
/

注意这里我们涉及了3个视图,并应用其关联进行数据获取.
首先需要输入一个pid,这个pid即process id,也就是在Top或ps中我们看到的PID.
通过pid和v$process.spid相关联我们可以获得Process的相关信息
进而通过v$process.addr和v$session.paddr相关联,我们就可以获得和session相关的所有信息.
再结合v$sqltext,我们即可获得当前session正在执行的SQL语句.

通过v$process视图，我们得以把操作系统和数据库关联了起来.

4.连接数据库,找到问题sql及进程

通过Top中我们观察到的PID,进而应用我的getsql脚本,我们得到以下结果输出.

$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Mon Dec 29 10:52:14 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> @getsql
Enter value for spid: 20521
old  10: where c.spid = '&pid'
new  10: where c.spid = '20521'

SQL_TEXT
----------------------------------------------------------------
select * from (select VC2URL,VC2PVDID,VC2MOBILE,VC2ENCRYPTFLAG,S
ERVICEID,VC2SUB_TYPE,CISORDER,NUMGUID,VC2KEY1, VC2NEEDDISORDER,V
C2PACKFLAG,datopertime from hsv_2cpsync where datopertime<=sysda
te and numguid>70000000000308 order by NUMGUid) where rownum<=20

那么这段代码就是当前正在疯狂消耗CPU的罪魁祸首.
接下来需要进行的工作就是找出这段代码的问题，看是否可以通过优化提高其效率，减少资源消耗.

5.进一步的我们可以通过dbms_system包跟踪该进程

SQL> @getsid
Enter value for spid: 20521
old 3: select addr from v$process where spid = &spid)
new 3: select addr from v$process where spid = 20521)

SID SERIAL# USERNAME MACHINE
----------------------------------------------------------------
45 38991 HSUSER_V51 hswapjsptl1.hurray.com.cn

SQL> exec dbms_system.set_sql_trace_in_session(45,38991,true);

PL/SQL procedure successfully completed.

SQL> !

这部分内容可以参考:
http://www.eygle.com/case/sql_trace_1.htm

对于Windows上的类似问题,可以参考:
http://www.eygle.com/faq/Use.Nt.tools.manage.Oracle.htm

6.一点说明

很多时候，高CPU消耗都是由于问题SQL导致的,所以找到这些SQL通常也就找到了问题所在，通过优化调整
通常就可以解决问题。

但是有时候你可能会发现，这些最消耗CPU的进程是后台进程，这一般是由于异常、BUG或者恢复后的异常
导致的，需要具体问题具体分析了.

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.


关于shared pool的深入探讨(六)-www.eygle.com

关于shared pool的深入探讨(六)

Monday, 2004-09-13 12:04 Eygle

研究了几天shared pool,没想到忽然就撞到问题上来了.
作为一个案例写出来给大家参考一下吧.

问题起因是公司做短信群发,就是那个18万买的4000字的短信小说(嘘,小声点,我也没看过...).
群发的时候每隔一段时间就会发生一次消息队列拥堵的情况
在数据库内部实际上是向一个数据表中记录发送日志.

我们介入来检查数据库的问题,在一个拥堵时段我开始诊断:

SQL> select sid,event,p1,p1raw from v$session_wait;

       SID EVENT                                                                    P1 P1RAW
---------- ---------------------------------------------------------------- ---------- --------
        76 latch free                                                       2147535824 8000CBD0
        83 latch free                                                       2147535824 8000CBD0
       148 latch free                                                       3415346832 CB920E90
       288 latch free                                                       2147535824 8000CBD0
       285 latch free                                                       2147535824 8000CBD0
       196 latch free                                                       2147535824 8000CBD0
       317 latch free                                                       2147535824 8000CBD0
         2 pmon timer                                                              300 0000012C
         1 rdbms ipc message                                                       300 0000012C
         4 rdbms ipc message                                                       300 0000012C
         6 rdbms ipc message                                                    180000 0002BF20

       SID EVENT                                                                    P1 P1RAW
---------- ---------------------------------------------------------------- ---------- --------
        18 rdbms ipc message                                                      6000 00001770
       102 rdbms ipc message                                                      6000 00001770
       311 rdbms ipc message                                                      6000 00001770
       194 rdbms ipc message                                                      6000 00001770
       178 rdbms ipc message                                                      6000 00001770
         3 log file parallel write                                                   1 00000001
        13 log file sync                                                          2705 00000A91
        16 log file sync                                                          2699 00000A8B
       104 log file sync                                                          2699 00000A8B
       308 log file sync                                                          2694 00000A86
       262 log file sync                                                          2705 00000A91

       SID EVENT                                                                    P1 P1RAW
---------- ---------------------------------------------------------------- ---------- --------
       172 log file sync                                                          2689 00000A81
       169 log file sync                                                          2705 00000A91
       108 log file sync                                                          2694 00000A86
        38 log file sync                                                          2707 00000A93
        34 db file scattered read                                                   63 0000003F
         5 smon timer                                                              300 0000012C
        27 SQL*Net message to client                                        1413697536 54435000
        60 SQL*Net message to client                                        1413697536 54435000
       239 SQL*Net message to client                                        1413697536 54435000
...ignore some idle waiting here...
        11 SQL*Net message from client                                       675562835 28444553
        12 SQL*Net message from client                                      1413697536 54435000

170 rows selected.

在这次查询中,我发现大量的latch free等待,再次查询时这些等待消失,应用也恢复了正常.

SQL> select sid,event,p1,p1raw from v$session_wait where event not like 'SQL*Net%';

       SID EVENT                                                                    P1 P1RAW
---------- ---------------------------------------------------------------- ---------- --------
         2 pmon timer                                                              300 0000012C
         1 rdbms ipc message                                                       300 0000012C
         4 rdbms ipc message                                                       300 0000012C
         6 rdbms ipc message                                                    180000 0002BF20
        18 rdbms ipc message                                                      6000 00001770
       102 rdbms ipc message                                                      6000 00001770
       178 rdbms ipc message                                                      6000 00001770
       194 rdbms ipc message                                                      6000 00001770
       311 rdbms ipc message                                                      6000 00001770
         3 log file parallel write                                                   1 00000001
       148 log file sync                                                          2547 000009F3

       SID EVENT                                                                    P1 P1RAW
---------- ---------------------------------------------------------------- ---------- --------
       273 log file sync                                                          2544 000009F0
       190 log file sync                                                          2545 000009F1
         5 smon timer                                                              300 0000012C

14 rows selected.

接下来我们来看这些latch free等待的是哪些latch

SQL> select addr,latch#,name,gets,spin_gets from v$latch order by spin_gets;

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
80001398          3 session switching                                                    111937          0
80002010          6 longop free list                                                      37214          0
800023A0          7 cached attr list                                                          0          0
80002628         10 event group latch                                                   2391668          0
.....
80003F3C         28 message pool operations parent latch                                      3          0
.....
80006030         60 mostly latch-free SCN                                                    19          0
80005F8C         59 file number translation table                                            68          0
80005F14         58 dlm cr bast queue latch                                                   0          0
80005E8C         57 name-service request                                                      0          0
80005E14         56 name-service memory objects                                               0          0
80005DA0         55 name-service namespace bucket                                             0          0

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
80005D2C         54 name-service pending queue                                                0          0
80005CB4         53 name-service request queue                                                0          0
80004E08         52 name-service entry                                                        0          0
80008AB0         76 KCL lock element parent latch                                             0          0
80008A48         75 KCL instance latch                                                        0          0
80007F18         73 redo copy                                                               816          0
80007BBC         71 archive process latch                                                     0          0
80007B54         70 archive control                                                           1          0
80006A10         68 Active checkpoint queue latch                                       2003308          0
800064B0         66 large memory latch                                                        0          0
80006448         65 cache protection latch                                                    0          0

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
800060EC         61 batching SCNs                                                             0          0
8000CAB0         96 global transaction                                                  6833807          0
8000CA48         95 global tx free list                                                   58258          0
8000C238         93 cost function                                                             0          0
80009FCC         91 temp lob duration state obj allocation                                    0          0
8000995C         87 ktm global data                                                        8118          0
80009228         84 transaction branch allocation                                        282388          0
80008EC4         80 begin backup scn array                                                 6968          0
80008D54         79 loader state object freelist                                          42712          0
80008B80         78 KCL freelist latch                                                        0          0
80008B18         77 KCL name table latch                                                      0          0

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
8000D484        118 presentation list                                                         0          0
8000D41C        117 session timer                                                        855944          0
.....
8000E9D0        129 process queue                                                            44          0
8000E900        127 query server freelists                                                   66          0
8000FC84        140 AQ Propagation Scheduling System Load                                     0          0
8000E898        126 query server process                                                     10          0
8000E27C        125 job_queue_processes parameter latch                                  111937          0
8000DA1C        124 NLS data objects                                                          2          0

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
8000D95C        123 ncodef allocation latch                                              111937          0
8000D674        122 virtual circuits                                                          0          0
8000D60C        121 virtual circuit queues                                               159877          0
8000D5A4        120 virtual circuit buffers                                                   0          0
8000D4EC        119 address list                                                              2          0
.....
8000CD70        102 Direct I/O Adaptor                                                        2          0
.....
80002408          8 GDS latch                                                                30          0
800092E4         85 sort extent pool                                                      69834          1
8000EC38        132 parallel query alloc buffer                                              80          1
8000E968        128 error message lists                                                      22          1
80001400          4 process group creation                                              2615542          2
8000EAA0        131 parallel query stats                                                     14          2

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
8000CD08        101 Token Manager                                                       1151107          2
8000CB18         97 global tx hash mapping                                               507846          2
80006378         63 cache buffer handles                                                 315924          4
8000EA38        130 process queue reference                                              190993          5
80003E3C         26 channel handle pool latch                                           2391680         18
80003EAC         27 channel operations parent latch                                     4783425         24
80009B90         89 intra txn parallel recovery                                           32654         33
8000FCF8        141 fixed table rows for x$hs_session                                    161368         41
800012C8          1 process allocation                                                  2391688        154
80009B28         88 parallel txn reco latch                                              174519        271
8000CCA0        100 library cache load lock                                            14947545       5958

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
8000C8D0         94 user lock                                                          13086412       6078
8000914C         82 list of block allocation                                          120650357      12024
80006A78         69 Checkpoint queue latch                                            154361751      17686
80009D34         90 sequence cache                                                     64611720      32027
80009090         81 dml lock allocation                                               234465024      45351
800091C0         83 transaction allocation                                            214227648      48345
800096AC         86 undo global data                                                  188271244      49641
800028A0         13 enqueue hash chains                                               373244264     131322
80007E04         72 redo allocation                                                   439389808     201498
80001468          5 session idle bit                                                 2039097976     204969
80002838         12 enqueues                                                          471338482     273695

ADDR         LATCH# NAME                                                                   GETS  SPIN_GETS
-------- ---------- ---------------------------------------------------------------- ---------- ----------
80001330          2 session allocation                                                261826230     428312
800063E0         64 multiblock read objects                                          1380614923    1366278
800026B8         11 messages                                                          207935758    1372606
80001218          0 latch wait list                                                   203479569    1445342
80006310         62 cache buffers chains                                             3.8472E+10    2521699
8000A17C         92 row cache objects                                                1257586714    2555872
80007F80         74 redo writing                                                      264722932    4458044
80006700         67 cache buffers lru chain                                          5664313769   30046921
8000CBD0         98 shared pool                                                       122433688   59070585
8000CC38         99 library cache                                                    4414533796 1037032730

142 rows selected.

SQL> select startup_time from v$instance;

STARTUP_T
---------
13-AUG-04

检查数据库启动时间

我们注意到,在当前数据库中竞争最严重的两个latch是shared pool和library cache.
显然这极有可能是SQL的过度解析造成的.

进一步我们检查v$sqlarea发现:

SQL> select sql_text,VERSION_COUNT,INVALIDATIONS,PARSE_CALLS,OPTIMIZER_MODE,PARSING_USER_ID,PARSING_SCHEMA_ID,ADDRESS,HASH_VALUE
from v$sqlarea where version_count >1000;
  2

SQL_TEXT
------------------------------------------------------------------------------------------------------------------------
VERSION_COUNT INVALIDATIONS PARSE_CALLS OPTIMIZER_MODE            PARSING_USER_ID PARSING_SCHEMA_ID ADDRESS  HASH_VALUE
------------- ------------- ----------- ------------------------- --------------- ----------------- -------- ----------
insert into sms_log (MSGDATE,MSGTIME,MSGID,MSGKIND,MSGTYPE,MSGTYPE_MOMT,MSGLEN,MSGSTATUS,AREAID,IFIDDEST,IFIDSRC,ADDRSRC
,ADDRDEST,ADDRFEE,ADDRUSER,SERVICECODE,PLANID,FEETYPE,FEEVALUE,DATACODING,FLAGS,SMLEN,SMCONT) values (:b0,:b1,:b2,:b3,:b
4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12,:b13,:b14,:b15,:b16,:b17,:b18,:b19,:b20,:b21,:b22)
         7023             0        1596 MULTIPLE CHILDREN PRESENT              36                36 C82AF1C8 3974744754

这就是写日志记录的代码,这段代码使用了绑定变量,但是version_count却有7023个.
也就是这个sql有7023个子指针.这是不可想象的.

通过前面几节的研究我们知道,如果这个sql有7023个子指针
那么意味着这些子指针都将存在于同一个Bucket的链表上
那么这也就意味着,如果同样SQL再次执行,Oracle将不得不搜索这个链表以寻找可以共享的SQL.
这将导致大量的library cache latch的竞争.

这时候我开始猜测原因:
1.可能代码存在问题,在每次执行之前程序修改某些session参数,导致sql不能共性
2.可能是8.1.5的v$sqlarea记录存在问题,我们看到的结果是假象:)
3.Bug

Ok,我们的诊断不能停.
最直接的我dump内存来看:

SQL> ALTER SESSION SET EVENTS 'immediate trace name LIBRARY_CACHE level 4';

察看trace文件得到如下结果(摘录包含该段代码的片断):

BUCKET 21049:
  LIBRARY OBJECT HANDLE: handle=c82af1c8
  name=
insert into sms_log (MSGDATE,MSGTIME,MSGID,MSGKIND,MSGTYPE,MSGTYPE_MOMT,MSGLEN,MSGSTATUS,AREAID,IFIDDEST,IFIDSRC,
ADDRSRC,ADDRDEST,ADDRFEE,ADDRUSER,SERVICECODE,PLANID,FEETYPE,FEEVALUE,DATACODING,FLAGS,SMLEN,SMCONT) values
(:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12,:b13,:b14,:b15,:b16,:b17,:b18,:b19,:b20,:b21,:b22)
  hash=ece9cab2 timestamp=09-09-2004 12:51:29
  namespace=CRSR flags=RON/TIM/PN0/LRG/[10010001]
  kkkk-dddd-llll=0000-0001-0001 lock=N pin=S latch=5
  lwt=c82af1e0[c82af1e0,c82af1e0] ltm=c82af1e8[c82af1e8,c82af1e8]
  pwt=c82af1f8[c82af1f8,c82af1f8] ptm=c82af250[c82af250,c82af250]
  ref=c82af1d0[c82af1d0,c82af1d0]
    LIBRARY OBJECT: object=c1588e84
    type=CRSR flags=EXS[0001] pflags= [00] status=VALD load=0
    CHILDREN: size=7024
    child#    table reference   handle
    ------ -------- --------- --------
         0 c1589040  c1589008 c668c2bc
         1 c1589040  bfd179c4 c6ec9ee8
         2 c1589040  bfd179e0 c2dd9b3c
         3 c1589040  bfd179fc c5a46614
         4 c1589040  bfd17a18 c35f1388
         5 c1589040  bfd17a34 c77401bc
         6 c1589040  bfd17a50 c4092838
         7 c1589040  bfddb310 c6cd5258
         8 c1589040  bfddb32c c63c6650
         9 c1589040  bfddb348 c7e4e3d0
        10 c1589040  bfddb364 c4c4b110
        11 c1589040  bfddb380 c5950348
        12 c1589040  bfddb39c c6c33aa4
        13 c1589040  bfddb3b8 c672b0bc
...........................................
.....ignore losts of child cursor here.....
...........................................
      7001 bf595bc8  c641fba0 c6467890
      7002 bf595bc8  c641fbbc c3417168
      7003 bf595bc8  c641fbd8 c3417bb0
      7004 bf595bc8  c641fbf4 c2fdccbc
      7005 bf595bc8  c641fc10 c7f7ca50
      7006 bf595bc8  c641fc2c c7f508ec
      7007 bf595bc8  c641fc48 c268d8d8
      7008 c641fcb8  c641fc64 bec61ed8
      7009 c641fcb8  c641fc80 c4a6cc5c
      7010 c641fcb8  c641fc9c c1a8aa34
      7011 c641fcb8  c0ae4ea0 c0ae4ddc
      7012 c641fcb8  c0ae4ebc bd55fe60
      7013 c641fcb8  c0ae4ed8 c226914c
      7014 c641fcb8  c0ae4ef4 c51dd2e0
      7015 c641fcb8  c0ae4f10 c480c468
      7016 c641fcb8  c0ae4f2c c60196d0
      7017 c641fcb8  c0ae4f48 c4675d2c
      7018 c641fcb8  c0ae4f64 bd5e2750
      7019 c641fcb8  c0ae4f80 c09b1bb0
      7020 c641fcb8  c0ae4f9c bf2d6044
      7021 c641fcb8  c0ae4fb8 c332c1c4
      7022 c641fcb8  c0ae4fd4 cbdde0f8
    DATA BLOCKS:
    data#     heap  pointer status pins change
    ----- -------- -------- ------ ---- ------
        0 c3ef2c50 c1588f08 I/P/A     0 NONE

这里确实存在7023个子指针

查询v$sql得到相同的结果:

SQL> select CHILD_NUMBER,EXECUTIONS,OPTIMIZER_MODE,OPTIMIZER_COST,PARSING_USER_ID,PARSING_SCHEMA_ID,ADDRESS,HASH_VALUE
   2 from v$sql where HASH_VALUE='3974744754';

CHILD_NUMBER EXECUTIONS OPTIMIZER_ OPTIMIZER_COST PARSING_USER_ID PARSING_SCHEMA_ID ADDRESS  HASH_VALUE
------------ ---------- ---------- -------------- --------------- ----------------- -------- ----------
           0      12966 CHOOSE             238150              36                36 C82AF1C8 3974744754
           1       7111 CHOOSE             238150              36                36 C82AF1C8 3974744754
           2       9160 CHOOSE             238150              36                36 C82AF1C8 3974744754
           3       9127 CHOOSE             238150              36                36 C82AF1C8 3974744754
           4       8109 CHOOSE             238150              36                36 C82AF1C8 3974744754
           5       4386 CHOOSE             238150              36                36 C82AF1C8 3974744754
           6       4913 CHOOSE             238150              36                36 C82AF1C8 3974744754
           7       3764 CHOOSE             238150              36                36 C82AF1C8 3974744754
           8       3287 CHOOSE             238150              36                36 C82AF1C8 3974744754
           9       3156 CHOOSE             238150              36                36 C82AF1C8 3974744754
.....
        7015          1 CHOOSE             238150              36                36 C82AF1C8 3974744754
        7016          1 CHOOSE             238150              36                36 C82AF1C8 3974744754
        7017          0 CHOOSE             238150              36                36 C82AF1C8 3974744754

CHILD_NUMBER EXECUTIONS OPTIMIZER_ OPTIMIZER_COST PARSING_USER_ID PARSING_SCHEMA_ID ADDRESS  HASH_VALUE
------------ ---------- ---------- -------------- --------------- ----------------- -------- ----------
        7018       9396 NONE                                    0                 0 C82AF1C8 3974744754
        7019       5008 CHOOSE             237913              36                36 C82AF1C8 3974744754
        7020        625 CHOOSE             237913              36                36 C82AF1C8 3974744754
        7021      10101 CHOOSE             237913              36                36 C82AF1C8 3974744754
        7022       7859 CHOOSE             237913              36                36 C82AF1C8 3974744754

7023 rows selected.

这里确实存在7023个子指针,第二种猜测被否定了,同时研发发过来的代码也不存在第一种情况.
那么只能是第三种情况了,Oracle的Bug,Ok,那我们需要找到解决办法.

搜索Metalink,发现Bug:1210242
该Bug描述为:
On certain SQL statements cursors are not shared when TIMED_STATISTICS is enabled.

碰巧我这个数据库的TIMED_STATISTICS设置为True
修改TIMED_STATISTICS为False以后,观察v$sql,发现有效子指针很快下降到2个.

SQL> select CHILD_NUMBER,OPTIMIZER_COST,OPTIMIZER_MODE,EXECUTIONS,ADDRESS from v$sql where hash_value=3974744754 and OPTIMIZER_MODE='CHOOSE';

CHILD_NUMBER OPTIMIZER_COST OPTIMIZER_ EXECUTIONS ADDRESS
------------ -------------- ---------- ---------- --------
           0         238167 CHOOSE          63943 C82AF1C8
           1         238300 CHOOSE          28915 C82AF1C8

第二天下降到只有一个.

SQL> select CHILD_NUMBER,OPTIMIZER_COST,OPTIMIZER_MODE,EXECUTIONS,ADDRESS from v$sql where hash_value=3974744754 and OPTIMIZER_MODE='CHOOSE';

CHILD_NUMBER OPTIMIZER_COST OPTIMIZER_ EXECUTIONS ADDRESS
------------ -------------- ---------- ---------- --------
           0         238702 CHOOSE         578124 C82AF1C8

短信群发从此正常.

对于这个问题,另外一个可选的方法是设置一个隐含参数:
_sqlexec_progression_cost = 0

这个参数的具体含义为:
SQL execution progression monitoring cost threshold
即:SQL执行进度监控成本阀值

这个参数根据COST来决定需要监控的SQL.执行进度监控会引入额外的函数调用和Row Sources
这可能导致SQL的执行计划或成本发生改变,从而产生不同的子指针.
_sqlexec_progression_cost 的缺省值为1000,成本大于1000的所有SQL都会被监控
如果该参数设置为0,那么SQL的执行进度将不会被跟踪.

执行进度监控信息会被记录到V$SESSION_LONGOPS视图中,如果Time_statistics参数设置为False,那么这个信息就不会被记录.

所以,Time_statistics参数和_sqlexec_progression_cost是解决问题的两个途径.

通过查询我们也可以看到,在这个数据库中,OPTIMIZER_COST >1000的SQL主要有以下五个:

SQL> select distinct(sql_text) from v$sql where OPTIMIZER_COST >1000;

SQL_TEXT
--------------------------------------------------------------------------------
insert into sms_detail_error (msgdate,addruser,msgid,areaid,reason,spnumber,msgt
ime,ifiddest,msqkey,servicecode,planid,feetype,feevalue,smcont,submittimes,submi
tdate,submittime,msgstate_resp,errorcode_resp,msgstate_rept,errorcode_rept) valu
es (:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12,:b13,:b14,:b15,:b16,:
b17,:b18,:b19,:b20)

insert into sms_detail_success (msgdate,addruser,msgid,areaid,spnumber,msgtime,i
fiddest,servicecode,planid,feetype,feevalue,smcont,submittimes,submitdate,submit
time,respdate,resptime,reptdate,repttime,msqkey) values (:b0,:b1,:b2,:b3,:b4,:b5
,:b6,:b7,:b8,:b9,:b10,:b11,:b12,:b13,:b14,:b15,:b16,:b17,:b18,:b19)

insert into sms_log (MSGDATE,MSGTIME,MSGID,MSGKIND,MSGTYPE,MSGTYPE_MOMT,MSGLEN,M
SGSTATUS,AREAID,IFIDDEST,IFIDSRC,ADDRSRC,ADDRDEST,ADDRFEE,ADDRUSER,SERVICECODE,P
LANID,FEETYPE,FEEVALUE,DATACODING,FLAGS,SMLEN,SMCONT) values (:b0,:b1,:b2,:b3,:b
4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12,:b13,:b14,:b15,:b16,:b17,:b18,:b19,:b20,:b2
1,:b22)

insert into sms_resprept_error (msgdate,areaid,addruser,msgid,submittimes,submit
date,submittime,msgid_gw,msgstate_resp,errorcode_resp,msgstate_rept,errorcode_re
pt,servicecode) values (:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12)

insert into sms_statusrept (reptdate,addruser,msgid_gw,repttime,statustype,msgid
_stus,msgstate,errorcode) values (:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7)

而这五个SQL中,在v$sqlarea中,有四个version_count都在10以上:

SQL>  select sql_text,version_count from v$sqlarea where version_count>10;

SQL_TEXT
--------------------------------------------------------------------------------
VERSION_COUNT
-------------
insert into sms_detail_error (msgdate,addruser,msgid,areaid,reason,spnumber,msgt
ime,ifiddest,msqkey,servicecode,planid,feetype,feevalue,smcont,submittimes,submi
tdate,submittime,msgstate_resp,errorcode_resp,msgstate_rept,errorcode_rept) valu
es (:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12,:b13,:b14,:b15,:b16,:
b17,:b18,:b19,:b20)
           42

insert into sms_log (MSGDATE,MSGTIME,MSGID,MSGKIND,MSGTYPE,MSGTYPE_MOMT,MSGLEN,M
SGSTATUS,AREAID,IFIDDEST,IFIDSRC,ADDRSRC,ADDRDEST,ADDRFEE,ADDRUSER,SERVICECODE,P
LANID,FEETYPE,FEEVALUE,DATACODING,FLAGS,SMLEN,SMCONT) values (:b0,:b1,:b2,:b3,:b
4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12,:b13,:b14,:b15,:b16,:b17,:b18,:b19,:b20,:b2
1,:b22)
         7026

insert into sms_resprept_error (msgdate,areaid,addruser,msgid,submittimes,submit
date,submittime,msgid_gw,msgstate_resp,errorcode_resp,msgstate_rept,errorcode_re
pt,servicecode) values (:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7,:b8,:b9,:b10,:b11,:b12)
          301

insert into sms_statusrept (reptdate,addruser,msgid_gw,repttime,statustype,msgid
_stus,msgstate,errorcode) values (:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7)
           41

具体可以参考Metalink: Note 62143

至此这个关于shared pool的问题找到了原因,并得以及时解决.


字符集问题的初步探讨(一)-www.eygle.com

字符集问题的初步探讨(一)

--字符集的基本知识

Saturday, 2004-09-11 11:58 Eygle

原文发表于itpub技术丛书《Oracle数据库DBA专题技术精粹》,未经许可,严禁转载本文.

Oracle全球支持(即Globalization Support)允许我们使用本地语言和格式来存储和检索数据。通过全球支持，Oracle可以支持多种语言及字符集，得以展示数据库的强大魅力。

由于不同语言及字符集的共同存储存在设置上具有一定的复杂性，字符集一度成为普遍困扰大家的一个主要问题。
本文试图就一些常见问题进行探讨，希望可以把一些实际经验共享给大家！

1． 字符集的基本知识

如果从头说起，字符集最早的编码方案来自于与ASCII.
这也是我们最常见的编码方式。该方案起源于1960年代初期，最初是美国国会图书馆制定用来作为美国图书馆界书目交换的共同标准，最后完善成为美国的国家标准ASCII（American Standard Codefor Information Interchange），之后进一步演变成世界性的计算机字符编码标准ISO646（其全名为7-bit coded character set for information interchange）。成为计算机编码方案的基础。

Oracle数据库最早支持的编码方案也就是US7ASCII.
但是我们知道，英文字符一般是以一个字节来存储的，7位的编码方案最多只能代表128个字符；经过扩展的8位的编码方案也只能代表256个字符，这远远不能满足计算机发展的需要，对于亚洲国家复杂的字符存储需要更多的码位，于是各种编码方案随之而生。

为了容纳全世界各种语言的所有字符和符号，解决不同编码之间的兼容和转换问题，1991年元月，10多家公司共同出资，组建Unicode协会,随后Unicode编码产生了。
Unicode协会的口号是: 给每个字符提供了一个唯一的数字，不论是什么平台，不论是什么程序，不论什么语言。
最初Unicode编码使用2-Byte(16bit)来进行编码，但是最多只能容纳65536个字符，仍然不够使用，后来进行了扩充，也就是Unicode3.1标准，增加了额外的补充字符定义，现在Unicode4.0标准已经发布，具体可以参考Unicode官方站点:

http://www.unicode.org/

Unicode编码方案主要有三个实施标准:
UTF-8
USC-2
UTF-16
Oracle从7.2开始支持UTF-8编码，提供Unicode编码支持。

按照各种标准的含义，Oracle推荐，如果你的数据库需要存放不同语言的不同符号和字符，建议使用Unicode编码方案。诚然，Unicode方案可以表示更多的字符，但是由于多位的存储，需要额外的存储空间和网络传输，所以选择最适合的数据库字符集仍然需要慎重考虑。


字符集问题的初步探讨(二)-www.eygle.com

字符集问题的初步探讨(二)

--数据库的字符集

Saturday, 2004-09-11 11:38 Eygle

原文发表于itpub技术丛书《Oracle数据库DBA专题技术精粹》,未经许可,严禁转载本文.

2． 数据库的字符集

字符集在创建数据库时指定，在创建后通常不能更改，所以在创建数据库时能否选择一个正确的字符集就显得尤为重要。

在创建数据库时，我们可以指定字符集(CHARACTER SET)和国家字符集(NATIONAL CHARACTER SET)。
字符集用来存储:
CHAR, VARCHAR2, CLOB, LONG等类型数据
用来标示诸如表名、列名以及PL/SQL变量等
SQL和PL/SQL程序单元等
国家字符集用以存储:
NCHAR, NVARCHAR2, NCLOB等类型数据

这些设置在数据库创建时指定，我们可以看一下数据库的创建脚本:

connect SYS/change_on_install as SYSDBA
set echo on
spool E:\oracle\ora92\assistants\dbca\logs\CreateDB.log
startup nomount pfile="E:\oracle\admin\eygle\scripts\init.ora";
CREATE DATABASE eygle
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 3
MAXDATAFILES 100
DATAFILE 'E:\oracle\oradata\eygle\system01.dbf' SIZE 250M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE 'E:\oracle\oradata\eygle\temp01.dbf' SIZE 40M REUSE AUTOEXTEND
ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE "UNDOTBS1" DATAFILE 'E:\oracle\oradata\eygle\undotbs01.dbf' SIZE 50M REUSE AUTOEXTEND
ON NEXT 5120K MAXSIZE UNLIMITED
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
LOGFILE GROUP 1 ('E:\oracle\oradata\eygle\redo01.log') SIZE 10M,
GROUP 2 ('E:\oracle\oradata\eygle\redo02.log') SIZE 10M,
GROUP 3 ('E:\oracle\oradata\eygle\redo03.log') SIZE 10M;
spool off
exit;

以上用粗体显示的就是对我们至关重要的字符集设置。

在创建数据库的过程中，在以下界面选择你的字符集，对于简体中文平台，缺省的字符集是:ZHS16GBK

一旦你的字符集选定了，数据库中能够存储的字符就受到了限制，所以你选择的字符集的应该可以容纳所有你将用到字符。

常见的中文字符集有:

ZHS16CGB231280 	CGB2312-80 	16-bit Simplified Chinese MB, ASCII
ZHS16GBK 	    GBK 		16-bit Simplified Chinese MB, ASCII, UDC

其中GB2312码是中华人民共和国国家汉字信息交换用编码，全称《信息交换用汉字编码字符集--基本集》，由国家标准总局发布，
1981年5月1日实施，通行于大陆。新加坡等地也使用此编码。
GBK编码是1995年12月颁布的指导性规范。
GBK与国家标准 GB 2312-80 信息处理交换码所对应的、事实上的内码标准兼容；同时，在字汇一级支持 ISO/IEC 10646-1 和
GB 13000-1 的全部中日韩 (CJK) 汉字(20902字)。包含了更多的编码。

但是我们说，ZHS16GBK 并非是ZHS16CGB231280的严格超集（虽然后者的汉字在前者中都存在，但是同样的编码在不同两个
字符集中可能表达不同的汉字），所以在做数据库字符转换时仍然需要特别注意。

Oracle的字符集命名遵循以下命名规则:

     <Language><bit size><encoding>
即:  <语言>    <比特位数><编码>
比如: ZHS    · 16	    ·GBK

需要说明的是，有些字符集命名违背了这个规范，Oracle8/Oralce8i中的UTF-8是第一个打破这个命名规范的字符集。
我们可以看到一类字符集以 AL开头，如:
AL16UTF16
其中 AL代表 ALL,指适用于所有语言(All Languages)，按照这个标准当年UTF-8本应被命名为AL24UTF8。


字符集问题的初步探讨(三)-www.eygle.com

字符集问题的初步探讨(三)

--字符集的更改

Saturday, 2004-09-11 11:57 Eygle

原文发表于itpub技术丛书《Oracle数据库DBA专题技术精粹》,未经许可,严禁转载本文.

2． 字符集的更改

数据库创建以后，如果需要修改字符集，通常需要重建数据库，通过导入导出的方式来转换。
我们也可以通过以下方式更改

ALTER DATABASE CHARACTER SET

注意:修改数据库字符集时必须谨慎，修改之前一定要为数据库备份。由于不能回退这项操作,因此可能会造成数据丢失或者损坏。

这是最简单的转换字符集的方式，但并不总是有效。
这个命令在Oracle8时被引入Oracle,这个操作在本质上并不转换任何数据库字符，只是简单的更新数据库中所有跟字符集相关的信息。

这意味着，你只能在新字符集是旧字符集严格超集的情况下使用这种方式转换。
所谓超集是指:
当前字符集中的每一个字符在新字符集中都可以表示，并使用同样的代码点
比如很多字符集都是US7ASCII的严格超集。

如果不是超集，将获得以下错误:

SQL> ALTER DATABASE CHARACTER SET  ZHS16CGB231280;
ALTER DATABASE CHARACTER SET  ZHS16CGB231280
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set

下面我们来看一个测试(以下测试在Oracle9.2.0下进行，Oracle9i较Oracle8i在编码方面有较大改变，在Oracle8i中，测试结果可能略有不同):

SQL> select name,value$ from props$ where name like '%NLS%';

NAME                           VALUE$
------------------------------ ------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CHARACTERSET               US7ASCII
NLS_CALENDAR                   GREGORIAN
NLS_DATE_FORMAT                DD-MON-RR
NLS_DATE_LANGUAGE              AMERICAN
……………….
NLS_NCHAR_CHARACTERSET         AL16UTF16
NLS_RDBMS_VERSION              9.2.0.4.0

20 rows selected.
SQL> select name,dump(name) from eygle.test;

NAME   DUMP(NAME)
------------------------------------------------------
测试     Typ=1 Len=4: 178,226,202,212
Test      Typ=1 Len=4: 116,101,115,116

2 rows selected.

转换字符集，数据库应该在RESTRICTED模式下进行.

c:\>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Nov 1 10:52:30 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP MOUNT;
ORACLE instance started.

Total System Global Area   76619308 bytes
Fixed Size                   454188 bytes
Variable Size              58720256 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
Database mounted.
SQL> ALTER SESSION SET SQL_TRACE=TRUE;

Session altered.

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;

System altered.

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;

System altered.

SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;

System altered.

SQL> ALTER DATABASE OPEN;

Database altered.

SQL> set linesize 120
SQL> ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12721: operation cannot execute when other sessions are active

SQL> ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12716: Cannot ALTER DATABASE CHARACTER SET when CLOB data exists

在Oracle9i中，如果数据库存在CLOB类型字段，那么就不允许对字符集进行转换

SQL>

这时候，我们可以去查看alert<sid>.log日志文件，看CLOB字段存在于哪些表上:

ALTER DATABASE CHARACTER SET ZHS16GBK
 SYS.METASTYLESHEET (STYLESHEET) - CLOB populated
ORA-12716 signalled during: ALTER DATABASE CHARACTER SET ZHS16GBK...

对于不同情况，Oracle提供不同的解决方案，如果是用户数据表，一般我们可以把包含CLOB字段的表导出，然后drop掉相关对象，
转换后再导入数据库；对于系统表，可以按照以下方式处理:

SQL> truncate table Metastylesheet;

Table truncated.

然后可以继续进行转换！

SQL> ALTER SESSION SET SQL_TRACE=TRUE;

Session altered.

SQL> ALTER DATABASE CHARACTER SET ZHS16GBK;

Database altered.

SQL> ALTER SESSION SET SQL_TRACE=FALSE;

Session altered.

在9.2.0中，转换完成以后，可以通过运行catmet.sql脚本来重建Metastylesheet表:

SQL> @?/rdbms/admin/catmet.sql

转换后的数据：

SQL> select name,value$ from props$ where name like '%NLS%';

NAME                           VALUE$
------------------------------ ------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CHARACTERSET               ZHS16GBK
…..
NLS_NCHAR_CHARACTERSET         AL16UTF16
NLS_RDBMS_VERSION              9.2.0.4.0

20 rows selected.

SQL> select * from eygle.test;

NAME
------------------------------
测试
test

2 rows selected.

提示:
通过设置sql_trace，我们可以跟踪很多数据库的后台操作，这个工具是DBA常用的“利器”之一。
我们简单看一下数据库更改字符集时的后台处理，我提取了主要的更新部分。
通过以下跟踪过程，我们看到数据库在更改字符集的时候，主要更新了12张数据字典表，修改了数据库的原数据，这也证实了我们以前的说法:
这个更改字符集的操作在本质上并不转换任何数据库字符，只是简单的更新数据库中所有跟字符集相关的信息。

update col$ set charsetid = :1
where
 charsetform = :2

update argument$ set charsetid = :1
where
 charsetform = :2

update collection$ set charsetid = :1
where
 charsetform = :2

update attribute$ set charsetid = :1
where
 charsetform = :2

update parameter$ set charsetid = :1
where
 charsetform = :2

update result$ set charsetid = :1
where
 charsetform = :2

update partcol$ set spare1 = :1
where
 charsetform = :2

update subpartcol$ set spare1 = :1
where
 charsetform = :2

update props$ set value$ = :1
where
 name = :2

update "SYS"."KOTAD$" set SYS_NC_ROWINFO$ = :1
where
 SYS_NC_OID$ = :2

update seq$ set increment$=:2,minvalue=:3,maxvalue=:4,cycle#=:5,order$=:6,
  cache=:7,highwater=:8,audit$=:9,flags=:10
where
 obj#=:1

update kopm$ set metadata = :1, length  = :2
where
 name='DB_FDO'

在这里我们顺便纠正一个由来以及的错误方法.
经常可以在网上看到这样的更改字符集的方法：

1）用SYS用户名登陆ORACLE。

2）查看字符集内容

SQL>SELECT * FROM PROPS$;

3）修改字符集

SQL> update props$ set value$='新字符集' where name='NLS_CHARACTERSET'

4) COMMIT;

我们看到很多人在这个问题上遇到了惨痛的教训，使用这种方式更改字符集，如果你的value$值输入了不正确的字符集，在8i中那么你
的数据库可能会无法启动，这种情况是非常严重的,有时候你必须从备份中进行恢复；如果是在9i中，可以重新启动数据库后再修改回正
确的字符集。但是我们仍然不建议使用这种方式进行任何数据库修改，这是一种极其危险的操作。
实际上当我们更新了字符集，数据库启动时会根据数据库的字符集自动的来修改控制文件的字符集，如果字符集可以识别，更新控制文
件字符集等于数据库字符集；如果字符集不可识别，那么控制文件字符集更新为US7ASCII.

通过更新props$表的方式修改字符集,在Oracle7之后就不应该被使用.

以下是我的测试结果，但是严禁一切不备份的修改研究，即使是对测试库的。

SQL> update props$ set value$='EYGLE' where name='NLS_CHARACTERSET';

1 row updated.

SQL> commit;

Commit complete.

SQL> select name,value$ from props$ where name like '%NLS%';

NAME                           VALUE$
------------------------------ -----------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CHARACTERSET               EYGLE
NLS_CALENDAR                   GREGORIAN
NLS_DATE_FORMAT                DD-MON-RR
NLS_DATE_LANGUAGE              AMERICAN
….
NLS_NCHAR_CHARACTERSET         ZHS16GBK
NLS_RDBMS_VERSION              8.1.7.1.1

18 rows selected.

重新启动数据库，发现alert.log文件中记录如下操作:

Mon Nov 03 16:11:35 2003
Updating character set in controlfile to US7ASCII
Completed: ALTER DATABASE OPEN

启动数据库后恢复字符集设置:

SQL> update props$ set value$='ZHS16GBK' where name='NLS_CHARACTERSET';

1 row updated.

SQL> commit;

Commit complete.

SQL> select name,value$ from props$ where name like '%NLS%';

NAME                           VALUE$
------------------------------ -----------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CHARACTERSET               ZHS16GBK
NLS_CALENDAR                   GREGORIAN
NLS_DATE_FORMAT                DD-MON-RR
NLS_DATE_LANGUAGE              AMERICAN
………
NLS_COMP                       BINARY
NLS_NCHAR_CHARACTERSET         ZHS16GBK
NLS_RDBMS_VERSION              8.1.7.1.1

18 rows selected.

重新启动数据库后，发现控制文件的字符集被更新:

Mon Nov 03 16:21:41 2003
Updating character set in controlfile to ZHS16GBK
Completed: ALTER DATABASE OPEN

理解了字符集调整的内部操作以后，我们可以轻易的指出，以上的方法是不正确的，通过前面 ” ALTER DATABASE CHARACTER SET” 方式更改字
符集时，Oracle至少需要更改12张数据字典表，而这种直接更新props$表的方式只完成了其中十二分之一的工作，潜在的完整性隐患是可想而知的。

所以，更改字符集尽量要使用正常的途径。


字符集问题的初步探讨(四)-www.eygle.com

字符集问题的初步探讨(四)

-- 导入导出及转换

Tuesday, 2004-09-14 21:54 Eygle

原文发表于itpub技术丛书《Oracle数据库DBA专题技术精粹》,未经许可,严禁转载本文.

4． 导入导出及转换

导入导出是我们常用的一个数据迁移及转化工具，因其导出文件具有平台无关性，所以在跨平台迁移中，最为常用。
在导出操作时，非常重要的是客户端的字符集设置，也就是客户端的NLS_LANG设置。
NLS_LANG参数由以下部分组成:

NLS_LANG=<Language>_<Territory>.<Clients Characterset>

NLS_LANG各部分含义如下:
LANGUAGE指定:
-Oracle消息使用的语言
-日期中月份和日显示
TERRITORY指定
-货币和数字格式
-地区和计算星期及日期的习惯
CHARACTERSET:
-控制客户端应用程序使用的字符集
通常设置或者等于客户端(如Windows)代码页
或者对于unicode应用设置为UTF8
在Windows上查看当前系统的代码页可以使用chcp命令:

E:\>chcp

 活动的代码页: 936

代码页936也就是中文字符集 GBK,在Microsoft的官方站点上，我们可以遭到关于936代码页的具体编码规则,请参考以下链接:

http://www.microsoft.com/globaldev/reference/dbcs/936.htm

我们看一个简单的测试，来了解一下这几个参数的作用:

E:\>set NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK

E:\>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on 星期六 11月 1 22:51:59 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

连接到:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select sysdate from dual;

SYSDATE
----------
01-11月-03

已选择 1 行。

SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production中断开

E:\>set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

E:\>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Nov 1 22:52:24 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select sysdate from dual;

SYSDATE
---------
01-NOV-03

1 row selected.

SQL>

查看客户端NLS_LANG设置可以使用以下方法:

Windows使用:

echo %NLS_LANG%
如:
E:\>echo %NLS_LANG%
AMERICAN_AMERICA.ZHS16GBK

Unix使用:

env|grep NLS_LANG
如:
/opt/oracle>env|grep NLS_LANG
NLS_LANG=AMERICAN_CHINA.ZHS16GBK

    Windows客户端设置,可以在注册表中更改NLS_LANG,具体键值位于:
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMExx\
xx指存在多个ORACLE_HOME时系统编号。

导入和导出是客户端产品，同SQL*PLUS和Oralce Forms一样，因此，使用EXP/IMP工具将按照NLS_LANG定义的方式转换字符集。

导出使用的字符集将会记录在导出文件中，当文件导入时，将会检查导出时使用的字符集设置，如果这个字符集不同于导入客户端的NLS_LANG
设置，字符集将根据导入客户端NLS_LANG设置进行转换，如果必要，在数据插入数据库之前会进行进一步转换。

通常在导出时最好把客户端字符集设置得和数据库端相同，这样可以避免在导出时发生不必要的数据转换，导出文件将和数据库具有相同的字符集。
即使将来会把导出文件导入到不同字符集的数据库中，这样做也可以把转换延缓至导入时刻。

当进行数据导入时，主要存在以下两种情况:
1.源数据库和目标数据库具有相同字符集设置
这时，只需要设置NLS_LANG等于数据库字符集即可导入(前提是，导出使用的是和源数据库相同字符集，即三者相同)

2.源数据库和目标数据库字符集不同
如果我们导出时候使用的NLS_LANG是和源数据库相同的字符集，那么导入时就可以设置客户端NLS_LANG等于导出时使用的字符集，这
样转换只发生在数据库端，而且只发生一次。

例如:
如果进行从WE8MSWIN1252到UTF8的转换
1)使用NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252导出数据库。
这时创建的导出文件包含WE8MSWIN1252的数据
2)导入时使用NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252
这时转换仅发生在insert数据到UTF8的数据库中。

以上假设的转换只在目标数据库字符集是源数据库字符集的超集时才能转换。如果不同，一般就需要进行一些特殊的处理。

我们简单看一下导入的转换过程(以Oracle8i为例)：

1.确定导出数据库字符集环境
通过读取导出文件头，可以获得导出文件的字符集设置
2.确定导入session的字符集，即导入Session使用的NLS_LANG环境变量
3.IMP读取导出文件
读取导出文件字符集ID，和导入进程的NLS_LANG进行比较
4.如果导出文件字符集和导入Session字符集相同，那么在这一步骤内就不需要转换
如果不同，就需要把数据转换为导入Session使用的字符集。
然而这种转换只能在单byte字符集之间进行。
我们看一个测试：

E:\nls2>set NLS_LANG=AMERICAN_AMERICA.US7ASCII

设置导入session NLS_LANG为US7ASCII

E:\nls2>e:\oracle\ora8i\bin\imp eygle/eygle file=Sus7ascii-Cus7ascii-exp817.dmp fromuser=eygle touser=eygle tables=test

这个导出文件是从US7ASCII数据库导出，导出客户端NLS_LANG也是US7ASCII

Import: Release 8.1.7.1.1 - Production on Fri Nov 7 00:59:22 2003

(c) Copyright 2000 Oracle Corporation.  All rights reserved.

Connected to: Oracle8i Enterprise Edition Release 8.1.7.1.1 - Production
With the Partitioning option
JServer Release 8.1.7.1.1 - Production

这时导入，在DMP文件和NLS_LANG之间不需要进行字符集转换。

Export file created by EXPORT:V08.01.07 via conventional path
import done in US7ASCII character set and ZHS16GBK NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export server uses UTF8 NCHAR character set (possible ncharset conversion)
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

5.对于多Byte字符集的导入(如:UTF8)
需要设置导入Session字符集和导出字符集相同
否则就会遇到:IMP-16 "Required character set conversion (type %lu to %lu) not supported" 错误。
:

E:\nls2>set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

导入Session字符集设置为ZHS16GBK
导入US7ASCII的导出文件

E:\nls2>e:\oracle\ora8i\bin\imp eygle/eygle file=Sus7ascii-Cus7ascii-exp817.dmp fromuser=eygle touser=eygle

Import: Release 8.1.7.1.1 - Production on Fri Nov 7 00:38:55 2003

(c) Copyright 2000 Oracle Corporation.  All rights reserved.

Connected to: Oracle8i Enterprise Edition Release 8.1.7.1.1 - Production
With the Partitioning option
JServer Release 8.1.7.1.1 - Production

IMP-00016: required character set conversion (type 1 to 852) not supported
IMP-00000: Import terminated unsuccessfully

在从导出文件US7ASCII到导入 NLS_LANG设置为ZHS16GBK的过程中，不支持单Byte字符集向多Byte转换，报出以上错误。

6.导入Session字符集应该是导出字符集的超级，否则，专有的字符将难以正确转换。
7.当数据转换为导入Session字符集设置以后，如果导入Session字符集不同于导入数据库字符集，这时还需要最后一步转换，这要求导入数据库字符
集是导入session字符集的超级，否则某些专有字符将不能正常转换。
我们继续看上面的两个过程，这里有这样两个原则:
1．如果NLS_LANG的设置和数据库相同，那么数据（在传输过程中当然是2进制码）不经过转换就直接插入数据库中。
2．如果NLS_LANG的设置和数据库不同，那么数据需要转换后才能插入数据库中。
我们再回头来看上面的第一个例子:
:

Export file created by EXPORT:V08.01.07 via conventional path
import done in US7ASCII character set and ZHS16GBK NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export server uses UTF8 NCHAR character set (possible ncharset conversion)
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

这时候经过第一步转换后的数据，US7ASCII到ZHS16GBK丢失首位，原样插入数据库，我们看到这时数据库中存放的就是错误的字符(在后面
部分我们做了详细的转换):

E:\nls2>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Nov 7 00:35:39 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle8i Enterprise Edition Release 8.1.7.1.1 - Production
With the Partitioning option
JServer Release 8.1.7.1.1 - Production

SQL> select * from test;

NAME
--------------------
2bJT
test

在Oracle9i中，以上情况略有不同。


字符集问题的初步探讨(五)-www.eygle.com

字符集问题的初步探讨(五)

----如何识别导出文件的字符集

Tuesday, 2004-09-28 23:45 Eygle

原文发表于itpub技术丛书《Oracle数据库DBA专题技术精粹》,未经许可,严禁转载本文.

我们知道在导出文件中，记录着导出使用的字符集id,通过查看导出文件头的第2、3个字节，我们可以找到16进制表示的字符集ID,在Windows上，
我们可以使用UltraEdit等工具打开dmp文件，查看其导出字符集::

在Unix上我们可以通过以下命令来查看:

cat expdat.dmp | od -x | head

Oracle提供标准函数，对字符集名称及ID进行转换:

SQL> select nls_charset_id('ZHS16GBK') from dual;

NLS_CHARSET_ID('ZHS16GBK')
--------------------------
                       852

1 row selected.

SQL> select nls_charset_name(852) from dual;

NLS_CHAR
--------
ZHS16GBK

1 row selected.

十进制转换十六进制:

SQL> select to_char('852','xxxx') from dual;

TO_CH
-----
  354

1 row selected.

对应上面的图中第2、3字节，我们知道该导出文件字符集为ZHS16GBk.

查询数据库中有效的字符集可以使用以下脚本:

col nls_charset_id for 9999
col nls_charset_name for a30
col hex_id for a20
select
nls_charset_id(value) nls_charset_id,
value nls_charset_name,
to_char(nls_charset_id(value),'xxxx') hex_id
from  v$nls_valid_values
where parameter = 'CHARACTERSET'
order by nls_charset_id(value)
/

输出样例如下:

NLS_CHARSET_ID NLS_CHARSET_NAME               HEX_ID
-------------- ------------------------------ -------------
             1 US7ASCII                           1
             2 WE8DEC                             2
             3 WE8HP                              3
             4 US8PC437                           4
             5 WE8EBCDIC37                        5
             6 WE8EBCDIC500                       6
             7 WE8EBCDIC1140                      7
             8 WE8EBCDIC285                       8
 ...................
           850 ZHS16CGB231280                   352
           851 ZHS16MACCGB231280                353
           852 ZHS16GBK                         354
           853 ZHS16DBCS                        355
           860 ZHT32EUC                         35c
           861 ZHT32SOPS                        35d
           862 ZHT16DBT                         35e
           863 ZHT32TRIS                        35f
           864 ZHT16DBCS                        360
           865 ZHT16BIG5                        361
           866 ZHT16CCDC                        362
           867 ZHT16MSWIN950                    363
           868 ZHT16HKSCS                       364
           870 AL24UTFFSS                       366
           871 UTF8                             367
           872 UTFE                             368

..................................

在很多时候，当我们进行导入操作的时候，已经离开了源数据库，这时如果目标数据库的字符集和导出文件不一致，很多时候就需要进行特殊处理，
以下介绍几种方法，主要以US7ASCII和ZHS16GBK为例

1． 源数据库字符集为US7ASCII，导出文件字符集为US7ASCII或ZHS16GBK，目标数据库字符集为ZHS16GBK
在Oracle92中，我们发现对于这种情况，不论怎样处理，这个导出文件都无法正确导入到Oracle9i数据库中，这可能是因为Oracle9i的编码方案发生了较大改变。

以下是我们所做的简单测试，其中导出文件命名规则为:

S-Server ，后跟Server字符集
C-client , 后跟导出操作时客户端字符集

导入时客户端字符集设置在命令行完成，限于篇幅，我们省略了部分测试过程。
对于Oracle9iR2,我们的测试结果是US7ASCII字符集，不管怎样转换，都无法正确导入ZHS16GBK字符集的数据库中。

在进行导入操作时，如果字符不能正常转换，Oracle数据库会自动用一个”?”代替，也就是编码63。

E:\nls2>set NLS_LANG=AMERICAN_AMERICA.US7ASCII

E:\nls2>imp eygle/eygle file=Sus7ascii-Cus7ascii.dmp fromuser=eygle touser=eygle tables=test

Import: Release 9.2.0.4.0 - Production on Mon Nov 3 17:14:39 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Export file created by EXPORT:V09.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

E:\nls2>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Nov 3 17:14:50 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select name,dump(name) from test;

NAME	DUMP(NAME)
-----------------------------
????	Typ=1 Len=4: 63,63,63,63
test	Typ=1 Len=4: 116,101,115,116

2 rows selected.

SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

E:\nls2>set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

E:\nls2>imp eygle/eygle file=Sus7ascii-Cus7ascii.dmp fromuser=eygle touser=eygle tables=test ignore=y

Import: Release 9.2.0.4.0 - Production on Mon Nov 3 17:15:28 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Export file created by EXPORT:V09.02.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
export client uses US7ASCII character set (possible charset conversion)
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

E:\nls2>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Nov 3 17:15:34 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select name,dump(name) from test;

NAME		DUMP(NAME)
--------------------------------------------------------------------------------
????		Typ=1 Len=4: 63,63,63,63
test		Typ=1 Len=4: 116,101,115,116
????		Typ=1 Len=4: 63,63,63,63
test		Typ=1 Len=4: 116,101,115,116

4 rows selected.

SQL> drop table test;

Table dropped.

SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

E:\nls2>set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

E:\nls2>imp eygle/eygle file=Sus7ascii-Czhs16gbk.dmp fromuser=eygle touser=eygle tables=test ignore=y

Import: Release 9.2.0.4.0 - Production on Mon Nov 3 17:17:21 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Export file created by EXPORT:V09.02.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

E:\nls2>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Nov 3 17:17:30 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select name,dump(name) from test;

NAME	DUMP(NAME)
----------------------------------------------
????	Typ=1 Len=4: 63,63,63,63
test	Typ=1 Len=4: 116,101,115,116

2 rows selected.

SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

E:\nls2>set NLS_LANG=AMERICAN_AMERICA.US7ASCII

E:\nls2>imp eygle/eygle file=Sus7ascii-Czhs16gbk.dmp fromuser=eygle touser=eygle tables=test ignore=y

Import: Release 9.2.0.4.0 - Production on Mon Nov 3 17:18:00 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Export file created by EXPORT:V09.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

E:\nls2>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Nov 3 17:18:08 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select name,dump(name) from test;

NAME	DUMP(NAME)
----------------------------------------
????	Typ=1 Len=4: 63,63,63,63
test	Typ=1 Len=4: 116,101,115,116
????	Typ=1 Len=4: 63,63,63,63
test	Typ=1 Len=4: 116,101,115,116

4 rows selected.

SQL>

对于这种情况，我们可以通过使用Oracle8i的导出工具，设置导出字符集为US7ASCII，导出后修改第二、三字符，修改 0001 为
0354,这样就可以将US7ASCII字符集的数据正确导入到ZHS16GBK的数据库中。

修改导出文件:

导入修改后的导出文件:

E:\nls2>set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

E:\nls2>imp eygle/eygle file=Sus7ascii-Cus7ascii-exp817.dmp fromuser=eygle touser=eygle tables=test

Import: Release 9.2.0.4.0 - Production on Mon Nov 3 17:37:17 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Export file created by EXPORT:V08.01.07 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
export server uses UTF8 NCHAR character set (possible ncharset conversion)
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

E:\nls2>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Nov 3 17:37:23 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select name,dump(name) from test;

NAME     DUMP(NAME)
--------------------------------------------------------------------------------
测试       Typ=1 Len=4: 178,226,202,212
Test        Typ=1 Len=4: 116,101,115,116

2 rows selected.

SQL>

2． 使用create database的方法
如果导出文件使用的字符集是US7ASCII，目标数据库的字符集是ZHS16GBK,我们可以使用create database的方法来修改，具体如下:

SQL> col parameter for a30
SQL> col value for a30
SQL> select * from v$nls_parameters;

PARAMETER                      VALUE
------------------------------ ------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CALENDAR                   GREGORIAN
NLS_DATE_FORMAT                DD-MON-RR
NLS_DATE_LANGUAGE              AMERICAN
NLS_CHARACTERSET               ZHS16GBK
NLS_SORT                       BINARY
……………….

19 rows selected.

SQL> create database character set us7ascii;
create database character set us7ascii
*
ERROR at line 1:
ORA-01031: insufficient privileges

SQL> select * from v$nls_parameters;

PARAMETER                      VALUE
------------------------------ ------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CALENDAR                   GREGORIAN
NLS_DATE_FORMAT                DD-MON-RR
NLS_DATE_LANGUAGE              AMERICAN
NLS_CHARACTERSET               US7ASCII
NLS_SORT                       BINARY
…………..

19 rows selected.

SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

E:\nls2>set nls_lang=AMERICAN_AMERICA.US7ASCII

E:\nls2>imp eygle/eygle file=Sus7ascii-Cus7ascii.dmp fromuser=eygle touser=eygle

Import: Release 9.2.0.4.0 - Production on Sun Nov 2 14:53:26 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Export file created by EXPORT:V09.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
. . importing table                         "TEST"          2 rows imported
Import terminated successfully without warnings.

E:\nls2>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Sun Nov 2 14:53:35 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select * from test;

NAME
----------
测试
test

2 rows selected.

我们看到，当发出create database character set us7ascii；命令时，数据库v$nls_parameters中的字符集设置随之更改，该参数影响导入进程，
更改后可以正确导入数据，重起数据库后，该设置恢复。

提示:v$nls_paraemters来源于x$nls_parameters,该动态性能视图影响导入操作；而nls_database_parameters来源于props$数据表，影响数据存储。

3． Oracle提供的字符扫描工具csscan

我们说以上的方法只是应该在不得已的情况下使用，其本质是欺骗数据库，强制导入数据，可能损失元数据。
如果要确保数据的完整性，应该使用csscan扫描数据库，找出所有不兼容的字符，然后通过编写相应的脚本及代码，在转换之后进行更新，确保数据的正确性。
我们简单看一下csscan的使用。

要使用csscan之前，需要以sys用户身份创建相应数据字典对象:

E:\nls2>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Sun Nov 2 19:42:07 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select instance_name from v$intance;
select instance_name from v$intance
                          *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
penny

1 row selected.

SQL> @?/rdbms/admin/csminst.sql

User created.

Grant succeeded.

………..

这个脚本创建相应用户(csmig)及数据字典对象，扫描信息会记录在相应的数据字典表里。

我们可以在命令行调用这个工具对数据库进行扫描:

E:\nls2>csscan FULL=Y FROMCHAR=ZHS16GBK TOCHAR=US7ASCII LOG=US7check.log CAPTURE=Y ARRAY=1000000 PROCESS=2

Character Set Scanner v1.1 : Release 9.2.0.1.0 - Production on Sun Nov 2 20:24:45 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Username: eygle/eygle

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Enumerating tables to scan...

. process 1 scanning SYS.SOURCE$[AAAABHAABAAAAIRAAA]
. process 2 scanning SYS.ATTRIBUTE$[AAAAEoAABAAAAhZAAA]
. process 2 scanning SYS.PARAMETER$[AAAAEoAABAAAAhZAAA]
. process 2 scanning SYS.METHOD$[AAAAEoAABAAAAhZAAA]
……..
. process 2 scanning SYSTEM.DEF$_AQERROR[AAAA8fAABAAACWJAAA]
. process 1 scanning WMSYS.WM$ENV_VARS[AAABeWAABAAAFMZAAA]
………………….
. process 2 scanning SYS.UGROUP$[AAAAA5AABAAAAGpAAA]
. process 2 scanning SYS.CON$[AAAAAcAABAAAACpAAA]
. process 1 scanning SYS.FILE$[AAAAARAABAAAABxAAA]

Creating Database Scan Summary Report...

Creating Individual Exception Report...

Scanner terminated successfully.

然后我们可以检查输出的日志来查看数据库扫描情况:

Database Scan Individual Exception Report

[Database Scan Parameters]

Parameter                      Value
------------------------------ ------------------------------------------------
Scan type                      Full database
Scan CHAR data?                YES
Current database character set ZHS16GBK
New database character set     US7ASCII
Scan NCHAR data?               NO
Array fetch buffer size        1000000
Number of processes            2
Capture convertible data?      YES
------------------------------ ------------------------------------------------

[Data Dictionary individual exceptions]

[Application data individual exceptions]

User  : EYGLE
Table : TEST
Column: NAME
Type  : VARCHAR2(10)
Number of Exceptions         : 1
Max Post Conversion Data Size: 4

ROWID              Exception Type      Size Cell Data(first 30 bytes)
------------------ ------------------ ----- ------------------------------
AAABpIAADAAAAAMAAA lossy conversion         测试
------------------ ------------------ ----- ------------------------------

不能转换的数据将会被记录下来，我们可以根据这些信息在转换之后，对数据进行相应的更新，确保转换无误。


字符集问题的初步探讨(六)-乱码的产生-www.eygle.com

字符集问题的初步探讨(六)

----乱码的产生

Thursday, 2004-10-07 1:37 Eygle

原文发表于itpub技术丛书《Oracle数据库DBA专题技术精粹》,未经许可,严禁转载本文.

最后我们来讨论一下乱码的产生。

通常在我们的现实环境中，存在3个字符集设置。

第一: 客户端应用字符集(Client Application Character Set)

第二: 客户端NLS_LANG参数设置

第三: 服务器端，数据库字符集(Character Set)设置

我们说，一个字符在客户端应用(比如SQLPLUS,CMD,NOTEPAD等)中以怎样的字符显示取决于客户端操作系统，客户端能够显示怎样的字符，
我们就可以在应用中录入这些字符，至于这些字符能否在数据库中正常存储，就和另外的两个字符集设置紧密相关了。

在传输过程中，客户端NLS_LANG主要用于进行转换判断

如果NLS_LANG等于数据库字符集，则不进行任何转换直接把字符插入数据库

如果不同则进行转换，转换主要有两个任务

  • 如果存在对应关系，则把相应二进制编码经过映射后(这一步映射以后，所代表的字符可能发生转换)传递给数据库
  • 如果不存在对应关系，则传递一个替换字符(很多平台就是?)

数据库字符集，在和客户端NLS_LANG不同时，会把经过NLS_LANG转换的字符进行进一步处理

  • 对于?（即不存在对应关系的字符）直接以？形式存放入数据库
  • 对于其他字符，在NLS_LANG和数据库字符集之间进行转换后存入。

以下我们来看一下最为常见的字符集及乱码的产生:

1.当NLS_LANG字符集与数据库字符集不同，同时NLS_LANG不同于Server端字符集设置

在这种情况下，存在两种可能:

  • 客户端输入的字符在NLS_LANG中没有对应的字符，这时无法转换，NLS_LANG使用替换字符替代这些无法映射的字符(这一步转换在TTS中
    完成)，在很多字符集中这个替代字符就是”?”
  • 当客户端的字符在NLS_LANG中对应了不同的字符时，传递给数据库以后发生转换，存储的是字符，但是已经丢失了元数据，数据库中
    的字符不再代表客户端的输入。而且这个过程不可逆，这也就是为什么很多时候在客户端输入的是正常的编码，查询之后会得到未知字符的原因。

我们通过上图来简单说明一下这个过程，当客户端在WE8ISO8859P15字符集时，输入欧元符号: �,这时客户端NLS_LANG和数据库端字符集不同，
进行第一次转换，客户端�符号编码是A4,在NLS_LANG转换时，A4对应了NLS_LANG中的‘¤’，这一步的转换产生了错误映射。由于数据库字符集不
同于NLS_LANG设置，这时进一步的转换发生了，存入数据库的编码变成了C2A4,虽然同NLS_LANG进行了正确的转换，但是客户端录入的数据已经
损坏或者丢失了。

我们可以用我们熟悉的字符集做一个简单的测试:

测试环境:

客户端应用为中文18030字符集

NLS_LANG设置为US7ASCII字符集

数据库CHARACTER SET为ZHS16GBK

c:\>set NLS_LANG=AMERICAN_AMERICA.US7ASCII

c:\>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 4 01:19:57 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> insert into test values('测试');

1 row created.

SQL> select name,dump(name) from test;

NAME	DUMP(NAME)
--------------------------------------------------
2bJT	Typ=1 Len=4: 50,98,74,84

这时候我们发现，查询出来的是混乱的字符，我们把这些字符转换为2进制就是
110010   1100010   1001010   1010100
补全8位就是       00110010  01100010  01001010  01010100
我们把首位换成1   10110010  11100010  11001010  11010100

我们来看正确的存储:
c:\>set nls_lang=AMERICAN_AMERICA.ZHS16GBK

c:\>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 4 01:40:18 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> insert into test values('测试');

1 row created.

SQL> col dump(name) for a30
SQL> select name,dump(name) from test;

NAME DUMP(NAME)
---------- ------------------------------
测试 Typ=1 Len=4: 178,226,202,212

1 row selected.

我们把这个结果转换为2进制表示
          10110010  11100010  11001010  11010100

这个结果正是我们前面乱码首位补全1后的结果。

这个测试说明在US7ASCII转换中文的时候除去了首位的 1,这样就丢失了元数据，导致乱码出现，NLS_LANG的转换作用由此可加一斑！

3． NLS_LANG和数据库字符集相同时
在这种情况下，数据库端对客户端传递过来的编码不进行任何转换(这样可以提高性能)，直接存储进入数据库，那么这时候就存在和上面同样的问题，
如果客户端传递过来的字符集在数据库中有正确的对应就可以正确存储，如果没有，就会被替换字符置换成？，乱码就这样产生了。

如上图所示，当NLS_LANG和数据库字符集设置相同都为UTF8时，客户端的欧元符号的编码A4就不会经过任何转换就插入到数据库中，而在UTF8的数
据库中，A4代表的是一个非法字符。

我们来看一个简单的测试

测试环境:

客户端字符集应用为中文GB18030

客户端NLS_LANG为US7ASCII

数据库字符集为US7ASCII

我们知道这个时候，存入的数据，数据库不进行任何转换，在以下的测试中，我们看到中文在US7ASCII字符集下得以正确显示。

c:\>set nls_lang=AMERICAN_AMERICA.US7ASCII

c:\>sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 4 01:02:04 2003

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> insert into test values('测试');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test;

NAME
----------
测试

1 row selected.

SQL> col dump(name) for a30
SQL> select name,dump(name) from test;

NAME       DUMP(NAME)
---------- ------------------------------
测试       Typ=1 Len=4: 178,226,202,212

1 row selected.

SQL> select * from nls_database_parameters;

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_LANGUAGE                   AMERICAN
NLS_TERRITORY                  AMERICA
NLS_CURRENCY                   $
NLS_ISO_CURRENCY               AMERICA
NLS_NUMERIC_CHARACTERS         .,
NLS_CHARACTERSET               US7ASCII
NLS_CALENDAR                   GREGORIAN
NLS_DATE_FORMAT                DD-MON-RR
NLS_DATE_LANGUAGE              AMERICAN
NLS_SORT                       BINARY
NLS_TIME_FORMAT                HH.MI.SSXFF AM

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_TIMESTAMP_FORMAT           DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY              $
NLS_COMP                       BINARY
NLS_LENGTH_SEMANTICS           BYTE
NLS_NCHAR_CONV_EXCP            FALSE
NLS_NCHAR_CHARACTERSET         AL16UTF16
NLS_RDBMS_VERSION              9.2.0.4.0

20 rows selected.

SQL>

结语:

对于DBA来说，有一个很重要的原则就是:不要把你的数据库置于危险的境地！

这就要求我们，在进行任何可能对数据库结构发生改变的操作之前，先做有效的备份，很多DBA没有备份的操作中得到了惨痛的教训。


How to Install Orabm-www.eygle.com

How to Install Orabm

Sunday, 2004-09-26 14:44 Eygle

1.首先下载orabm包

你可以从以下地址下载:

http://www.linxcel.co.uk/orabm/orabm.tar

也可以从本地下载.

[gqgai@eygle gqgai]$ wget http://www.linxcel.co.uk/orabm/orabm.tar
--17:46:55--  http://www.linxcel.co.uk/orabm/orabm.tar
           => `orabm.tar'
Resolving www.linxcel.co.uk... done.
Connecting to www.linxcel.co.uk[212.227.127.109]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,280,000 [application/x-tar]

100%[========================================================================================>] 1,280,000     26.53K/s    ETA 00:00

17:47:43 (26.53 KB/s) - `orabm.tar' saved [1280000/1280000]

2.查看相关文件

$ tar -xvf *.tar
x orabm, 0 bytes, 0 tape blocks
x orabm/src, 0 bytes, 0 tape blocks
x orabm/src/orabmload.pc, 24200 bytes, 48 tape blocks
x orabm/src/orabm.c, 9346 bytes, 19 tape blocks
x orabm/src/init.ora, 1442 bytes, 3 tape blocks
x orabm/src/BUILD_FROM_SOURCE.txt, 863 bytes, 2 tape blocks
x orabm/install, 0 bytes, 0 tape blocks
x orabm/install/orabm_analyze.sql, 1068 bytes, 3 tape blocks
x orabm/install/orabm_cache.sql, 1116 bytes, 3 tape blocks
x orabm/install/orabm_ind.sql, 1124 bytes, 3 tape blocks
x orabm/install/orabm_query_cache.sql, 497 bytes, 1 tape blocks
x orabm/install/orabm_serverside_stress.sql, 8528 bytes, 17 tape blocks
x orabm/install/orabm_tab.sql, 2321 bytes, 5 tape blocks
x orabm/install/orabm_tab_rm.sql, 197 bytes, 1 tape blocks
x orabm/install/orabm_user.sql, 233 bytes, 1 tape blocks
x orabm/bin, 0 bytes, 0 tape blocks
x orabm/bin/orabm_tps.awk, 182 bytes, 1 tape blocks
x orabm/bin/orabm_tps.sh, 70 bytes, 1 tape blocks
x orabm/bin/solaris, 0 bytes, 0 tape blocks
x orabm/bin/solaris/orabmload, 85940 bytes, 168 tape blocks
x orabm/bin/solaris/orabm, 53140 bytes, 104 tape blocks
x orabm/bin/linux, 0 bytes, 0 tape blocks
x orabm/bin/linux/orabm, 42332 bytes, 83 tape blocks
x orabm/bin/linux/orabmload, 50741 bytes, 100 tape blocks
x orabm/bin/orabm.linuxd2.log, 559 bytes, 2 tape blocks
x orabm/bin/windows, 0 bytes, 0 tape blocks
x orabm/bin/windows/orabm.exe, 196653 bytes, 385 tape blocks
x orabm/bin/windows/orabmload.exe, 233525 bytes, 457 tape blocks
x orabm/orabm.pdf, 239954 bytes, 469 tape blocks
x orabm/orabm.htm, 200488 bytes, 392 tape blocks
x orabm/orabm_files, 0 bytes, 0 tape blocks
x orabm/orabm_files/image001.jpg, 46143 bytes, 91 tape blocks
x orabm/orabm_files/image002.jpg, 8437 bytes, 17 tape blocks
x orabm/orabm_files/_vti_cnf, 0 bytes, 0 tape blocks
x orabm/orabm_files/_vti_cnf/image002.jpg, 724 bytes, 2 tape blocks
x orabm/orabm_files/_vti_cnf/image001.jpg, 725 bytes, 2 tape blocks
x orabm/orabm_files/_vti_cnf/image003.gif, 699 bytes, 2 tape blocks
x orabm/orabm_files/_vti_cnf/editdata.mso, 708 bytes, 2 tape blocks
x orabm/orabm_files/_vti_cnf/filelist.xml, 707 bytes, 2 tape blocks
x orabm/orabm_files/_vti_cnf/header.htm, 1264 bytes, 3 tape blocks
x orabm/orabm_files/_vti_cnf/.fp_folder_info, 58 bytes, 1 tape blocks
x orabm/orabm_files/editdata.mso, 2976 bytes, 6 tape blocks
x orabm/orabm_files/filelist.xml, 289 bytes, 1 tape blocks
x orabm/orabm_files/image003.gif, 14667 bytes, 29 tape blocks
x orabm/orabm_files/header.htm, 4705 bytes, 10 tape blocks
$ ls
orabm      orabm.tar
$ cd orabm
$ ls
bin          install      orabm.htm    orabm.pdf    orabm_files  src
$ ls
bin          install      orabm.htm    orabm.pdf    orabm_files  src
$ cd install
$ ls
orabm_analyze.sql            orabm_ind.sql                orabm_serverside_stress.sql  orabm_tab_rm.sql
orabm_cache.sql              orabm_query_cache.sql        orabm_tab.sql                orabm_user.sql

注意:缺省的orabm测试用用户会建立在tools表空间,如果你想把数据放在其他表空间可以修改orabm_user.sql来调整.

3.安装的步骤如下:

# | Operation | Command
1 | create the ORABM user (assumes TOOLS tablespace, TEMP temporary tablespace) | sqlplus system/pwd @orabm_user
2 | create the tables | sqlplus system/pwd @orabm_tab
3 | load the data | $ orabmload Warehouses 1
4 | create the indexes | sqlplus system/pwd @orabm_ind
5 | analyze the tables and indexes | sqlplus system/pwd @orabm_analyze
6 | create the stress-test PL/SQL procedures | sqlplus system/pwd @orabm_serverside_stress
7 | cache the table and index data in the SGA | sqlplus system/pwd @orabm_cache

4.安装日志及如下

$ sqlplus "/ as sysdba" @orabm_user

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Sep 25 17:55:40 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

User created.

Grant succeeded.

User altered.

User altered.

Revoke succeeded.

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
$ sqlplus "/ as sysdba" @orabm_tab

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Sep 25 17:55:56 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Table created.

Table created.

Table created.

Table created.

Table created.

Table created.

Table created.

Table created.

Table created.

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

$ cd ..
$ ls
bin          install      orabm.htm    orabm.pdf    orabm_files  src
$ cd bin
$ ls
linux              orabm.linuxd2.log  orabm_tps.awk      orabm_tps.sh       solaris            windows
$ cd solaris
$ ls
orabm      orabmload
$ ./orabmload Warehouse 1
ld.so.1: ./orabmload: fatal: /opt/oracle/product/9.2.0/lib/libclntsh.so.9.0: wrong ELF class: ELFCLASS64
Killed

$ LD_LIBRARY_PATH=${ORACLE_HOME}/lib32:${LD_LIBRARY_PATH} export LD_LIBRARY_PATH

$ ./orabmload Warehouses 1

Connected to ORACLE as user: ORABM
using timestamp=20040925181524
TPCC Data Load Started...
Loading Item
.................... 20000
.................... 40000
.................... 60000
.................... 80000
.................... 100000
Item Done.
Loading Warehouse
Loading Stock Wid=1
.................... 20000
.................... 40000
.................... 60000
.................... 80000
.................... 100000
 Stock Done.
Loading District
Loading Customer for DID=1, WID=1
...Customer Done.
Loading Customer for DID=2, WID=1
...Customer Done.
Loading Customer for DID=3, WID=1
...Customer Done.
Loading Customer for DID=4, WID=1
...Customer Done.
Loading Customer for DID=5, WID=1
...Customer Done.
Loading Customer for DID=6, WID=1
...Customer Done.
Loading Customer for DID=7, WID=1
...Customer Done.
Loading Customer for DID=8, WID=1
...Customer Done.
Loading Customer for DID=9, WID=1
...Customer Done.
Loading Customer for DID=10, WID=1
...Customer Done.
Loading Orders for D=1, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=2, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=3, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=4, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=5, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=6, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=7, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=8, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=9, W= 1
. 1000
. 2000
. 3000
Orders Done.
Loading Orders for D=10, W= 1
. 1000
. 2000
. 3000
Orders Done.

...DATA LOADING COMPLETED SUCCESSFULLY.
$ cd ../../install
$ ls
orabm_analyze.sql            orabm_ind.sql                orabm_serverside_stress.sql  orabm_tab_rm.sql
orabm_cache.sql              orabm_query_cache.sql        orabm_tab.sql                orabm_user.sql
$ sqlplus "/ as sysdba" @orabm_ind

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Sep 25 18:31:05 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

DOC> *
DOC> * same indexes as used by Oracle record breaking 32-CPU
DOC> * RAC TPC-C benchmark on Linux - Sept 2002
DOC> *
DOC> * Geoff Ingram (geoff@dbcool.com)
DOC> */

Session altered.

Index created.

Index created.

Index created.

Index created.

Index created.

Index created.

Index created.

Index created.

Index created.

Index created.

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
$ sqlplus "/ as sysdba" @orabm_analyze

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Sep 25 18:32:17 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Session altered.

Table analyzed.

Table analyzed.

Table analyzed.

Table analyzed.

Table analyzed.

Table analyzed.

Table analyzed.

Table analyzed.

Table analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Index analyzed.

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
$ sqlplus "/ as sysdba" @orabm_serverside_stress

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Sep 25 18:35:50 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

DOC> *
DOC> *    v2.0
DOC> *
DOC> *    Copyright (c) 2002, Geoff Ingram (geoff@dbcool.com) - Proton Technology Ltd
DOC> *
DOC> *    orabm_serverside_stress.sql: Oracle package for CPU stress test benchmark
DOC> *
DOC> *    You may distribute orabm_serverside_stress.sql under the terms of either the
DOC> *    widely available GNU General Public License or the Artistic License
DOC> *    with the exception that it cannot be placed on a CD-ROM or similar media
DOC> *    for commercial distribution without the prior approval of the author.
DOC> *
DOC> */

Procedure created.

Procedure created.

Procedure created.

Procedure created.

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
$ sqlplus "/ as sysdba" @orabm_cache

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Sep 25 18:36:07 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

Table altered.

  COUNT(*)
----------
     30000

Table altered.

  COUNT(*)
----------
        10

Table altered.

  COUNT(*)
----------
     30000

Table altered.

  COUNT(*)
----------
    299952

Table altered.

  COUNT(*)
----------
    100000

  COUNT(*)
----------
     30000

  COUNT(*)
----------
     30000

  COUNT(*)
----------
    100000

  COUNT(*)
----------
    299952

  COUNT(*)
----------
     30000

  COUNT(*)
----------
     30000

  COUNT(*)
----------
    100000

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

至此安装完成.


Use orabm To test system CPU TPC-www.eygle.com

Use orabm To test system CPU TPC

Sunday, 2004-09-26 13:24 Eygle

orabm是一个开源的系统CPU性能测试工具.
作者Geoff Ingram曾经为Oracle工作数年,是High Performance Oracle" (ISBN: 0471224367)一书的作者.

orabm的安装你可以参考:

How To Install Orabm

作者原网页如下:

http://linxcel.co.uk/orabm/orabm.htm

我们接下来看一下怎样使用orabm通过Oracle数据库来测试CPU性能.

1.首先我们先要了解一下orabm的原理使用:

How Orabm Works

Orabm works by running a user-specified number of database transactions in each of a user-specified number of concurrent database sessions.
Orabm通过在用户指定的并发下运行指定数量的事务来测试系统性能.
The transactions are executed by the ORABM_SERVERSIDE_STRESS stored procedure, under the schema ORABM.
事务通过执行orabm用户的ORABM_SERVERSIDE_STRESS过程来实现.

For each concurrent session, ORABM_SERVERSIDE_STRESS runs the number of transactions specified on the orabm command line, and returns the transactions per second (TPS) value for that session during the sampling interval on completion.
对于每个并发session,ORABM_SERVERSIDE_STRESS运行在orabm命令行指定数量的事务.
并返回在完成所有任务的采样间隔内每秒的事务数量.
To ensure that all concurrent sessions are processing transactions during the sampling interval, the TPS value only includes results from the middle 80% of transactions: the first 10% and last 10% are ignored.
为了保证准确性,TPS值只取中间的80%数据,头尾的10%都将被忽略.

The transactions are loosely based on the TPC-C Order-Status and Stock-Level transactions, using a predefined distribution of transactions.
事务是松散的,基于标准的TPC-C测试的订单、库存事务模型,使用预定义的事务分布.
The transaction split, which is based on data returned by the DBMS_RANDOM package, should be:
事务基于DBMS_RANDOM包的返回值进行分割,应该是:

Stock-Level:Order-by-Customer-Name:Order-by-Customer-Id
50% :30% :20%

The string returned by ORABM_SERVERSIDE_STRESS includes the transaction split during the test, to ensure that the transaction distribution is correct, subject to random fluctuations e.g.:
为了确保事务分布的正确性,ORABM_SERVERSIDE_STRESS的输出包含事务分割比例,输出结果具有随机波动,例如:

...sl=4042(50.5%) on=2384(29.8%) oi=1573(19.7%)...

Orabm Command Line

Once you have set up the test tables, data, and indexes, you're ready to run orabm. The following command shows orabm running 20000 transactions in a single session against the Oracle database identified by ORACLE_SID in the UNIX environment:
在成功安装了orabm之后,在UNIX下定义好了ORACLE_SID环境变量之后,我们可以如下运行orabm命令进行测试:

$ orabm 1 20000

This command line runs the same workload against a remote database identified by the Oracle Net alias linxceld1.co.uk from a Windows command box:
以下是在WINDOWS下远程运行方式:

C:\> orabm 1 20000 linxceld1.co.uk

Note: running against a remote database has little (if any), affect on the transaction throughput, because all processing takes place on the DBMS server.

Execution of a single Orabm session should show a single CPU at close to 100% utilization, provided that all table and index data is present in the Oracle block buffer cache and no other workload is running on the database server. On UNIX or Linux, you can use the “top” command to confirm this, or check that no "db file sequential read" event waits are taking place for the Oracle session using info in the V$SESSION_EVENT view - these indicate waits for physical I/O.

如果所有的测试表和相关索引都已经Cache到内存中,系统上没有其他任务运行,那么你可以看到单个Orabm Session会使用将近100%的CPU资源.在Linux或者Unix上，可以使用Top来查看CPU使用情况,或者检察数据库中不存在"db file sequential read"等待事件.

Alternatively, if your Oracle DBMS is running on Linux, you can use the gkrellm performance monitor to show that CPU utilization of a single CPU is at ~100% and no physical I/O is taking place. Gkrellm can be downloaded from:

http://web.wt.net/~billw/gkrellm/gkrellm.html

Here's an example of the command line you would use to run 10000 transactions against a local Oracle database for three iterations. In the first iteration, one session runs, in the second iteration two concurrent sessions run, and in the third iteration, six concurrent sessions run:

以下是一个测试例子,对本地数据库进行三个阶段测试,分别以1,2,6个并发执行10000个事务.

$ orabm 1,2,6 10000

Keep in mind that the specified number of transactions is run in each concurrent session.

注意,这里定义的10000个事务是对每个session来说的.

Note: you should specify sufficient transactions such that the TPS results produced don't fluctuate significantly between runs for a given number of sessions; 100000 is a good value to choose.

Note:你应该定义足够的事务以便TPS结果在不同数量并发下波动尽量小,通常100,000是一个好的选择.

Results Output

Output is appended to a log file orabm.database.log, where database is either the ORACLE_SID or TNS alias that identifies the database where the test was run e.g. orabm.t92.log. For each iteration, the TPS value for each concurrent session appears between begin and end markers. For example, the following shows the contents of the log for two concurrent sessions - in this case the second iteration for the previous command line example - where txn(all) displays the total transaction count, and xn(sam) and t(sam) show the total transactions and time for the middle 80% of transactions for which sampling took place:

输出结果的说明:
txn(all)----代表Total transaction Count,总的事务数量.
xn(sam)-----采样的事务数量
t(sam)------采样事务运行的时间.

---begin sess=2 txn=10000 ORACLE_SID=t92 Fri Nov 8 20:31:48 2002
T92.WORLD txn(all)=10000 xn(sam)=7999 t(sam)=44 tps=182 ...
T92.WORLD txn(all)=10000 xn(sam)=7999 t(sam)=45 tps=178 ...
---end - Fri Nov 8 20:32:46 2002

The total TPS for this iteration is the sum of the TPS for the two concurrent sessions (182+178=360).
对于以上输出,在2个并发下,TPS值为182+178=360

A shell script (orabm_tps.sh) can be used to process output from the log on UNIX and Linux. The script aggregates the TPS values for concurrent sessions in a single iteration into a total TPS value for that iteration. The output based on the log info from the previous command line (3 iterations with 1, then 2, then 6 concurrent sessions) shows:
也可以用shell script(orabm_tps.sh)进行输出日志分析.

$ orabm_tps.sh orabm.t92.log
ORACLE_SID=t92 sess=1
      tps=182
ORACLE_SID=t92 sess=2 tps=360
ORACLE_SID=t92 sess=6
      tps=364

In this example the server was a 2 CPU model - as a result, 2 concurrent sessions running in orabm are enough to completely utilize all available CPU capacity.
在这个例子中,Server有两个CPU,测试中两个并发足以消耗所有的CPU资源.

Additional sessions should result in the total TPS remaining unchanged, or even falling slightly as the operating system performs context switches to share the overloaded CPU resource between more ready-to-run sessions than available CPUs.
继续增加并发并不会导致TPS值得增加,甚至有可能会下降.

2.看一下我的一个测试结果

$ orabm 1,2,6,10,15,20,25,30 10000
---begin sess=1 txn=10000 ORACLE_SID=hsbill Sun Sep 26 00:51:34 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=89 tps=90 sl=3915(48.9%) on=2481(31%) oi=1603(20%) end=260904-00:53:25
---end - Sun Sep 26 00:53:25 2004
---begin sess=2 txn=10000 ORACLE_SID=hsbill Sun Sep 26 00:53:25 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=96 tps=83 sl=3992(49.9%) on=2464(30.8%) oi=1543(19.3%) end=260904-00:55:25
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=104 tps=77 sl=3945(49.3%) on=2404(30.1%) oi=1650(20.6%) end=260904-00:55:34
---end - Sun Sep 26 00:55:34 2004
---begin sess=6 txn=10000 ORACLE_SID=hsbill Sun Sep 26 00:55:34 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=189 tps=42 sl=4039(50.5%) on=2332(29.2%) oi=1628(20.4%) end=260904-00:59:32
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=193 tps=41 sl=3999(50%) on=2402(30%) oi=1598(20%) end=260904-00:59:36
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=192 tps=42 sl=3933(49.2%) on=2435(30.4%) oi=1631(20.4%) end=260904-00:59:36
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=198 tps=40 sl=4033(50.4%) on=2358(29.5%) oi=1608(20.1%) end=260904-00:59:38
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=201 tps=40 sl=4027(50.3%) on=2339(29.2%) oi=1633(20.4%) end=260904-00:59:40
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=202 tps=40 sl=3998(50%) on=2454(30.7%) oi=1547(19.3%) end=260904-00:59:42
---end - Sun Sep 26 00:59:42 2004
---begin sess=10 txn=10000 ORACLE_SID=hsbill Sun Sep 26 00:59:42 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=277 tps=29 sl=3951(49.4%) on=2446(30.6%) oi=1602(20%) end=260904-01:05:24
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=287 tps=28 sl=3993(49.9%) on=2412(30.2%) oi=1594(19.9%) end=260904-01:05:39
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=287 tps=28 sl=3965(49.6%) on=2390(29.9%) oi=1644(20.6%) end=260904-01:05:43
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=288 tps=28 sl=3944(49.3%) on=2472(30.9%) oi=1583(19.8%) end=260904-01:05:43
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=290 tps=28 sl=4106(51.3%) on=2294(28.7%) oi=1599(20%) end=260904-01:05:44
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=293 tps=27 sl=4040(50.5%) on=2397(30%) oi=1562(19.5%) end=260904-01:05:44
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=292 tps=27 sl=3950(49.4%) on=2438(30.5%) oi=1611(20.1%) end=260904-01:05:46
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=295 tps=27 sl=4006(50.1%) on=2430(30.4%) oi=1563(19.5%) end=260904-01:05:47
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=301 tps=27 sl=4008(50.1%) on=2362(29.5%) oi=1629(20.4%) end=260904-01:05:48
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=301 tps=27 sl=3984(49.8%) on=2363(29.5%) oi=1652(20.7%) end=260904-01:05:49
---end - Sun Sep 26 01:05:49 2004
---begin sess=15 txn=10000 ORACLE_SID=hsbill Sun Sep 26 01:05:49 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=398 tps=20 sl=4050(50.6%) on=2379(29.7%) oi=1570(19.6%) end=260904-01:14:14
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=402 tps=20 sl=4024(50.3%) on=2366(29.6%) oi=1609(20.1%) end=260904-01:14:14
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=408 tps=20 sl=4032(50.4%) on=2326(29.1%) oi=1641(20.5%) end=260904-01:14:15
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=408 tps=20 sl=4007(50.1%) on=2355(29.4%) oi=1637(20.5%) end=260904-01:14:15
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=402 tps=20 sl=4071(50.9%) on=2377(29.7%) oi=1551(19.4%) end=260904-01:14:15
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=408 tps=20 sl=4055(50.7%) on=2385(29.8%) oi=1559(19.5%) end=260904-01:14:17
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=415 tps=19 sl=3963(49.5%) on=2424(30.3%) oi=1612(20.2%) end=260904-01:14:22
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=407 tps=20 sl=4061(50.8%) on=2337(29.2%) oi=1601(20%) end=260904-01:14:23
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=416 tps=19 sl=3900(48.8%) on=2404(30.1%) oi=1695(21.2%) end=260904-01:14:25
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=421 tps=19 sl=3942(49.3%) on=2442(30.5%) oi=1615(20.2%) end=260904-01:14:26
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=417 tps=19 sl=3966(49.6%) on=2432(30.4%) oi=1601(20%) end=260904-01:14:26
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=427 tps=19 sl=4039(50.5%) on=2383(29.8%) oi=1577(19.7%) end=260904-01:14:28
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=439 tps=18 sl=3994(49.9%) on=2443(30.5%) oi=1562(19.5%) end=260904-01:14:33
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=450 tps=18 sl=4053(50.7%) on=2427(30.3%) oi=1519(19%) end=260904-01:14:37
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=451 tps=18 sl=4044(50.6%) on=2360(29.5%) oi=1595(19.9%) end=260904-01:14:38
---end - Sun Sep 26 01:14:38 2004
---begin sess=20 txn=10000 ORACLE_SID=hsbill Sun Sep 26 01:14:38 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=493 tps=16 sl=4028(50.4%) on=2358(29.5%) oi=1613(20.2%) end=260904-01:24:55
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=510 tps=16 sl=4077(51%) on=2346(29.3%) oi=1576(19.7%) end=260904-01:25:13
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=507 tps=16 sl=4033(50.4%) on=2351(29.4%) oi=1615(20.2%) end=260904-01:25:13
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=508 tps=16 sl=3980(49.8%) on=2383(29.8%) oi=1636(20.5%) end=260904-01:25:14
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=505 tps=16 sl=3998(50%) on=2405(30.1%) oi=1596(20%) end=260904-01:25:14
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=507 tps=16 sl=4048(50.6%) on=2401(30%) oi=1550(19.4%) end=260904-01:25:15
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=511 tps=16 sl=3998(50%) on=2343(29.3%) oi=1658(20.7%) end=260904-01:25:17
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=509 tps=16 sl=4001(50%) on=2360(29.5%) oi=1638(20.5%) end=260904-01:25:17
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=513 tps=16 sl=4048(50.6%) on=2409(30.1%) oi=1542(19.3%) end=260904-01:25:19
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=516 tps=16 sl=3969(49.6%) on=2400(30%) oi=1630(20.4%) end=260904-01:25:21
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=519 tps=15 sl=3960(49.5%) on=2396(30%) oi=1643(20.5%) end=260904-01:25:22
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=529 tps=15 sl=4032(50.4%) on=2377(29.7%) oi=1590(19.9%) end=260904-01:25:26
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=535 tps=15 sl=4080(51%) on=2357(29.5%) oi=1562(19.5%) end=260904-01:25:27
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=526 tps=15 sl=4080(51%) on=2326(29.1%) oi=1593(19.9%) end=260904-01:25:27
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=530 tps=15 sl=4019(50.2%) on=2400(30%) oi=1580(19.8%) end=260904-01:25:28
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=523 tps=15 sl=3945(49.3%) on=2477(31%) oi=1577(19.7%) end=260904-01:25:28
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=532 tps=15 sl=4058(50.7%) on=2382(29.8%) oi=1559(19.5%) end=260904-01:25:30
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=534 tps=15 sl=4029(50.4%) on=2363(29.5%) oi=1607(20.1%) end=260904-01:25:30
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=547 tps=15 sl=4027(50.3%) on=2342(29.3%) oi=1630(20.4%) end=260904-01:25:34
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=563 tps=14 sl=4077(51%) on=2344(29.3%) oi=1578(19.7%) end=260904-01:25:36
---end - Sun Sep 26 01:25:36 2004
---begin sess=25 txn=10000 ORACLE_SID=hsbill Sun Sep 26 01:25:36 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=626 tps=13 sl=4011(50.1%) on=2422(30.3%) oi=1566(19.6%) end=260904-01:38:37
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=621 tps=13 sl=3964(49.6%) on=2415(30.2%) oi=1620(20.3%) end=260904-01:38:39
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=631 tps=13 sl=4035(50.4%) on=2401(30%) oi=1563(19.5%) end=260904-01:38:39
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=630 tps=13 sl=4014(50.2%) on=2432(30.4%) oi=1553(19.4%) end=260904-01:38:44
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=631 tps=13 sl=4082(51%) on=2343(29.3%) oi=1574(19.7%) end=260904-01:38:44
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=636 tps=13 sl=3961(49.5%) on=2407(30.1%) oi=1631(20.4%) end=260904-01:38:47
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=638 tps=13 sl=4048(50.6%) on=2352(29.4%) oi=1599(20%) end=260904-01:38:50
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=636 tps=13 sl=3967(49.6%) on=2414(30.2%) oi=1618(20.2%) end=260904-01:38:51
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=632 tps=13 sl=3970(49.6%) on=2405(30.1%) oi=1624(20.3%) end=260904-01:38:51
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=637 tps=13 sl=3972(49.7%) on=2398(30%) oi=1629(20.4%) end=260904-01:38:51
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=637 tps=13 sl=4028(50.4%) on=2406(30.1%) oi=1565(19.6%) end=260904-01:38:52
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=634 tps=13 sl=4015(50.2%) on=2383(29.8%) oi=1601(20%) end=260904-01:38:52
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=638 tps=13 sl=3983(49.8%) on=2502(31.3%) oi=1514(18.9%) end=260904-01:38:53
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=641 tps=12 sl=3947(49.3%) on=2479(31%) oi=1573(19.7%) end=260904-01:38:54
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=647 tps=12 sl=3956(49.5%) on=2426(30.3%) oi=1617(20.2%) end=260904-01:38:54
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=636 tps=13 sl=3958(49.5%) on=2481(31%) oi=1560(19.5%) end=260904-01:38:54
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=644 tps=12 sl=3918(49%) on=2478(31%) oi=1603(20%) end=260904-01:38:56
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=646 tps=12 sl=4027(50.3%) on=2471(30.9%) oi=1501(18.8%) end=260904-01:38:57
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=644 tps=12 sl=4026(50.3%) on=2426(30.3%) oi=1547(19.3%) end=260904-01:38:57
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=645 tps=12 sl=4031(50.4%) on=2359(29.5%) oi=1609(20.1%) end=260904-01:38:58
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=647 tps=12 sl=4054(50.7%) on=2330(29.1%) oi=1615(20.2%) end=260904-01:38:58
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=651 tps=12 sl=3960(49.5%) on=2405(30.1%) oi=1634(20.4%) end=260904-01:38:59
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=660 tps=12 sl=4027(50.3%) on=2381(29.8%) oi=1591(19.9%) end=260904-01:39:00
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=665 tps=12 sl=3942(49.3%) on=2452(30.7%) oi=1605(20.1%) end=260904-01:39:01
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=717 tps=11 sl=4019(50.2%) on=2344(29.3%) oi=1636(20.5%) end=260904-01:39:26
---end - Sun Sep 26 01:39:26 2004
---begin sess=30 txn=10000 ORACLE_SID=hsbill Sun Sep 26 01:48:31 2004
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=739 tps=11 sl=3994(49.9%) on=2414(30.2%) oi=1591(19.9%) end=260904-02:04:02
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=741 tps=11 sl=3951(49.4%) on=2423(30.3%) oi=1625(20.3%) end=260904-02:04:02
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=745 tps=11 sl=4043(50.5%) on=2357(29.5%) oi=1599(20%) end=260904-02:04:05
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=751 tps=11 sl=3993(49.9%) on=2449(30.6%) oi=1557(19.5%) end=260904-02:04:07
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=749 tps=11 sl=4018(50.2%) on=2405(30.1%) oi=1576(19.7%) end=260904-02:04:10
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=750 tps=11 sl=3994(49.9%) on=2394(29.9%) oi=1611(20.1%) end=260904-02:04:11
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=751 tps=11 sl=4066(50.8%) on=2369(29.6%) oi=1564(19.6%) end=260904-02:04:11
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=752 tps=11 sl=3973(49.7%) on=2374(29.7%) oi=1652(20.7%) end=260904-02:04:12
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=759 tps=11 sl=3887(48.6%) on=2515(31.4%) oi=1597(20%) end=260904-02:04:13
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=754 tps=11 sl=3974(49.7%) on=2439(30.5%) oi=1586(19.8%) end=260904-02:04:13
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=755 tps=11 sl=4000(50%) on=2336(29.2%) oi=1663(20.8%) end=260904-02:04:13
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=757 tps=11 sl=3931(49.1%) on=2442(30.5%) oi=1626(20.3%) end=260904-02:04:14
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=758 tps=11 sl=3989(49.9%) on=2401(30%) oi=1609(20.1%) end=260904-02:04:14
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=757 tps=11 sl=3974(49.7%) on=2403(30%) oi=1622(20.3%) end=260904-02:04:15
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=760 tps=11 sl=4049(50.6%) on=2375(29.7%) oi=1575(19.7%) end=260904-02:04:15
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=761 tps=11 sl=3870(48.4%) on=2416(30.2%) oi=1713(21.4%) end=260904-02:04:17
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=758 tps=11 sl=4036(50.5%) on=2368(29.6%) oi=1595(19.9%) end=260904-02:04:17
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=761 tps=11 sl=3966(49.6%) on=2445(30.6%) oi=1588(19.9%) end=260904-02:04:18
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=761 tps=11 sl=3969(49.6%) on=2413(30.2%) oi=1617(20.2%) end=260904-02:04:18
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=761 tps=11 sl=3999(50%) on=2417(30.2%) oi=1583(19.8%) end=260904-02:04:19
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=755 tps=11 sl=4060(50.8%) on=2366(29.6%) oi=1573(19.7%) end=260904-02:04:20
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=774 tps=10 sl=4041(50.5%) on=2367(29.6%) oi=1591(19.9%) end=260904-02:04:21
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=763 tps=10 sl=4087(51.1%) on=2343(29.3%) oi=1569(19.6%) end=260904-02:04:22
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=769 tps=10 sl=4021(50.3%) on=2407(30.1%) oi=1571(19.6%) end=260904-02:04:23
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=773 tps=10 sl=4019(50.2%) on=2413(30.2%) oi=1567(19.6%) end=260904-02:04:23
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=763 tps=10 sl=4004(50.1%) on=2352(29.4%) oi=1643(20.5%) end=260904-02:04:24
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=770 tps=10 sl=4063(50.8%) on=2354(29.4%) oi=1582(19.8%) end=260904-02:04:24
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=779 tps=10 sl=4019(50.2%) on=2399(30%) oi=1581(19.8%) end=260904-02:04:24
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=784 tps=10 sl=4032(50.4%) on=2374(29.7%) oi=1593(19.9%) end=260904-02:04:26
HSBILL.HURRAY.COM.CN txn(all)=10000 xn(sam)=7999 t(sam)=809 tps=10 sl=3962(49.5%) on=2458(30.7%) oi=1579(19.7%) end=260904-02:04:28
---end - Sun Sep 26 02:04:28 2004

3.使用脚本格式化输出

$ orabm_tps.sh ./solaris/bm.hsbill.log
ORACLE_SID=hsbill
              sess=1 tps=90
ORACLE_SID=hsbill sess=2
              tps=160
ORACLE_SID=hsbill sess=6 tps=245
ORACLE_SID=hsbill
              sess=10 tps=276
ORACLE_SID=hsbill sess=15
              tps=289
ORACLE_SID=hsbill sess=20 tps=309
ORACLE_SID=hsbill
              sess=25 tps=313
ORACLE_SID=hsbill sess=30 tps=321

这里我们可以看出,这台服务器的CPU性能tps值应该在310左右.


Use bonnie to Test system IO speed-www.eygle.com

Use bonnie to Test system IO speed

Last updated: Friday, 2004-09-17 11:48 Eygle

Bonnie是一款极小的测试系统IO性能的工具,源代码公开.作者主页:
http://www.textuality.com/bonnie/
你也可以点击这里下载

编译Bonnie极其简单,但是需要你安装了make及gcc (或cc)

# make
Options are "make bsd" and "make SysV" - the default is "bsd".
If you get messages about missing functions, try "make SysV."
make Bonnie
make[1]: Entering directory `/export/home/gqgai/bonnie'
cc -O     Bonnie.c   -o Bonnie
make[1]: Leaving directory `/export/home/gqgai/bonnie'

其使用手册在:

http://www.textuality.com/bonnie/advice.html

测试IO速度:

1.T3阵列速度测试(raid5)

# df -k
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/dsk/c0t0d0s0    1018382  117711  839569    13%    /
/dev/dsk/c0t0d0s6    2055705 1177602  816432    60%    /usr
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
mnttab                     0       0       0     0%    /etc/mnttab
/dev/dsk/c0t0d0s1    1448911  772148  618807    56%    /var
swap                 4770120       8 4770112     1%    /var/run
swap                 4958928  188816 4770112     4%    /tmp
/dev/dsk/c5t1d0s0    51634648 35154404 15963898    69%    /data1
/dev/dsk/c5t1d1s1    25816144 21498881 4059102    85%    /data3
/dev/dsk/c5t1d1s0    25816144 14650723 10907260    58%    /data2
/dev/dsk/c0t2d0s1    15483618 1074317 14254465     8%    /temp
/dev/dsk/c0t2d0s0    7136886 2824586 4240932    40%    /varlink
/dev/dsk/c0t2d0s5    8258597 5868224 2307788    72%    /opt
/dev/dsk/c0t2d0s7    2053605 1281342  710655    65%    /export/home
/dev/dsk/c0t2d0s6    2053605  178151 1813846     9%    /usr/local
# format
Searching for disks...done

AVAILABLE DISK SELECTIONS:
       0. c0t0d0
          /pci@1f,4000/scsi@3/sd@0,0
       1. c0t1d0
          /pci@1f,4000/scsi@3/sd@1,0
       2. c0t2d0
          /pci@1f,4000/scsi@3/sd@2,0
       3. c3t0d0
          /pci@4,4000/scsi@4/sd@0,0
       4. c3t1d0
          /pci@4,4000/scsi@4/sd@1,0
       5. c3t2d0
          /pci@4,4000/scsi@4/sd@2,0
       6. c3t3d0
          /pci@4,4000/scsi@4/sd@3,0
       7. c5t1d0
          /pci@1f,2000/SUNW,qlc@1/fp@0,0/ssd@w50020f23000083a2,0
       8. c5t1d1
          /pci@1f,2000/SUNW,qlc@1/fp@0,0/ssd@w50020f23000083a2,1
Specify disk (enter its number): ^D
# ./Bonnie -d /data1 -s 2046 -m billing-center
File '/data1/Bonnie.8273', size: 2145386496
Writing with putc()...done
Rewriting...done
Writing intelligently...done
Reading with getc()...done
Reading intelligently...adone
Seeker 2...Seeker 1...Seeker 3...start 'em...done...done...done...
              -------Sequential Output-------- ---Sequential Input-- --Random--
              -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
Machine    MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
billing- 2046 10251 87.5 32430 55.7 14048 39.5 12625 99.5 48763 67.3  61.5  8.3

简要介绍一下输出:

这里Sequential Output指写入速度,Char指按字符方式写入,Block指按块方式写入,Rewrite指顺序改写速度(也就是数据修改)
Sequential Input指读取速度

CPU,指该操作占用的CPU资源.

此处T3 Raid5的写入达到 10251 K/sec

2.本地磁盘速度

# ./Bonnie -d /opt/oracle -s 1024 -m billing-center
File '/opt/oracle/Bonnie.8545', size: 1073741824
Writing with putc()...done
Rewriting...done
Writing intelligently...done
Reading with getc()...done
Reading intelligently...done
Seeker Seeker 2...1...Seeker 3...start 'em...done...done...done...
              -------Sequential Output-------- ---Sequential Input-- --Random--
              -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
Machine    MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
billing- 1024  9582 85.0 15928 29.8  6900 20.3 11735 96.5 46098 67.2 256.6  8.8

后面会逐渐添加一些其他硬件的测试数据.

3. EMC CLARiiON CX500 测试数据

系统环境:

# /usr/platform/sun4u/sbin/prtdiag -v
System Configuration:  Sun Microsystems  sun4u Sun Fire 480R
System clock frequency: 150 MHz
Memory size: 4096 Megabytes

========================= CPUs ===============================================

          Run   E$    CPU     CPU
Brd  CPU  MHz   MB   Impl.    Mask
---  ---  ---  ----  -------  ----
 A    0   1050  8.0   US-III+  11.0
 A    2   1050  8.0   US-III+  11.0

========================= Memory Configuration ===============================

          Logical  Logical  Logical
     MC   Bank     Bank     Bank         DIMM    Interleave  Interleaved
Brd  ID   num      size     Status       Size    Factor      with
---  ---  ----     ------   -----------  ------  ----------  -----------
 A    0     0       512MB   no_status     256MB     8-way        0
 A    0     1       512MB   no_status     256MB     8-way        0
 A    0     2       512MB   no_status     256MB     8-way        0
 A    0     3       512MB   no_status     256MB     8-way        0
 A    2     0       512MB   no_status     256MB     8-way        0
 A    2     1       512MB   no_status     256MB     8-way        0
 A    2     2       512MB   no_status     256MB     8-way        0
 A    2     3       512MB   no_status     256MB     8-way        0

========================= IO Cards =========================

                    Bus  Max
 IO  Port Bus       Freq Bus  Dev,
Type  ID  Side Slot MHz  Freq Func State Name                              Model
---- ---- ---- ---- ---- ---- ---- ----- --------------------------------  ----------------------
PCI   8    B    2    33   33  2,0  ok    SUNW,XVR-100                      SUNW,375-3126
PCI   8    B    4    33   33  4,0  ok    fibre-channel-pci10df,f900.10df.+
PCI   8    B    5    33   33  5,0  ok    fibre-channel-pci10df,f900.10df.+
PCI   8    A    0    66   66  1,0  ok    pci-pci8086,b154.0/pci108e,1000   PCI-BRIDGE
PCI   8    A    0    66   66  0,0  ok    pci108e,1000-pci108e,1000.1       device on pci-bridge
PCI   8    A    0    66   66  0,1  ok    SUNW,qfe-pci108e,1001             SUNW,pci-qfe/pci-bridg+
PCI   8    A    0    66   66  1,0  ok    pci108e,1000-pci108e,1000.1       device on pci-bridge
PCI   8    A    0    66   66  1,1  ok    SUNW,qfe-pci108e,1001             SUNW,pci-qfe/pci-bridg+
PCI   8    A    0    66   66  2,0  ok    pci108e,1000-pci108e,1000.1       device on pci-bridge
PCI   8    A    0    66   66  2,1  ok    SUNW,qfe-pci108e,1001             SUNW,pci-qfe/pci-bridg+
PCI   8    A    0    66   66  3,0  ok    pci108e,1000-pci108e,1000.1       device on pci-bridge
PCI   8    A    0    66   66  3,1  ok    SUNW,qfe-pci108e,1001             SUNW,pci-qfe/pci-bridg+

=========================  Environmental Status =========================

System Temperatures (Celsius):
-------------------------------
Device          Temperature     Status
---------------------------------------
CPU0             50             OK
CPU2             52             OK
DBP0             28             OK

=================================

Front Status Panel:
-------------------
Keyswitch position: NORMAL

System LED Status:

  LOCATOR   FAULT    POWER
  -------  -------  -------
   [OFF]    [OFF]    [ ON]

=================================

Disk Status:
------------
DISK 0: [NO_FAULT]
DISK 1: [NO_FAULT]

=================================

Fan Status:
-----------

Bank             RPM    Status
----            -----   ------
CPU0             5660   [NO_FAULT]
CPU1             3896   [NO_FAULT]
CPU2             3797   [NO_FAULT]
IO0              3947   [NO_FAULT]
IO1              4166   [NO_FAULT]

=================================

Power Supplies:
---------------
Supply   Status
------   ------
PS0      [NO_FAULT]
PS1      [NO_FAULT]

=================================

========================= HW Revisions =======================================

System PROM revisions:
----------------------
OBP 4.10.8 2003/07/25 08:44

IO ASIC revisions:
------------------
         Port
Model     ID  Status Version
-------- ---- ------ -------
Schizo    8     ok      7
Schizo    9     ok      7

阵列为CLARiiON CX500,以下分别是4块盘的Raid1+0及Raid5的测试数据:

Raid1+0测试

# ./Bonnie -d /eygle -s 2046 -m jump
File '/eygle/Bonnie.460', size: 2145386496
Writing with putc()...done
Rewriting...done
Writing intelligently...done
Reading with getc()...done
Reading intelligently...done
Seeker Seeker 2...1...Seeker 3...start 'em...done...done...done...
              -------Sequential Output-------- ---Sequential Input-- --Random--
              -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
Machine    MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
jump     2046 37438 88.8 111172 63.8 75940 90.0 43495 99.7 322153 99.9 17747.8 177.5

这里EMC CX500的速度达到了,37438K/sec,比T3的性能强了很多

下面是Raid5的测试数据:

# ./Bonnie -d /eygle -s 2046 -m jump
File '/eygle/Bonnie.473', size: 2145386496
Writing with putc()...done
Rewriting...done
Writing intelligently...done
Reading with getc()...done
Reading intelligently...done
Seeker Seeker 2...1...Seeker 3...start 'em...done...done...done...
              -------Sequential Output-------- ---Sequential Input-- --Random--
              -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
Machine    MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
jump     2046 40652 95.5 106768 56.1 75673 90.9 43356 99.4 314381 99.8 17347.3 160.5

Raid5这里的字符写速度达到了40652K/sec,较Raid1+0稍快,而Block方式写Raid1+0较Raid5稍快.

实际上EMC一直强调其Raid5读写性能较Raid1+0相差无几.


Orabm: a stress test to measure CPU performance for a CPU-intensive Oracle workload

Two Stress Test Tools for Oracle DBMS:

1) Orabm: an Open Source suite to test CPU performance under a CPU-intensive Oracle workload.

2) Orastress!: a tool to generate a multi-session, multi-instance, multi-mode workload from a single command line.

by Geoff Ingram (http://linxcel.co.uk/DbCool/vb/doc/geoff.ingram@linxcel.co.uk)

© Linxcel Europe Ltd

2004

About the Author.. 3

Background Reading: the TPC-C benchmark.. 3

Introduction.. 3

Orabm... 4

Installation.. 5

How Orabm Works. 5

Orabm Command Line.. 5

Results Output.. 6

Orastress! 7

Installation.. 7

Obtaining A Key.. 7

Orastress! Command Line.. 8

Results Output.. 9

Monitoring Performance During Execution.. 10

Reference Result.. 10

Appendix A – Building Orabm and Orabmload from source.. 12

Pre-requisites. 12

To build orabmload.. 12

To build orabm... 12

About the Author

Geoff Ingram began his IT career in the 1980s after gaining a Physics degree at the University of Birmingham, UK. He has operated as a freelance Oracle consultant for several years, preceded by several years in product development at Oracle Corp, latterly as a principal software engineer. He is the author of "High Performance Oracle" (ISBN: 0471224367) published by John Wiley Inc. in August 2002:

http://www.amazon.com/exec/obidos/search-handle-url/index=books&field-author=Ingram,Geoff

Background Reading: the TPC-C benchmark

All DBAs should have at least some familiarity with the TPC-C benchmark, as Orabm and Orastress! are based on some of its facilities. The full TPC-C specification - including examples of the 5 TPC transactions and an input data generator (written in embedded SQL) - can be found at http://linxcel.co.uk/DbCool/vb/doc/www.tpc.org.

A TPC-C compliant data-loader (Orabmload) is included, that implements all the functions in the specification. This data is the basis for both Orabm and Orastress!.

Introduction

Oracle DBAs and developers often find themselves in situations where they need to measure database performance against a baseline, typically to ensure that operational improvements deliver the expected benefits or to ensure that no regression in performance has occurred as a result of changes.

The changes in question may be due to a server upgrade, an Oracle upgrade, an operating system upgrade, or something more radical like a change in operating system or server hardware vendor.

This paper describes three command line tools to facilitate basic baseline performance information capture with minimal effort:

· Orabmload: loads TPC-C compliant data into a user-chosen number of Warehouses

· Orabm: stresses the CPU and memory of an Oracle DBMS server

· Orastress!: stresses the DBMS server with a multi-session, multi-instance load

Orabmload generates the test data for both Orabm and Orastress!. It’s Open Source, and available as a Pro*C program. Appendix A includes instructions on how to build the executable from source.

These tools are not fully-fledged, all encompassing, or totally configurable. Instead they are designed to run out-of-the box and deliver results quickly, to provide a stake in the ground for the performance of a server running several different types of Oracle DBMS workload:

· CPU intensive workload - Orabm

· Mixed-workload Online Transaction Processing (OLTP) - Orastress!

· I/O intensive INSERT workload - Orastress!

· I/O intensive direct-path INSERT workload - Orastress!

Ready built executables for Windows are provided in all cases: all you need is a low end PC with Oracle9i client installed, and one or more Oracle databases (any 8i or 9i server platform) accessible by Oracle Net to get started.

Orabm transactions are based on the Stock-Level and Order-Status read-only transactions in TPC-C. By ensuring that the data fits totally in memory (through an appropriate Oracle configuration), Orabm can generate a CPU and memory intensive workload with almost zero physical I/O.

Orastress! runs in one of four possible modes, where the mode is provided through a command line parameter. These modes are described in the following table:

Command Line Arg | Description
READ | Runs the identical read-only workload as Orabm to stress CPU and memory.
OLTP | Uses all five TPC-C transactions: New-Order, Order-Status, Payment, Stock-Level and Delivery, in order to generate a mixed-transaction (SQL INSERT/UPDATE/DELETE) OLTP workload which stresses CPU, memory, and I/O.
INS | Runs an I/O intensive SQL INSERT workload by copying rows into the ITEM_INS table from the TPC-C ITEM table.
DIO | Runs an I/O intensive direct-path INSERT workload by copying rows into the ITEM_DIO table from the TPC-C ITEM table.

All tests run entirely on the database server without client-server traffic generation, and consecutive transactions run without any delay period: that’s because the goal of the tests is to stress the DBMS server. In these respects the tests differ fundamentally from TPC-C, which simulates the behavior of a real-world application with real end users who introduce thinking and data-entry time delays between transactions.

Orabm

Orabm is a set of SQL scripts and command line program (Orabm) designed to help answer the question:

"how does my server perform under a CPU/memory intensive Oracle database workload"

The code is downloadable from:

http://www.linxcel.co.uk/orabm/orabm.tar

The Orabm data loader program (Orabmload) generates a TPC-C compliant set of data against which the test runs, and orabm runs the stress test itself.

Source code for both Orabm (orabm.c) and Orabmload (orabmload.pc) is available.

Note: Ready-built executables for Oracle9i on Sun Solaris, Linux, and Windows are provided – the Windows version means you can run the entire suite from any PC, even a low-end one, where Oracle client software is installed. The database can be any Oracle database accessible by Oracle Net.

If you don't run Oracle on those platforms you can easily build your own versions from source, using instructions in Appendix A. POSIX threads support is required to build orabm, which runs multiple concurrent database sessions at once from separate threads in the same program.

The chief characteristics of a workload to meet the goal of stressing the CPUs are:

1. it runs entirely within the DBMS server thereby avoiding delays from client/server roundtrips.

2. there is no wait time between transactions

3. all transactions are read-only to avoid file-write operations

4. the set of tables which the stress test runs against fit entirely within a 200MB buffer cache

Provided that you allocate an Oracle System Global Area (SGA) with a 200MB buffer cache, the Oracle workload imposed by orabm should result in no physical I/O at all, once the data is cached - just logical I/O from the Oracle buffer cache, resulting in intensive use of CPU and memory.

Installation

All objects used by the stress test are owned by ORABM. Follow the steps below to install the objects and load the test data, making sure that ORACLE_SID is set to the database that you want to run the test against:

# | Operation | Command
1 | create the ORABM user (assumes TOOLS tablespace, TEMP temporary tablespace) | sqlplus system/pwd @orabm_user
2 | create the tables | sqlplus system/pwd @orabm_tab
3 | load the data | $ orabmload Warehouses 1
4 | create the indexes | sqlplus system/pwd @orabm_ind
5 | analyze the tables and indexes | sqlplus system/pwd @orabm_analyze
6 | create the stress-test PL/SQL procedures | sqlplus system/pwd @orabm_serverside_stress
7 | cache the table and index data in the SGA | sqlplus system/pwd @orabm_cache

Note: you can optionally run Orabmload against a remote database by first setting the environment symbol LOCAL (Windows) or TWO_TASK (UNIX/Linux) to contain an Oracle Net alias where you installed the objects. Keep in mind this will be a lot slower than running the load from the server where the database is located.

Atfer completing the list, you can use the orabm_query_cache.sql script to display the approximate percent of each table's data and index blocks present in the block buffer cache. This should be close to 100%.

How Orabm Works

Orabm works by running a user-specified number of database transactions in each of a user-specified number of concurrent database sessions. The transactions are executed by the ORABM_SERVERSIDE_STRESS stored procedure, under the schema ORABM.

For each concurrent session, ORABM_SERVERSIDE_STRESS runs the number of transactions specified on the orabm command line, and returns the transactions per second (TPS) value for that session during the sampling interval on completion. To ensure that all concurrent sessions are processing transactions during the sampling interval, the TPS value only includes results from the middle 80% of transactions: the first 10% and last 10% are ignored.

The transactions are loosely based on the TPC-C Order-Status and Stock-Level transactions, using a predefined distribution of transactions. The transaction split, which is based on data returned by the DBMS_RANDOM package, should be:

Stock-Level:Order-by-Customer-Name:Order-by-Customer-Id

50%:30%:20%

The string returned by ORABM_SERVERSIDE_STRESS includes the transaction split during the test, to ensure that the transaction distribution is correct, subject to random fluctuations e.g.:

...sl=4042(50.5%) on=2384(29.8%) oi=1573(19.7%)...

Orabm Command Line

Once you have set up the test tables, data, and indexes, you're ready to run orabm. The following command shows orabm running 20000 transactions in a single session against the Oracle database identified by ORACLE_SID in the UNIX environment:

$ orabm 1 20000

This command line runs the same workload against a remote database identified by the Oracle Net alias linxceld1.co.uk from a Windows command box:

C:\> orabm 1 20000 linxceld1.co.uk

Note: running against a remote database has little (if any), affect on the transaction throughput, because all processing takes place on the DBMS server.

Execution of a single Orabm session should show a single CPU at close to 100% utilization, provided that all table and index data is present in the Oracle block buffer cache and no other workload is running on the database server. On UNIX or Linux, you can use the “top” command to confirm this, or check that no "db file sequential read" event waits are taking place for the Oracle session using info in the V$SESSION_EVENT view - these indicate waits for physical I/O.

Alternatively, if your Oracle DBMS is running on Linux, you can use the gkrellm performance monitor to show that CPU utilization of a single CPU is at ~100% and no physical I/O is taking place. Gkrellm can be downloaded from:

http://web.wt.net/~billw/gkrellm/gkrellm.html

Here's an example of the command line you would use to run 10000 transactions against a local Oracle database for three iterations. In the first iteration, one session runs, in the second iteration two concurrent sessions run, and in the third iteration, six concurrent sessions run:

$ orabm 1,2,6 10000

Keep in mind that the specified number of transactions is run in each concurrent session.

Note: you should specify sufficient transactions such that the TPS results produced don't fluctuate significantly between runs for a given number of sessions; 100000 is a good value to choose.

Results Output

Output is appended to a log file orabm.database.log, where database is either the ORACLE_SID or TNS alias that identifies the database where the test was run e.g. orabm.t92.log. For each iteration, the TPS value for each concurrent session appears between begin and end markers. For example, the following shows the contents of the log for two concurrent sessions - in this case the second iteration for the previous command line example - where txn(all) displays the total transaction count, and xn(sam) and t(sam) show the total transactions and time for the middle 80% of transactions for which sampling took place:

---begin sess=2 txn=10000 ORACLE_SID=t92 Fri Nov 8 20:31:48 2002

T92.WORLD txn(all)=10000 xn(sam)=7999 t(sam)=44 tps=182 ...

T92.WORLD txn(all)=10000 xn(sam)=7999 t(sam)=45 tps=178 ...

---end - Fri Nov 8 20:32:46 2002

The total TPS for this iteration is the sum of the TPS for the two concurrent sessions (182+178=360). A shell script (orabm_tps.sh) can be used to process output from the log on UNIX and Linux. The script aggregates the TPS values for concurrent sessions in a single iteration into a total TPS value for that iteration. The output based on the log info from the previous command line (3 iterations with 1, then 2, then 6 concurrent sessions) shows:

$ orabm_tps.sh orabm.t92.log

ORACLE_SID=t92 sess=1 tps=182

ORACLE_SID=t92 sess=2 tps=360

ORACLE_SID=t92 sess=6 tps=364

In this example the server was a 2 CPU model - as a result, 2 concurrent sessions running in orabm are enough to completely utilize all available CPU capacity. Additional sessions should result in the total TPS remaining unchanged, or even falling slightly as the operating system performs context switches to share the overloaded CPU resource between more ready-to-run sessions than available CPUs.

Orastress!

Orastress! is a Windows command line utility and Oracle package procedure designed to help answer the question:

"how does my server perform under a wide range of Oracle DBMS workloads"

The code is downloadable from:

http://www.linxcel.co.uk/orabm/orastress.zip

Note: to run Orastress! you need a Windows PC with Oracle9i client software, and one or more Oracle instances accessible via Oracle net.

Installation

Orastress! requires the same TPC-C schema used by the Orabm CPU stress test. The schema and objects should be installed as shown in the following table.

It’s important to be aware that, while Orabm uses a TPC-C schema with a single Warehouse to ensure all data can be cached in memory, with Orastress! you can choose the number of Warehouses to be a higher value.

Note: the size of the data loaded scales with the number of Warehouses. A 10 Warehouse schema requires approximately 1GB of database space. If you already loaded data for Orabm, run the SQL “DROP USER ORABM CASCADE” first to prepare for Orastress!.

Create the ORABM schema objects, then load and analyze the data as follows:

# | Operation | Command
1 | create the ORABM user (assumes TOOLS tablespace, TEMP temporary tablespace) | sqlplus system/pwd @orabm_user
2 | create the tables | sqlplus system/pwd @orabm_tab
3 | load the data | $ orabmload Warehouses n
4 | create the indexes | sqlplus system/pwd @orabm_ind
5 | analyze the tables and indexes | sqlplus system/pwd @orabm_analyze
6 | Ensure ORABM can run the DBMS_LOCK package | As SYS run: GRANT EXECUTE ON DBMS_LOCK TO ORABM

The Orastress! workload for each session is generated by the ORABM.ORASTRESS.STRESS package procedure. To create the tables required for the Orastress! insert tests, and install the package against the database identified by <your-TNS-alias> (where you loaded the test data), run:

sqlplus orabm/orabm@<your-TNS-alias> @orastress_tab.sql

sqlplus orabm/orabm@<your-TNS-alias> @orastress.plh

sqlplus orabm/orabm@<your-TNS-alias> @orastress.plb

Obtaining A Key

By default you can run one session per database at any time. This in itself provides useful information on server performance.

You need to register and get a key to create more than one concurrent load session per database.

To get a trial key free of charge, please complete the following online form. Your trial key details will be emailed to you shortly thereafter.

http://www.linxcel.co.uk/7505/10218_trialkey_orastress!.html

Your Serial number is displayed by running Orastress! without command line arguments from a DOS command window e.g.:

C:\orabm>orastress!
Serial: D5F8-C0A0

After receiving the key, install as follows by entering the Name and Key into the dialog box that displays when you run:

C:\orabm>orastress! register

Orastress! Command Line

Orastress! contains significant enhancements over Orabm:

· it provides 4 different types of workloads.

· it can execute against multiple instances in each iteration, from the same command line.

Command line usage:

orastress! –s sess-iterations-list –t transacts-per-sess –c tns-alias-list –m mode [ -s batchsize]

where transactions-per-session in each iteration is run concurrently against all aliases in tns-alias-list

mode is one of READ OLTP INS DIO

batchsize is optional number of rows inserted per transaction for INS and DIO mode (default 10000)

Note: a COMMIT takes place after each batchsize insert in INS or DIO mode.

Note: when Orastress! runs in READ mode against a single Warehouse, the code executed is identical to Orabm.

Example 1:

orastress! –s 1 –t 50000 –c inst1.world –m oltp

Run one iteration - comprising 50000 transactions in 1 session - against inst1.world.

Example 2:

orastress! –s 2 –t 50000 –c inst1.world,inst2.world –m oltp

Run one iteration comprising 2 concurrent sessions of 50000 transactions on each of inst1.world,inst2.world giving a total of 4 concurrent sessions. The location of the instances specified by inst1.world,inst2.world is entirely down to the user. They could be:

· 2 instances of a RAC cluster

· different non RAC instances on the same server

· different non RAC instances on different servers (e.g. one on Linux, one on Solaris)

Example 3:

    orastress! –s 1,2,4 –t 50000 –c inst1,inst2,inst3,inst4 –m read

Run 3 iterations each of 50000 transactions on each of four instances: inst1, inst2, inst3 and inst4, where the number of concurrent sessions in each iteration is:

1st iteration: 1 concurrent session on each instance, giving 4 sessions total

2nd iteration: 2 concurrent sessions on each instance, giving 8 sessions total

3rd iteration: 4 concurrent sessions on each instance, giving 16 sessions

Results Output

Output is very similar to Orabm, showing the transactions per second for each session in each iteration and the transaction split between the five TPC-C transactions for OLTP mode:

---begin mode=oltp sess=1 txn=5000 TNS=l Fri Sep 19 22:11:06 2003

LXD1.WORLD #1 w=3 txn(all)=5000 xn(sam)=3999 t(sam)=431 tps=92.8 end=190903-12:25:39

---end - Fri Sep 19 22:20:19 2003

You need to add the tps= values in each iteration session to give the total tps for that iteration.

Note: the instance id is given by #1.

Monitoring Performance During Execution

Orastress! in OLTP mode enables you to monitor performance via SQL during execution as follows:

  -- use this SQL to show total Transactions/Sec (TPS) for a single instance
  select sum(substr(module,instr(module,'#')+1)) tps from
  v$session where module like 'oltp%#%';

  -- use this SQL to show total TPS per instance for RAC
  select inst_id,sum(substr(module,instr(module,'#')+1)) tps from
  gv$session where module like 'oltp%#%'
  group by inst_id

  -- use this SQL to show total TPS cluster-wide for RAC
  select sum(substr(module,instr(module,'#')+1)) tps from
  gv$session where module like 'oltp%#%'

To convey the maximum information about performance during execution, a graphical presentation of wait events and statistics is required. For example, you can use the Event Profiles and Statistic Profiles options in the Enterprise Edition free trial of empower! to show wait events and statistics for all nodes in a RAC cluster on a single display. You can download empower! from:

http://www.linxcel.co.uk/empower/software/2.1/empower!.msi

The following screenshot shows significant amounts of waits for I/O (“db file sequential read”) and row level locks (“enqueue”) during a three-session iteration of Orastress! on Red Hat Linux ES 2.1, running on a single instance:

Reference Result

The following hardware and Oracle configuration produced ~100 TPS for a single session in repeated tests:

· Oracle 9.2.0.4

· Red Hat Linux ES 2.1 kernel 2.4.9-e.12

· 1 x Pentium P4 1.4GHz processor

· 1 GB ECC RAM

· database located on 10000rpm Ultra160 18GB SCSI drive

· 10 Warehouse schema (Orabmload – 50 mins load time)

· 8K blocksize database

· 3 x 100MB redo logs

· 500K redo log buffer

TOOLS tablespace definition as follows:

CREATE TABLESPACE TOOLS BLOCKSIZE 8192

DATAFILE

  '/u03/oradata/LXD1/tools01.dbf' SIZE 2000M AUTOEXTEND ON

  NEXT 1280K MAXSIZE UNLIMITED

  ONLINE PERMANENT EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K SEGMENT SPACE MANAGEMENT AUTO

/

Tip: set the TOOLS tablespace file size to ensure no autoextend takes place during the monitored interval.

Significant Oracle initialization parameters:

db_cache_size                      268435456

db_file_multiblock_read_count      16

log_buffer                         524288

log_checkpoint_interval            0

pga_aggregate_target               25165824

shared_pool_size                   83886080

sga_max_size                       403772716

workarea_size_policy               AUTO

Appendix A – Building Orabm and Orabmload from source

If the supplied executables of orabm and orabmload don't work

for your OS or version of Oracle, you can create both from the source code.

· orabmload.pc is a Pro*C program.

· orabm.c is an OCI program.

Pre-requisites

For orabmload you need Pro*C installed (check for $ORACLE_HOME/bin/proc).

For orabmload and orabm, you need a C compiler. On Linux, gcc is available.

You can also download ready-built binaries of gcc for many other OS, including Solaris.

Note: The table and index creation scripts assume a TOOLS tablespace. For 10g this doesn’t exist by default, so you need to create it.

To build orabmload

$ cd $ORACLE_HOME/rdbms/demo

Copy orabmload.pc to this directory.

Edit demo_rdbms.mk and add orabmload to the DEMOS symbol e.g.:

DEMOS=orabmload cdemo1 …

$ make -f demo_rdbms.mk orabmload PROC=$ORACLE_HOME/bin/proc

To build orabm

$ cd $ORACLE_HOME/rdbms/demo

Copy orabm to this directory.

Edit demo_rdbms.mk and add orabm to the DEMOS symbol e.g.:

DEMOS=orabm cdemo1 …

$ make -f demo_rdbms.mk orabm


Use Orastress! to test your database-www.eygle.com

Use Orastress! to test your database

Thursday, 2004-09-30 16:16 Eygle

Orastress!的作者是Geoff Ingram,也就是我们前面介绍的orabm的作者,他曾经为Oracle工作数年,是High Performance Oracle" (ISBN: 0471224367)一书的作者.
该书现在你可以在本站下载.

关于该工具的官方网页在这里可以找到:

http://www.linxcel.co.uk/orabm/index.html

Orastress!你可以在原网站下载,或选择本地下载.

该工具不是开源的,缺省的只能使用一个session测试,你可以从作者那里申请临时Key,通过以下页面我们可以获得7天的无功能限制使用版:

http://www.linxcel.co.uk/7505/10218_trialkey_orastress!.html

Orastress!需要在windows上运行,你需要安装Oracle客户端.

收到Key以后，注册方式如下:

C:\orabm>orastress!

  Serial: D5F8-C0A0

After receiving the key, install as follows by entering the Name and Key into the dialog box that displays when you run:

C:\orabm>orastress! register

Orastress!需要的数据和orabm类似,你可以参考Orabm的安装方式.

具体安装步骤如下:

# | Operation | Command
1 | create the ORABM user (assumes TOOLS tablespace, TEMP temporary tablespace) | sqlplus system/pwd @orabm_user
2 | create the tables | sqlplus system/pwd @orabm_tab
3 | load the data | $ orabmload Warehouses n
4 | create the indexes | sqlplus system/pwd @orabm_ind
5 | analyze the tables and indexes | sqlplus system/pwd @orabm_analyze
6 | Ensure ORABM can run the DBMS_LOCK package | As SYS run: GRANT EXECUTE ON DBMS_LOCK TO ORABM

注意:这里构建的如果是10个Warehouses的数据,那么大约需要1G的空间.
这里我建议对单节点数据库分别采用1,2,3,5,10个Warehouses进行1,2,4,6,10个并发的50000个事务的测试.
对于多节点RAC建议采用1,2,3,5,10个Warehouses进行1,3,4,7,10个并发的50000个事务的测试.

这一部分安装日志可以参考:安装日志

得到测试数据以后,还需要运行如下脚本:

sqlplus orabm/orabm@<your-TNS-alias> @orastress_tab.sql
sqlplus orabm/orabm@<your-TNS-alias> @orastress.plh
sqlplus orabm/orabm@<your-TNS-alias> @orastress.plb

日志参考:windows日志

命令行执行方式如下:

orastress! –s sess-iterations-list –t transacts-per-sess –c tns-alias-list –m mode [ -s batchsize]

这里需要如下参数:
-s 指定session数量
-t 指定每个session执行的事物数量.
-c 指定联结串
-m 指定运行模式.包括Read OLTP INS DIO
-s 指定对于INS或DIO模式下提交批量,缺省是10000里

Note: 如果 Orastress! 对单个Warehouse运行在read模式，那么代码执行和orabm相同.

对于四种运行模式说明如下:

READ:Runs the identical read-only workload as Orabm to stress CPU and memory.

OLTP:Uses all five TPC-C transactions: New-Order, Order-Status, Payment, Stock-Level and Delivery, in order to generate a mixed-transaction (SQL INSERT/UPDATE/DELETE) OLTP workload which stresses CPU, memory, and I/O.

INS:Runs an I/O intensive SQL INSERT workload by copying rows into the ITEM_INS table from the TPC-C ITEM table.

DIO:Runs an I/O intensive direct-path INSERT workload by copying rows into the ITEM_DIO table from the TPC-C ITEM table.

以下是一些运行举例:

Example 1:

orastress! –s 1 –t 50000 –c inst1.world –m oltp

Run one iteration - comprising 50000 transactions in 1 session - against inst1.world.
进行一组测试,通过一个session,包含50000个事务,对inst1.world数据库进行测试.

Example 2:

orastress! –s 2 –t 50000 –c inst1.world,inst2.world –m oltp

Run one iteration comprising 2 concurrent sessions of 50000 transactions on each of inst1.world,inst2.world giving a total of 4 concurrent sessions.The location of the instances specified by inst1.world,inst2.world is entirely down to the user. They could be:
运行一组测试，对两个数据库(inst1.world,inst2.world)各发出两个并发session，每个session运行50000个事务，这两个数据库可以是:

·2 instances of a RAC cluster

·different non RAC instances on the same server

·different non RAC instances on different servers (e.g. one on Linux, one on Solaris)

Example 3:

orastress! –s 1,2,4 –t 50000 –c inst1,inst2,inst3,inst4 –m read

Run 3 iterations each of 50000 transactions on each of four instances: inst1, inst2, inst3 and inst4, where the number of concurrent sessions in each iteration is:
运行3组测试，分别以1，2，4个并发session对四个实例，各执行50000个事务:

1st iteration: 1 concurrent session on each instance, giving 4 sessions total

2nd iteration: 2 concurrent sessions on each instance, giving 8 sessions total

3rd iteration: 4 concurrent sessions on each instance, giving 16 sessions

Results Output--输出结果:

Output is very similar to Orabm, showing the transactions per second for each session in each iteration and the transaction split between the five TPC-C transactions for OLTP mode:
输出结果和orabm非常类似,具体参考:

http://www.eygle.com/special/Use.orabm.2.Test.System.CPU.htm

---begin mode=oltp sess=1 txn=5000 TNS=l Fri Sep 19 22:11:06 2003

LXD1.WORLD #1 w=3 txn(all)=5000 xn(sam)=3999 t(sam)=431 tps=92.8 end=190903-12:25:39

---end - Fri Sep 19 22:20:19 2003

在这里简单说明一下:
对于Benchmark测试来说,最重要的是标准,如果大家有统一的模型及标准,那么测试数据也就有了意义,否则以不同的并发、数据进行各不相同的测试是不具有太大意义的.
标准、比较、参考，这对于测试来说是最重要的.

这里有一篇文章可供参考:

性能测试指标介绍

以下给出我的一些测试数据:

1.10个Warehouse的测试数据

E:\OraDoc\ORACLE~4\BENCHM~1\ORASTR~1>"orastress!.exe" -s 1 -t 300 -c hsbill -m oltp
---begin mode=oltp sess=1 txn=300 TNS=hsbill Thu Sep 30 10:35:09 2004
HSBILL.HURRAY.COM.CN#1 w=3 txn(all)=300 xn(sam)=239 t(sam)=120 tps=2 d=13(5.4%) n=102(42.7%) o=6(2.5%) p=112(46.9%) s=6(2.5%) end=
300904-10:34:38
---end - Thu Sep 30 10:37:39 2004

E:\OraDoc\ORACLE~4\BENCHM~1\ORASTR~1>"orastress!.exe" -s 2 -t 300 -c hsbill -m oltp
---begin mode=oltp sess=2 txn=300 TNS=hsbill Thu Sep 30 10:41:40 2004
HSBILL.HURRAY.COM.CN#1 w=4 txn(all)=300 xn(sam)=239 t(sam)=469 tps=.5 d=12(5%) n=103(43.1%) o=13(5.4%) p=101(42.3%) s=10(4.2%) end
=300904-10:47:25
HSBILL.HURRAY.COM.CN#1 w=4 txn(all)=300 xn(sam)=239 t(sam)=314 tps=.8 d=11(4.6%) n=92(38.5%) o=10(4.2%) p=119(49.8%) s=7(2.9%) end
=300904-10:47:51
---end - Thu Sep 30 10:50:51 2004

E:\OraDoc\ORACLE~4\BENCHM~1\ORASTR~1>"orastress!.exe" -s 2 -t 3000 -c hsbill -m oltp
---begin mode=oltp sess=2 txn=3000 TNS=hsbill Thu Sep 30 11:26:02 2004
HSBILL.HURRAY.COM.CN#1 w=8 txn(all)=3000 xn(sam)=2399 t(sam)=4991 tps=.5 d=109(4.5%) n=1016(42.4%) o=116(4.8%) p=1050(43.8%) s=108
(4.5%) end=300904-13:09:23
HSBILL.HURRAY.COM.CN#1 w=4 txn(all)=3000 xn(sam)=2399 t(sam)=5432 tps=.4 d=87(3.6%) n=997(41.6%) o=128(5.3%) p=1070(44.6%) s=117(4
.9%) end=300904-13:13:50
---end - Thu Sep 30 13:16:51 2004

2.5个warehouse的测试数据

E:\OraDoc\ORACLE~4\BENCHM~1\ORASTR~1>"orastress!.exe" -s 2 -t 300 -c hsbill -m oltp
---begin mode=oltp sess=2 txn=300 TNS=hsbill Thu Sep 30 15:48:20 2004
HSBILL.HURRAY.COM.CN#1 w=2 txn(all)=300 xn(sam)=239 t(sam)=13 tps=18.4 d=7(2.9%) n=97(40.6%) o=9(3.8%) p=119(49.8%) s=7(2.9%) end=
300904-15:45:40
HSBILL.HURRAY.COM.CN#1 w=5 txn(all)=300 xn(sam)=239 t(sam)=19 tps=12.6 d=7(2.9%) n=97(40.6%) o=11(4.6%) p=112(46.9%) s=12(5%) end=
300904-15:45:47
---end - Thu Sep 30 15:48:47 2004


Linxcel Europe Limited

Home
About us
Consulting Services
empower! for Oracle
Support
Download empower!
Purchase empower!
Industry news
Recruitment
Contact

Trial key application form [orastress!]

Your trial key provides you with full access to the orastress! product functionality for a period of 10 days. Please complete the form fully. Linxcel Europe Ltd, reserves the right to refuse trial keys.

Title
Firstname Lastname
Job Title
Organisation
Address
Zip/Postal Code
State/County
Country
--
Telephone
Fax
Email
Where did you hear about orastress!
Serial Number

NOTE

Your serial number can be found in orastress! by simply typing orastress! at the command prompt without any arguments.

We can not generate keys without your unique serial number


Use bonnie++ to Test system IO speed-www.eygle.com

Use bonnie++ to Test system IO speed

Last updated: Monday, 2004-09-20 21:25 Eygle

由于Bonnie存在一些众所周知的问题,比如>2G的文件支持.
mailto:russell@coker.com.au 开发了一套新的代码,用以支持>2G的文件等.
得到mailto:tbray@textuality.com的许可之后,Russell把他的软件命名为bonnie++,在网上发布,并开始流行起来.

目前的版本已经更新到了1.03a,你可以到以下地址下载:
http://www.coker.com.au/bonnie++/
你也可以点击这里下载,这个版本需要编译,如果你没有编译环境,可以点击这里下载我编译好的,适用于SUN Solaris环境(Solaris8测试通过)

Russell Coker的个人主页是:
http://www.coker.com.au/

Bonnie++ 与 bonnie的区别主要是:
http://www.coker.com.au/bonnie++/diff.html

我简单介绍一下Bonnie++的编译及使用:

1.编译

你需要把以上下载的源码编译以后才能使用,如果你没有编译环境,可以点击这里下载我编译好的,适用于SUN Solaris环境(Solaris8测试通过)

当然你需要安装make,及gcc等必要编译器.在编译过程中,如果遇到以下错误,可能是因为你没有设置正确的环境变量

$ ./configure
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .
checking for g++... g++
checking for C++ compiler default output... a.out
checking whether the C++ compiler works... configure: error: cannot run C++ compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.

设置环境变量后继续编译,一般可以成功.

# export LD_LIBRARY_PATH=/usr/lib:/usr/local/lib
# ./configure
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .
checking for g++... g++
checking for C++ compiler default output... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for a BSD-compatible install... /usr/bin/install -c
checking for an ANSI C-conforming const... yes
checking for egrep... egrep
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... no
checking for unistd.h... yes
checking for size_t... yes
checking vector.h usability... yes
checking vector.h presence... yes
checking for vector.h... yes
checking vector usability... yes
checking vector presence... yes
checking for vector... yes
checking algorithm usability... yes
checking algorithm presence... yes
checking for algorithm... yes
checking algo.h usability... yes
checking algo.h presence... yes
checking for algo.h... yes
checking algo usability... no
checking algo presence... no
checking for algo... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating bonnie.h
config.status: creating port.h
config.status: creating bonnie++.spec
config.status: creating bon_csv2html
config.status: creating bon_csv2txt
config.status: creating sun/pkginfo
config.status: creating conf.h
config.status: conf.h is unchanged

编译完成之后会生成bonnie++,可以用来测试了.

2.下面是一些测试结果

a.T3大文件读写测试

# ./bonnie++ -d /data1 -u root -s 4096 -m billing
Using uid:0, gid:1.
Writing with putc()...done
Writing intelligently...done
Rewriting...done
Reading with getc()...done
Reading intelligently...done
start 'em...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
billing          4G  9915  87 30319  56 11685  38  9999  99 47326  66 177.6   3
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16   639  19 +++++ +++  1258  22   679  16 +++++ +++  1197  27
billing,4G,9915,87,30319,56,11685,38,9999,99,47326,66,177.6,3,16,639,19,+++++,+++,1258,22,679,16,+++++,+++,1197,27

b. EMC CLARiiON CX500 禁用写Cache的测试数据

这个是在我禁用了写Cache以后的测试数据:

4块盘的Raid1+0测试:

# ./bonnie++ -d /eygle -u root -s 4096 -m jump
Using uid:0, gid:1.
File size should be double RAM for good results, RAM is 4096M.
# ./bonnie++ -d /eygle -u root -s 8192 -m jump
Using uid:0, gid:1.
Writing with putc()...done
Writing intelligently...done
Rewriting...done
Reading with getc()...done
Reading intelligently...done
start 'em...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
jump             8G 12647  36 13414   8  7952  13 33636  97 146503  71 465.7   5
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16    86   1 +++++ +++   161   1    81   1 +++++ +++   163   1
jump,8G,12647,36,13414,8,7952,13,33636,97,146503,71,465.7,5,16,86,1,+++++,+++,161,1,81,1,+++++,+++,163,1

4块盘的Raid5,禁用写Cache后的速度:

# ./bonnie++ -d /eygle -u root -s 8192 -m jump
Using uid:0, gid:1.
Writing with putc()...done
Writing intelligently...done
Rewriting...done
Reading with getc()...done
Reading intelligently...done
start 'em...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
jump             8G 10956  30 10771   6  3388   5 34169  98 158861  75 431.1   5
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16    81   1 +++++ +++   160   1    82   1 +++++ +++   109   1
jump,8G,10956,30,10771,6,3388,5,34169,98,158861,75,431.1,5,16,81,1,+++++,+++,160,1,82,1,+++++,+++,109,1

对比这两个结果我们发现(单位K/sec):

 | 字符写 | Block写 | 字符读 | Block读
Raid10 | 12,647 | 13,414 | 33,636 | 146,503
Raid5 | 10,956 | 10,771 | 34,169 | 158,861
Diff | 1,691 | 2,643 | -533 | -12,358

我们看到,在直接读写上,写Raid10会略快于Raid5;而在读取上,Raid5会略快于Raid10,这符合我们通常的观点.

这里需要提一下的是,通常我们建议把RedoLog file存放在Raid10的磁盘上,因其具有写优势.

c.EMC CLARiiON CX500 启用1G写Cache的测试数据

这是4块盘的Raid10的测试数据:

# ./bonnie++ -d /eygle -u root -s 8192 -m jump
Using uid:0, gid:1.
Writing with putc()...done
Writing intelligently...done
Rewriting...done
Reading with getc()...done
Reading intelligently...done
start 'em...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
jump             8G 31447  90 73130  50 29123  50 33607  97 144470  71 493.5   6
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16   786  13 +++++ +++  1534  14   781  12 +++++ +++  1527  15
jump,8G,31447,90,73130,50,29123,50,33607,97,144470,71,493.5,6,16,786,13,+++++,+++,1534,14,781,12,+++++,+++,1527,15

这是4块盘的Raid5的测试数据:

# ./bonnie++ -d /eygle -u root -s 8192 -m jump
Using uid:0, gid:1.
Writing with putc()...done
Writing intelligently...done
Rewriting...done
Reading with getc()...done
Reading intelligently...done
start 'em...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
jump             8G 34620  98 103440  65 35756  61 33900  97 160964  76 495.4   6
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16   788  12 +++++ +++  1503  14   783  11 +++++ +++  1520  15
jump,8G,34620,98,103440,65,35756,61,33900,97,160964,76,495.4,6,16,788,12,+++++,+++,1503,14,783,11,+++++,+++,1520,15

我们再来对比一下这个结果(单位K/sec):

 | 字符写 | Block写 | 字符读 | Block读
Raid10 | 31,447 | 73,130 | 33,607 | 144,470
Raid5 | 34,620 | 103,440 | 33,900 | 160,964
Diff | -3,173 | -30,310 | -293 | -16,494

Raid5在启用了大的Write Cache下,性能全面超过了Raid10

3.对T3和Emc做个对比

都是4块盘的Raid5的情况下:

 | 字符写 | Block写 | 字符读 | Block读
T3 | 9,915 | 30,319 | 9,999 | 47,326
EMC | 34,620 | 103,440 | 33,900 | 160,964
Diff | -24,705 | -73,120 | -23,901 | -113,638
Emc/T3 | 3.49 | 3.41 | 3.39 | 3.40

4.对ATA Raid10的测试

开有1G Cache的测试结果:

# ./bonnie++ -d /eygle -u root -s 8192 -m jump
Using uid:0, gid:1.
Writing with putc()...done
Writing intelligently...done
Rewriting...done
Reading with getc()...done
Reading intelligently...done
start 'em...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
jump             8G 34299  97 84734  54 30960  53 33918  97 155474  74 575.0   7
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16   786  12 +++++ +++  1525  13   783  11 +++++ +++  1508  15
jump,8G,34299,97,84734,54,30960,53,33918,97,155474,74,575.0,7,16,786,12,+++++,+++,1525,13,783,11,+++++,+++,1508,15

关闭Cache后的测试数据:

# ./bonnie++ -d /eygle -u root -s 8192 -m jump
Using uid:0, gid:1.
Writing with putc()...done
Writing intelligently...done
Rewriting...done
Reading with getc()...done
Reading intelligently...done
start 'em...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
jump             8G 15587  44 16282  10  6433  10 33863  97 153921  73 538.8   6
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16    99   1 +++++ +++   161   1    91   1 +++++ +++   180   1
jump,8G,15587,44,16282,10,6433,10,33863,97,153921,73,538.8,6,16,99,1,+++++,+++,161,1,91,1,+++++,+++,180,1


Differences between Bonnie and Bonnie++

I originally started work on this project to support more than 2G of storage for the database tests. At the time I was testing hard drive performance of some Sun servers with 8G of RAM, so a 2G test file (the maximum size for 32bit code) wasn't enough to get valid results. To do this I wrote a C++ class to encapsulate the file IO and support storage in a number of 1G files with all access being through an index to the 8K block used (giving a potential for storage of 2^44 bytes of data - 16T).
Then I started playing with the Reiser file system and found that Bonnie didn't run any faster on ReiserFS than on any other file system. So I decided that it needed to test the creation of large numbers of files in a directory to be able to show how file systems such as ReiserFS outperform older file systems such as Ext2 and UFS.
After it became apparent that Tim Bray and I will probably never agree on the relative merits of C vs C++ Tim suggested that I release my code independantly under the name Bonnie++.
After I started releasing test versions which then started to become popular I began added some features based on code contributions (such as synchronization of multiple bonnie++ processes) and on request (blocking mode).

Main Bonnie++ page.

Copyright © 2000 Russell Coker, may be distributed freely.


Clone ERP系统的注意事项-eygle.com

Clone ERP系统的注意事项

作者: Eygle

简单介绍一下ERP系统Clone中的注意事项

ERP系统的Clone是比较简单的,本文简单介绍几个需要注意的问题:

1.hosts文件的配置

hosts文件中的主机及别名要注意配置,否则在post clone后会出问题

正确的示例如下:

$ cat /etc/hosts
#
# Internet host table
#
127.0.0.1       localhost
172.16.33.66    finance1.hurray.com.cn  finance1        loghost

2.启动数据库在应用层post clone

这步是必须的.

$ perl adcfgclone.pl appsTier
Please enter the APPS password:
apps

First Creating a new context file for the cloned system.
The program is going to ask you for information about the new system:

Provide the values required for creation of the new APPL_TOP Context file.

Do you want to use a virtual hostname for the target node (y/n) [n] ?:

Target system database SID [PROD]:TEST

Target system domain name [hurray.com.cn]:

Target system database server node [erp]:finance1

Does the target system have more than one application tier server node (y/n) [n] ?:

Is the target system APPL_TOP divided into multiple mount points (y/n) [n] ?:

Target system APPL_TOP mount point [/u0/oracle/prodappl]:

Target system COMMON_TOP directory [/u0/oracle/prodcomn]:

Target system 8.0.6 ORACLE_HOME directory [/u0/oracle/prodora/8.0.6]:

Target system iAS ORACLE_HOME directory [/u0/oracle/prodora/iAS]:

Location of JDK 1.3.1 on the target system [/usr/java1.3]:

The new context file has to contain port numbers related to target system.

Do you want to preserve the port values from the source system on the target system (y/n) [y] ?:n
Clone Context uses the same port pool mechanism as the Rapid Install
Once you choose a port pool, Clone Context will validate the port availability.

Enter the port pool number:[0-99]
1

Checking the port pool 1
RC-40201: Unable to connect to Database TEST.
RC-50221: Warning: Port Pool 1 is not free. Please check logfile /tmp/CloneContext_07160914.log for conflicts.

Enter the port pool number:[0-99]
1

Checking the port pool 1
done: Port Pool 1 is free
Web Listener port is 8001
Complete port information available at /u0/oracle/prodappl/admin/out/TEST_finance1/portpool.lst

UTL_FILE_DIR on database tier consists of the following directories.

1. /tmp
2. /usr/tmp
3. /u0/oracle/proddb/9.2.0/appsutil/outbound/TEST_finance1.hurray.com.cn
4. /u0/oracle/prodcomn/admin
5. /u0/oracle/prodcomn/temp
Choose a value which will be set as APPLPTMP value on the target node [1]:

Backing up /u0/oracle/prodappl/admin/TEST_finance1.xml to /u0/oracle/prodappl/admin/TEST_finance1.xml0.bak

Creating the new APPL_TOP Context file from :
/u0/oracle/prodappl/ad/11.5.0/admin/template/adxmlctx.tmp

The new APPL_TOP context file has been created :
/u0/oracle/prodappl/admin/TEST_finance1.xml

Log file located at /tmp/CloneContext_07160914.log

Running Rapid Clone with command:
perl ./adclone.pl
        java=./../jre/1.3.1 mode=apply stage=/u0/oracle/prodcomn/clone
        component=appsTier method=CUSTOM
        appctxtg=/u0/oracle/prodappl/admin/TEST_finance1.xml showProgress

Using adconfig.zip : 115.342

Beginning application tier Apply - Fri Jul 16 09:18:34 2004
Log file located at /u0/oracle/prodappl/admin/TEST_finance1/log/ApplyAppsTier_07160918.log

Completed Apply...
Fri Jul 16 10:02:09 2004

Beginning APPSIAS_TEST registration to central inventory...

ORACLE_HOME NAME : APPSIAS_TEST
ORACLE_HOME PATH : /u0/oracle/prodora/iAS
INVENTORY LOCATION : /var/opt/oracle/oraInst.loc

Log file located at /export/home/oraprod/oraInventory/logs/OracleHomeCloner_07161002.log
RC-00123: ORACLE_HOME APPSIAS_TEST already exists inside the inventory

Starting application Services for TEST:
Running:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adstrtal.sh APPS/<appspwd>

You are running adstrtal.sh version 115.11

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adapcctl.sh start
script returned:
****************************************************

adapcctl.sh version 115.34

Starting Apache Web Server Listener (dedicated HTTP) ...
Starting Apache Web Server Listener (dedicated PLSQL) ...
/u0/oracle/prodora/iAS/Apache/Apache/bin/apachectl start: httpd started

adapcctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adalnctl.sh start
script returned:
****************************************************

adalnctl.sh version

Checking for FNDFS executable.
Starting listener process APPS_TEST.

adalnctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adcmctl.sh start
script returned:
****************************************************

You are running adcmctl.sh version 115.17

Starting concurrent manager for TEST ...
Starting TEST_0716@TEST Internal Concurrent Manager
Default printer is noprint

adcmctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adfrmctl.sh start
script returned:
****************************************************

You are running adfrmctl.sh version 115.29

Starting forms server for TEST on port 9001.

adfrmctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adrepctl.sh start
script returned:
****************************************************

You are running adrepctl.sh version 115.16

starting Reports Server for TEST on port 7001.

adrepctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adfmcctl.sh start
script returned:
****************************************************

You are running adfmcctl.sh version 115.16

Starting forms load balancing client for TEST.

adfmcctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/adfmsctl.sh start
script returned:
****************************************************

You are running adfmsctl.sh version 115.12

starting forms metrics server for TEST.

adfmsctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/jtffmctl.sh start
script returned:
****************************************************

You are running jtffmctl.sh version 115.7

Starting Fulfillment Server for TEST on port 9301 ...

jtffmctl.sh: exiting with status 0

.end std out.

****************************************************

Executing service control script:
/u0/oracle/prodcomn/admin/scripts/TEST_finance1/addisctl.sh start
ascript returned:
****************************************************

addisctl.sh version 115.9

/u0/oracle/prodora/8.0.6/vbroker/bin/osagent
Started osagent.
Osagent logs messages to the file /u0/oracle/prodora/8.0.6/discwb4/util/osagent.log.
Waiting for OAD to start...
Started OAD.
OAD logs messages to the file /u0/oracle/prodora/8.0.6/discwb4/util/oad.log.
Discoverer Locator Started.
Locator logs messages to the file /u0/oracle/prodora/8.0.6/discwb4/util/locator.log.
Cannot bind to OAD. Re-starting...

OAD is stopped
Osagent is stopped
Locator is stopped
Unable to stop gatekeeper. No process-id file found.
No other discoverer processes running
/u0/oracle/prodora/8.0.6/vbroker/bin/osagent
Started osagent.
Osagent logs messages to the file /u0/oracle/prodora/8.0.6/discwb4/util/osagent.log.
Waiting for OAD to start...
Started OAD.
OAD logs messages to the file /u0/oracle/prodora/8.0.6/discwb4/util/oad.log.
Discoverer Locator Started.
Locator logs messages to the file /u0/oracle/prodora/8.0.6/discwb4/util/locator.log.
Registering Discoverer Session
oadutil reg: Failed to bind to OAD
Registering the Collector
oadutil reg: Failed to bind to OAD
Applying preferences from file : /u0/oracle/prodora/8.0.6/discwb4/util/pref.txt
Finished applying preferences

Closing down registry..
Registry File sync...
Registering Discoverer Preference Repository
oadutil reg: Failed to bind to OAD

addisctl.sh: exiting with status 1

.end std out.

****************************************************

Check logfile /u0/oracle/prodcomn/admin/log/TEST_finance1/07161002.log for details

Exiting with status 1

如果见到Exiting with status 1就说明成功了.

2004年7月16日 星期五 10:32

If you have any question,please mail to eygle@itpub.net .


Undo Internal的研究-www.eygle.com

Undo Internal的研究

Sunday, 2004-09-19 16:05 Eygle

本文就Undo的内部结构作初步探讨:

我们通过实验来看一下回滚段的内部结构.

测试脚本及过程如下:

首先创建一个测试表
create table ud ( n number );
insert into ud values(1);
insert into ud values(2);
commit;

然后执行一个事物:
select * from ud;
update ud set n=1000 where n=2;
select * from ud;

找到该事物使用的回滚段:
select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec from v$transaction;

获得回滚段名称并dump其内容:
select usn,name from v$rollname where usn=7;
alter system dump undo header '_SYSSMU7$';

以下开始测试:

SQL> create table ud ( n number );
Table created.

SQL> insert into ud values(1);
1 row created.

SQL> insert into ud values(2);
1 row created.

SQL> commit;
Commit complete.

SQL> startup force;
ORACLE instance started.

Total System Global Area   47256168 bytes
Fixed Size                   451176 bytes
Variable Size              29360128 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
SQL> select usn,writes,rssize,xacts,hwmsize,shrinks,wraps from v$rollstat;

       USN     WRITES     RSSIZE      XACTS    HWMSIZE    SHRINKS      WRAPS
---------- ---------- ---------- ---------- ---------- ---------- ----------
         0       7380     385024          0     385024          0          0
         1          0     122880          0     122880          0          0
         2          0     122880          0     122880          0          0
         3          0     122880          0     122880          0          0
         4          0     122880          0     122880          0          0
         5          0     122880          0     122880          0          0
         6          0     122880          0     122880          0          0
         7          0     122880          0     122880          0          0
         8         54     122880          0     122880          0          0
         9       9040     122880          0     122880          0          0
        10        210     122880          0     122880          0          0

11 rows selected.

SQL> select * from ud;

         N
----------
         1
         2

SQL> update ud set n=1000 where n=2;

1 row updated.

SQL> select xidusn,xidslot,xidsqn,ubablk,ubafil,ubarec from v$transaction;

    XIDUSN    XIDSLOT     XIDSQN     UBABLK     UBAFIL     UBAREC
---------- ---------- ---------- ---------- ---------- ----------
         7         35       2861        109          2         28

SQL> select usn,writes,rssize,xacts,hwmsize,shrinks,wraps from v$rollstat;

       USN     WRITES     RSSIZE      XACTS    HWMSIZE    SHRINKS      WRAPS
---------- ---------- ---------- ---------- ---------- ---------- ----------
         0       7380     385024          0     385024          0          0
         1          0     122880          0     122880          0          0
         2          0     122880          0     122880          0          0
         3          0     122880          0     122880          0          0
         4          0     122880          0     122880          0          0
         5          0     122880          0     122880          0          0
         6          0     122880          0     122880          0          0
         7        126     122880          1     122880          0          0
         8         54     122880          0     122880          0          0
         9       9040     122880          0     122880          0          0
        10        210     122880          0     122880          0          0

11 rows selected.

SQL> select usn,name from v$rollname where usn=7;

       USN NAME
---------- ------------------------------
         7 _SYSSMU7$

SQL> alter system dump undo header '_SYSSMU7$';

System altered.

SQL> @gettrcname

TRACE_FILE_NAME
--------------------------------------------------------------------------------
/opt/oracle/admin/hsjf/udump/hsjf_ora_3563.trc

找到这个trace文件:

********************************************************************************
Undo Segment:  _SYSSMU7$ (7)
********************************************************************************
  Extent Control Header
  -----------------------------------------------------------------
  Extent Header:: spare1: 0      spare2: 0      #extents: 2      #blocks: 15
                  last map  0x00000000  #maps: 0      offset: 4080
      Highwater::  0x0080006d  ext#: 0      blk#: 3      ext size: 7
  #blocks in seg. hdr's freelists: 0
  #blocks below: 0
  mapblk  0x00000000  offset: 0
                   Unlocked
     Map Header:: next  0x00000000  #extents: 2    obj#: 0      flag: 0x40000000
  Extent Map
  -----------------------------------------------------------------
   0x0080006a  length: 7
   0x008000d1  length: 8

 Retention Table
  -----------------------------------------------------------
 Extent Number:0  Commit Time: 1095324259
 Extent Number:1  Commit Time: 1095296201

  TRN CTL:: seq: 0x040d chd: 0x0025 ctl: 0x0024 inc: 0x00000000 nfb: 0x0000
            mgc: 0x8201 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
            uba: 0x0080006d.040d.1c scn: 0x0000.017e6e59
Version: 0x01
  FREE BLOCK POOL::
    uba: 0x00000000.040d.1b ext: 0x0  spc: 0x994
    uba: 0x00000000.040c.30 ext: 0x5  spc: 0xa1e
    uba: 0x00000000.040c.43 ext: 0x5  spc: 0x198
    uba: 0x00000000.03ed.01 ext: 0x0  spc: 0x1fa0
    uba: 0x00000000.0000.00 ext: 0x0  spc: 0x0
  TRN TBL::------Transaction table,也就是这个回滚段中记录的事务列表

  index  state cflags  wrap#    uel         scn            dba            parent-xid    nub     stmt_num
  ------------------------------------------------------------------------------------------------
   0x00    9    0x00  0x0b2d  0x0027  0x0000.017ea992  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x01    9    0x00  0x0b2d  0x0002  0x0000.017e9dba  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x02    9    0x00  0x0b2d  0x0004  0x0000.017ea1ad  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x03    9    0x00  0x0b2d  0x0001  0x0000.017e99c7  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x04    9    0x00  0x0b2d  0x0000  0x0000.017ea5a0  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x05    9    0x00  0x0b2d  0x000b  0x0000.017ebd50  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x06    9    0x00  0x0b2d  0x0005  0x0000.017eb95d  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x07    9    0x00  0x0b2d  0x000f  0x0000.017f1fa2  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x08    9    0x00  0x0b2d  0x0029  0x0000.017eccb8  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x09    9    0x00  0x0b2d  0x0008  0x0000.017ec8c5  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x0a    9    0x00  0x0b2d  0x0009  0x0000.017ec4d3  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x0b    9    0x00  0x0b2d  0x000a  0x0000.017ec0e0  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x0c    9    0x00  0x0b2d  0x0011  0x0000.017ed49e  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x0d    9    0x00  0x0b2d  0x0014  0x0000.017ee85b  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x0e    9    0x00  0x0b2d  0x001f  0x0000.017f000c  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x0f    9    0x00  0x0b2d  0x0024  0x0000.017f2394  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x10    9    0x00  0x0b2d  0x0013  0x0000.017edc83  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x11    9    0x00  0x0b2d  0x0010  0x0000.017ed890  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x12    9    0x00  0x0b2d  0x000d  0x0000.017ee469  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x13    9    0x00  0x0b2d  0x0012  0x0000.017ee076  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x14    9    0x00  0x0b2d  0x0017  0x0000.017eec4e  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x15    9    0x00  0x0b2c  0x0016  0x0000.017e763f  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x16    9    0x00  0x0b2c  0x002a  0x0000.017e7a31  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x17    9    0x00  0x0b2d  0x001a  0x0000.017ef041  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x18    9    0x00  0x0b2d  0x001c  0x0000.017f07f1  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x19    9    0x00  0x0b2d  0x001e  0x0000.017ef826  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x1a    9    0x00  0x0b2d  0x0019  0x0000.017ef433  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x1b    9    0x00  0x0b2d  0x0021  0x0000.017f13c9  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x1c    9    0x00  0x0b2d  0x0020  0x0000.017f0be4  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x1d    9    0x00  0x0b2c  0x0003  0x0000.017e95d5  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x1e    9    0x00  0x0b2d  0x000e  0x0000.017efc19  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x1f    9    0x00  0x0b2d  0x0018  0x0000.017f03fe  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x20    9    0x00  0x0b2d  0x001b  0x0000.017f0fd7  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x21    9    0x00  0x0b2d  0x0022  0x0000.017f17bc  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x22    9    0x00  0x0b2d  0x0007  0x0000.017f1baf  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
    |<---状态9为非活动事务.
   0x23   10    0x80  0x0b2d  0x0000  0x0000.017f73e0  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
     |	|<---状态10位活动事务.			   |<---dba,包含这个活动事务的block地址
     |<---index就是事务表中的slot号			   |dba=0x0080006d我们对之进行转换,算法参考这里.
     | v$transaction.xidslot=35转换为16进制,正是23	 	   |0x0080006d = 0000 0000 1000 0000 0000 0000 0110 1101
                                |dba 0x0080006d位于file 2,block 109上
   0x24    9    0x00  0x0b2d  0xffff  0x0000.017f2519  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x25    9    0x00  0x0b2c  0x0015  0x0000.017e724c  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x26    9    0x00  0x0b2b  0x002c  0x0000.017e860a  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x27    9    0x00  0x0b2c  0x002b  0x0000.017ead85  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x28    9    0x00  0x0b2c  0x002e  0x0000.017e8def  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x29    9    0x00  0x0b2c  0x000c  0x0000.017ed0ab  0x0080006d  0x0000.000.00000000  0x00000001   0x00000000
   0x2a    9    0x00  0x0b2c  0x002f  0x0000.017e7e24  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x2b    9    0x00  0x0b2c  0x002d  0x0000.017eb178  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x2c    9    0x00  0x0b2c  0x0028  0x0000.017e89fc  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x2d    9    0x00  0x0b2c  0x0006  0x0000.017eb56b  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x2e    9    0x00  0x0b2c  0x001d  0x0000.017e91e2  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000
   0x2f    9    0x00  0x0b2c  0x0026  0x0000.017e8217  0x0080006c  0x0000.000.00000000  0x00000001   0x00000000

alter system dump datafile 2 block 109;

********************************************************************************
Start dump data blocks tsn: 1 file#: 2 minblk 109 maxblk 109
buffer tsn: 1 rdba: 0x0080006d (2/109)
scn: 0x0000.017f73e0 seq: 0x01 flg: 0x04 tail: 0x73e00201
frmt: 0x02 chkval: 0x8fbe type: 0x02=KTU UNDO BLOCK

********************************************************************************
UNDO BLK:
xid: 0x0007.023.00000b2d  seq: 0x40d cnt: 0x1c  irb: 0x1c  icl: 0x0   flg: 0x0000
 |				      |
 |<---xid = Undo segment no.Slotno.sequence no   |
                       |<---index.rollback.begin
                       |这是回滚开始的地方,我们向下找到这个记录

 Rec Offset      Rec Offset      Rec Offset      Rec Offset      Rec Offset
---------------------------------------------------------------------------
0x01 0x1f18     0x02 0x1e48     0x03 0x1d78     0x04 0x1ca8     0x05 0x1bd8
0x06 0x1b08     0x07 0x1a38     0x08 0x1968     0x09 0x1898     0x0a 0x17c8
0x0b 0x16f8     0x0c 0x1628     0x0d 0x1558     0x0e 0x1488     0x0f 0x13b8
0x10 0x12e8     0x11 0x1218     0x12 0x1148     0x13 0x1078     0x14 0x0fa8
0x15 0x0ed8     0x16 0x0e08     0x17 0x0d38     0x18 0x0c68     0x19 0x0b98
0x1a 0x0ac8     0x1b 0x09dc     0x1c 0x0960

*-----------------------------
* Rec #0x1  slt: 0x0b  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006c.040d.26 ctl max scn: 0x0000.017e096c prv tx scn: 0x0000.017e0d5e
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.01f.00000b4b uba: 0x0080005d.04fa.01
                      flg: C---    lkc:  0     scn: 0x0000.017ec07b
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 15(0xf) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0b 2d 5b
col  1: [ 7]  78 68 09 0d 0c 2a 20
col  2: [ 1]  80
col  3: [ 5]  c4 19 5b 63 64

*-----------------------------
* Rec #0x2  slt: 0x0a  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.01 ctl max scn: 0x0000.017e0d5e prv tx scn: 0x0000.017e0dd1
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.018.00000b4b uba: 0x0080005d.04fa.02
                      flg: C---    lkc:  0     scn: 0x0000.017ec46e
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 25(0x19) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0b 4c 3d
col  1: [ 7]  78 68 09 0d 0d 21 2c
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 0a 0a

*-----------------------------
* Rec #0x3  slt: 0x09  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.02 ctl max scn: 0x0000.017e0dd1 prv tx scn: 0x0000.017e109b
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.009.00000b4b uba: 0x0080005d.04fa.03
                      flg: C---    lkc:  0     scn: 0x0000.017ec860
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 35(0x23) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0c 07 22
col  1: [ 7]  78 68 09 0d 0e 18 38
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 14 15

*-----------------------------
* Rec #0x4  slt: 0x08  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.03 ctl max scn: 0x0000.017e109b prv tx scn: 0x0000.017e148e
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.011.00000b4b uba: 0x0080005d.04fa.04
                      flg: C---    lkc:  0     scn: 0x0000.017ecc53
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 45(0x2d) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0c 26 07
col  1: [ 7]  78 68 09 0d 0f 10 08
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 1e 20

*-----------------------------
* Rec #0x5  slt: 0x29  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.04 ctl max scn: 0x0000.017e148e prv tx scn: 0x0000.017e1880
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.01a.00000b4b uba: 0x0080005d.04fa.05
                      flg: C---    lkc:  0     scn: 0x0000.017ed046
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 55(0x37) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0c 44 50
col  1: [ 7]  78 68 09 0d 10 07 14
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 28 2b

*-----------------------------
* Rec #0x6  slt: 0x0c  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.05 ctl max scn: 0x0000.017e1880 prv tx scn: 0x0000.017e1c73
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.029.00000b4b uba: 0x0080005d.04fa.06
                      flg: C---    lkc:  0     scn: 0x0000.017ed439
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 65(0x41) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0c 63 32
col  1: [ 7]  78 68 09 0d 10 3a 21
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 32 36

*-----------------------------
* Rec #0x7  slt: 0x11  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.06 ctl max scn: 0x0000.017e1c73 prv tx scn: 0x0000.017e2066
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.027.00000b4b uba: 0x0080005d.04fa.07
                      flg: C---    lkc:  0     scn: 0x0000.017ed82b
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 75(0x4b) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0d 1e 17
col  1: [ 7]  78 68 09 0d 11 31 2d
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 3c 41

*-----------------------------
* Rec #0x8  slt: 0x10  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.07 ctl max scn: 0x0000.017e2066 prv tx scn: 0x0000.017e2459
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.01d.00000b4b uba: 0x0080005d.04fa.08
                      flg: C---    lkc:  0     scn: 0x0000.017edc1e
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 85(0x55) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0d 3c 60
col  1: [ 7]  78 68 09 0d 12 28 39
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 46 4c

*-----------------------------
* Rec #0x9  slt: 0x13  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.08 ctl max scn: 0x0000.017e2459 prv tx scn: 0x0000.017e284b
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.01c.00000b4b uba: 0x0080005d.04fa.09
                      flg: C---    lkc:  0     scn: 0x0000.017ee011
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 95(0x5f) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0d 5b 45
col  1: [ 7]  78 68 09 0d 13 20 09
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 50 57

*-----------------------------
* Rec #0xa  slt: 0x12  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.09 ctl max scn: 0x0000.017e284b prv tx scn: 0x0000.017e2c3e
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.02c.00000b4b uba: 0x0080005d.04fa.0a
                      flg: C---    lkc:  0     scn: 0x0000.017ee403
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 105(0x69) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0e 16 27
col  1: [ 7]  78 68 09 0d 14 17 15
col  2: [ 1]  80
col  3: [ 5]  c4 19 5c 5a 61

*-----------------------------
* Rec #0xb  slt: 0x0d  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.0a ctl max scn: 0x0000.017e2c3e prv tx scn: 0x0000.017e3031
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.022.00000b4b uba: 0x0080005d.04fa.0b
                      flg: C---    lkc:  0     scn: 0x0000.017ee7f6
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 115(0x73) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0e 35 0c
col  1: [ 7]  78 68 09 0d 15 0e 22
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 01 08

*-----------------------------
* Rec #0xc  slt: 0x14  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.0b ctl max scn: 0x0000.017e3031 prv tx scn: 0x0000.017e3424
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.02a.00000b4b uba: 0x0080005d.04fa.0c
                      flg: C---    lkc:  0     scn: 0x0000.017eebe9
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 125(0x7d) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0e 53 55
col  1: [ 7]  78 68 09 0d 16 05 2e
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 0b 13

*-----------------------------
* Rec #0xd  slt: 0x17  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.0c ctl max scn: 0x0000.017e3424 prv tx scn: 0x0000.017e3816
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.02e.00000b4b uba: 0x0080005d.04fa.0d
                      flg: C---    lkc:  0     scn: 0x0000.017eefdc
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 135(0x87) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0f 0e 37
col  1: [ 7]  78 68 09 0d 16 38 3a
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 15 1d

*-----------------------------
* Rec #0xe  slt: 0x1a  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.0d ctl max scn: 0x0000.017e3816 prv tx scn: 0x0000.017e3c09
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.028.00000b4b uba: 0x0080005d.04fa.0e
                      flg: C---    lkc:  0     scn: 0x0000.017ef3ce
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 145(0x91) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 0f 2d 1c
col  1: [ 7]  78 68 09 0d 17 30 0a
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 1f 28

*-----------------------------
* Rec #0xf  slt: 0x19  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.0e ctl max scn: 0x0000.017e3c09 prv tx scn: 0x0000.017e3ffc
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.02f.00000b4b uba: 0x0080005d.04fa.0f
                      flg: C---    lkc:  0     scn: 0x0000.017ef7c1
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 155(0x9b) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: -1
col  0: [ 5]  c5 0b 60 0f 4c
col  1: [ 7]  78 68 09 0d 18 27 16
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 29 33

*-----------------------------
* Rec #0x10  slt: 0x1e  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.0f ctl max scn: 0x0000.017e3ffc prv tx scn: 0x0000.017e43f4
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.02b.00000b4b uba: 0x0080005d.04fa.10
                      flg: C---    lkc:  0     scn: 0x0000.017efbb4
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 165(0xa5) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 1
col  0: [ 6]  c5 0b 60 10 06 4a
col  1: [ 7]  78 68 09 0e 01 1e 23
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 33 3e

*-----------------------------
* Rec #0x11  slt: 0x0e  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.10 ctl max scn: 0x0000.017e43f4 prv tx scn: 0x0000.017e4599
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.003.00000b4c uba: 0x0080005d.04fa.11
                      flg: C---    lkc:  0     scn: 0x0000.017effa7
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 175(0xaf) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 10 25 2c
col  1: [ 7]  78 68 09 0e 02 15 2f
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 3d 48

*-----------------------------
* Rec #0x12  slt: 0x1f  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.11 ctl max scn: 0x0000.017e4599 prv tx scn: 0x0000.017e46d6
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.021.00000b4b uba: 0x0080005d.04fa.12
                      flg: C---    lkc:  0     scn: 0x0000.017f0399
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 185(0xb9) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 10 44 11
col  1: [ 7]  78 68 09 0e 03 0c 3b
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 47 53

*-----------------------------
* Rec #0x13  slt: 0x18  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.12 ctl max scn: 0x0000.017e46d6 prv tx scn: 0x0000.017e4ad0
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.000.00000b4c uba: 0x0080005d.04fa.13
                      flg: C---    lkc:  0     scn: 0x0000.017f078c
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 195(0xc3) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 10 62 5a
col  1: [ 7]  78 68 09 0e 04 04 0b
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 51 5e

*-----------------------------
* Rec #0x14  slt: 0x1c  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.13 ctl max scn: 0x0000.017e4ad0 prv tx scn: 0x0000.017e4ec3
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.026.00000b4b uba: 0x0080005d.04fa.14
                      flg: C---    lkc:  0     scn: 0x0000.017f0b7f
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 205(0xcd) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 11 1d 3f
col  1: [ 7]  78 68 09 0e 04 37 17
col  2: [ 1]  80
col  3: [ 5]  c4 19 5d 5c 06

*-----------------------------
* Rec #0x15  slt: 0x20  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.14 ctl max scn: 0x0000.017e4ec3 prv tx scn: 0x0000.017e52b6
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.002.00000b4c uba: 0x0080005d.04fa.15
                      flg: C---    lkc:  0     scn: 0x0000.017f0f72
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 215(0xd7) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 11 3c 21
col  1: [ 7]  78 68 09 0e 05 2e 24
col  2: [ 1]  80
col  3: [ 5]  c4 19 5e 02 10

*-----------------------------
* Rec #0x16  slt: 0x1b  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.15 ctl max scn: 0x0000.017e52b6 prv tx scn: 0x0000.017e56a9
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.00a.00000b4b uba: 0x0080005d.04fa.16
                      flg: C---    lkc:  0     scn: 0x0000.017f1364
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 225(0xe1) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 11 5b 06
col  1: [ 7]  78 68 09 0e 06 25 30
col  2: [ 1]  80
col  3: [ 5]  c4 19 5e 0c 1b

*-----------------------------
* Rec #0x17  slt: 0x21  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.16 ctl max scn: 0x0000.017e56a9 prv tx scn: 0x0000.017e5a9b
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.006.00000b4c uba: 0x0080005d.04fa.17
                      flg: C---    lkc:  0     scn: 0x0000.017f1757
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 235(0xeb) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 12 15 4f
col  1: [ 7]  78 68 09 0e 07 1c 3c
col  2: [ 1]  80
col  3: [ 5]  c4 19 5e 16 26

*-----------------------------
* Rec #0x18  slt: 0x22  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.17 ctl max scn: 0x0000.017e5a9b prv tx scn: 0x0000.017e5e8d
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.012.00000b4b uba: 0x0080005d.04fa.18
                      flg: C---    lkc:  0     scn: 0x0000.017f1b4a
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 245(0xf5) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 12 34 31
col  1: [ 7]  78 68 09 0e 08 14 0c
col  2: [ 1]  80
col  3: [ 5]  c4 19 5e 20 30

*-----------------------------
* Rec #0x19  slt: 0x07  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.18 ctl max scn: 0x0000.017e5e8d prv tx scn: 0x0000.017e6281
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.005.00000b4c uba: 0x0080005d.04fa.19
                      flg: C---    lkc:  0     scn: 0x0000.017f1f3d
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8d  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 255(0xff) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 12 53 16
col  1: [ 7]  78 68 09 0e 09 0b 18
col  2: [ 1]  80
col  3: [ 5]  c4 19 5e 2a 3b

*-----------------------------
* Rec #0x1a  slt: 0x0f  objn: 516(0x00000204)  objd: 514  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.19 ctl max scn: 0x0000.017e6281 prv tx scn: 0x0000.017e6673
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0006.008.00000b4c uba: 0x0080005d.04fa.1a
                      flg: C---    lkc:  0     scn: 0x0000.017f232f
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x00400e8e  hdba: 0x00400e89
itli: 2  ispac: 0  maxfr: 4863
tabn: 1 slot: 7(0x7) flag: 0x6c lock: 0 ckix: 0
ncol: 4 nnew: 4 size: 0
col  0: [ 6]  c5 0b 60 13 0d 5f
col  1: [ 7]  78 68 09 0e 0a 02 24
col  2: [ 1]  80
col  3: [ 5]  c4 19 5e 34 46

*-----------------------------
* Rec #0x1b  slt: 0x24  objn: 18(0x00000012)  objd: 18  tblspc: 0(0x00000000)
*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.1a ctl max scn: 0x0000.017e6673 prv tx scn: 0x0000.017e6a66
KDO undo record:
KTB Redo
op: 0x04  ver: 0x01
op: L  itl: xid:  0x0007.01e.00000b14 uba: 0x008000dd.03f2.1b
                      flg: C---    lkc:  0     scn: 0x0000.017cfed9
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x0040007a  hdba: 0x00400079
itli: 1  ispac: 0  maxfr: 4863
tabn: 0 slot: 33(0x21) flag: 0x2c lock: 0 ckix: 0
ncol: 17 nnew: 11 size: 0
col  0: [ 2]  c1 02
col  1: [ 4]  c3 02 3e 4e
col  6: [ 1]  80
col  7: [ 7]  78 67 07 10 04 29 0e
col  8: [ 7]  78 68 09 0f 0e 39 1a
col  9: [ 7]  78 67 07 10 04 29 0e
col 10: [ 1]  80
col 13: [ 1]  80
col 14: *NULL*
col 15: [ 1]  80
col 16: [ 4]  c3 07 38 24

*-----------------------------
* Rec #0x1c  slt: 0x23  objn: 16177(0x00003f31)  objd: 16177  tblspc: 0(0x00000000)

SQL> select object_name from dba_objects where object_id=16177;

OBJECT_NAME
--------------------------------------------------------------------------------
UD

*       Layer:  11 (Row)   opc: 1   rci 0x00
Undo type:  Regular undo    Begin trans    Last buffer split:  No
Temp Object:  No
Tablespace Undo:  No
rdba: 0x00000000
*-----------------------------
uba: 0x0080006d.040d.1b ctl max scn: 0x0000.017e6a66 prv tx scn: 0x0000.017e6e59
KDO undo record:
KTB Redo
op: 0x03  ver: 0x01
op: Z
KDO Op code: URP row dependencies Disabled
  xtype: XA  bdba: 0x0040657a  hdba: 0x00406579
itli: 2  ispac: 0  maxfr: 4863
tabn: 0 slot: 1(0x1) flag: 0x2c lock: 0 ckix: 80
ncol: 1 nnew: 1 size: 0
col  0: [ 2]  c1 03   <------这里记录的就是前镜像 c1 03就是2

End dump data blocks tsn: 1 file#: 2 minblk 109 maxblk 109

我们再来看一下数据块的变化:

SQL> select file_id,block_id from dba_extents where segment_name='UD';

   FILE_ID   BLOCK_ID
---------- ----------
         1      25977

SQL> alter system dump datafile 1 block  min 25977 block max 25979;

System altered.

查看trace内容:

Start dump data blocks tsn: 0 file#: 1 minblk 25977 maxblk 25979
buffer tsn: 0 rdba: 0x00406579 (1/25977)
scn: 0x0000.017f2520 seq: 0x01 flg: 0x04 tail: 0x25201001
frmt: 0x02 chkval: 0x1d41 type: 0x10=DATA SEGMENT HEADER - UNLIMITED
  Extent Control Header
  -----------------------------------------------------------------
  Extent Header:: spare1: 0      spare2: 0      #extents: 1      #blocks: 7
                  last map  0x00000000  #maps: 0      offset: 4128
      Highwater::  0x0040657b  ext#: 0      blk#: 1      ext size: 7
  #blocks in seg. hdr's freelists: 1
  #blocks below: 1
  mapblk  0x00000000  offset: 0
                   Unlocked
     Map Header:: next  0x00000000  #extents: 1    obj#: 16177  flag: 0x40000000
  Extent Map
  -----------------------------------------------------------------
   0x0040657a  length: 7

  nfl = 1, nfb = 1 typ = 1 nxf = 0 ccnt = 1
  SEG LST:: flg: USED   lhd: 0x0040657a ltl: 0x0040657a
buffer tsn: 0 rdba: 0x0040657a (1/25978)
scn: 0x0000.017f73e0 seq: 0x01 flg: 0x04 tail: 0x73e00601
frmt: 0x02 chkval: 0x6763 type: 0x06=trans data
Block header dump:  0x0040657a
 Object id on Block? Y
 seg/obj: 0x3f31  csc: 0x00.17f73dc  itc: 2  flg: O  typ: 1 - DATA
     fsl: 0  fnx: 0x0 ver: 0x01

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
0x01   0x0005.018.00000b53  0x0080004d.04f6.1d  C---    0  scn 0x0000.017f2521
0x02   0x0007.023.00000b2d  0x0080006d.040d.1c  ----    1  fsc 0x0000.00000000

ITL事务槽--Interested Transaction List(ITL)
ITL内容包括:
xid---Transaction ID
Uba---Undo Block Address
Lck---Lock Status

xid=Undo.Segment.Number+Transaction.Table.Slot.Number+Wrap
我们看到itl2上存在活动事务.
xid=0x0007.023.00000b2d
指向7号回滚段.Slot号为23,Wrap#为b2d,正是我们dump回滚段看到的那个事务.

uba=Address.Of.Last.Undo.Block.Used+Sequence+Last.Entry.in.UNDO.Record.Map
uba=0x0080006d.040d.1c

data_block_dump,data header at 0xadb505c
===============
tsiz: 0x1fa0
hsiz: 0x16
pbl: 0x0adb505c
bdba: 0x0040657a
     76543210
flag=--------
ntab=1
nrow=2
frre=-1
fsbo=0x16
fseo=0x1f94
avsp=0x1f78
tosp=0x1f78
0xe:pti[0]      nrow=2  offs=0
0x12:pri[0]     offs=0x1f9a
0x14:pri[1]     offs=0x1f94
block_row_dump:
tab 0, row 0, @0x1f9a
tl: 6 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 2]  c1 02
tab 0, row 1, @0x1f94
tl: 6 fb: --H-FL-- lb: 0x2  cc: 1
col  0: [ 2]  c2 0b
end_of_block_dump
buffer tsn: 0 rdba: 0x0000657b (0/25979)
scn: 0x0000.00000000 seq: 0x01 flg: 0x05 tail: 0x00000001
frmt: 0x02 chkval: 0x627b type: 0x00=unknown
Hex dump of corrupt header 4 = CORRUPT
Dump of memory from 0x0ADB5000 to 0x0ADB5014
ADB5000 00000200 0000657B 00000000 05010000  [....{e..........]
ADB5010 0000627B                             [{b..]
End dump data blocks tsn: 0 file#: 1 minblk 25977 maxblk 25979

现在我们来总结一下事务的流程:
1.分配一个回滚段
2.在回滚段事务表中分配一个事务槽
3.分配undo block
4.更新数据块上的ITL事务槽
5.把前镜像记录在undo block内
6.更改数据块的内容

由于Delayed Block Cleanout的存在,Oracle在读一个block时,如果ITL事务槽存在活动事务,那么Oracle必须根据相应的xid找到
相应的回滚段以判断事务状态.


关于shared pool的深入探讨(一)-www.eygle.com

关于shared pool的深入探讨(一)

关于shared pool的设置一直是一个争议较多的内容.
很多文章上说,shared pool设置过大会带来额外的管理上的负担，从而在某些条件下会导致性能的下降.

那么这个管理上的负担指的是什么内容呢?
本文对这个内容作一定的深入探讨.
本文只涉及一个方面,后续的文章将从其他方面继续讨论.

基础知识:

我们可以通过如下命令转储shared pool共享内存的内容:

SQL> alter session set events 'immediate trace name heapdump level 2';

Session altered.

本测试中引用的两个trace文件:

9i:

SQL> @gettrcname

TRACE_FILE_NAME
--------------------------------------------------------------------------------
/opt/oracle/admin/hsjf/udump/hsjf_ora_24983.trc

8i:

SQL> @gettrcname

TRACE_FILE_NAME
--------------------------------------------------------------------------------
/usr/oracle8/admin/guess/udump/guess_ora_22038.trc

Shared Pool通过free list管理free块,Free List按不同size划分Bucket
在Oracle8i中,不同bucket的size范围如下所示(size显示的是下边界):

oracle:/usr/oracle8/admin/guess/udump>cat guess_ora_22038.trc|grep Bucket
Bucket 0 size=44
Bucket 1 size=76
Bucket 2 size=140
Bucket 3 size=268
Bucket 4 size=524
Bucket 5 size=1036
Bucket 6 size=2060
Bucket 7 size=4108
Bucket 8 size=8204
Bucket 9 size=16396
Bucket 10 size=32780

我们注意,在这里，小于76的块都位于Bucket 0上;大于32780的块,都在Bucket 10上
初始的,数据库启动以后,shared pool多数是连续内存块
当空间分配使用以后,内存块开始被分割,碎片开始出现，Bucket列表开始变长

Oracle请求shared pool空间时，首先进入相应的Bucket进行查找
如果找不到,则转向下一个非空的bucket,获取第一个chunk
分割这个chunk,剩余部分会进入相应的Bucket,进一步增加碎片

最终的结果是,Bucket 0上的内存块会越来越多,越来越碎小
(在我这个测试的小型的数据库上,Bucket 0上的碎片已经达到9030个
而shared_pool_size设置仅为150M)
通常如果每个Bucket上的chunk多余2000个，就被认为是share pool碎片过多

而在大多数情况下,我们请求的都是相对小的chunk,这样搜索Bucket 0往往消耗了大量的时间以及资源
这可能导致share pool Latch被长时间的持有,导致更多的share pool竞争

所以在Oracle9i之前,如果盲目的增大shared_pool_size或设置过大的shared_pool_size，往往会适得其反

我们看一下Oracle9i中的处理方式:

[oracle@jumper oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Wed Aug 18 22:13:07 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> alter session set events 'immediate trace name heapdump level 2';

Session altered.

SQL> @gettrcname

TRACE_FILE_NAME
--------------------------------------------------------------------------------
/opt/oracle/admin/hsjf/udump/hsjf_ora_24983.trc

SQL>
SQL> !
[oracle@jumper oracle]$ cd $admin
[oracle@jumper udump]$ cat hsjf_ora_24983.trc|grep Bucket
Bucket 0 size=16
Bucket 1 size=20
Bucket 2 size=24
Bucket 3 size=28
Bucket 4 size=32
Bucket 5 size=36
Bucket 6 size=40
Bucket 7 size=44
Bucket 8 size=48
Bucket 9 size=52
Bucket 10 size=56
Bucket 11 size=60
Bucket 12 size=64
Bucket 13 size=68
Bucket 14 size=72
Bucket 15 size=76
Bucket 16 size=80
Bucket 17 size=84
Bucket 18 size=88
Bucket 19 size=92
Bucket 20 size=96
Bucket 21 size=100
Bucket 22 size=104
Bucket 23 size=108
Bucket 24 size=112
Bucket 25 size=116
Bucket 26 size=120
Bucket 27 size=124
Bucket 28 size=128
Bucket 29 size=132
Bucket 30 size=136
Bucket 31 size=140
Bucket 32 size=144
Bucket 33 size=148
Bucket 34 size=152
Bucket 35 size=156
Bucket 36 size=160
Bucket 37 size=164
Bucket 38 size=168
Bucket 39 size=172
Bucket 40 size=176
Bucket 41 size=180
Bucket 42 size=184
Bucket 43 size=188
Bucket 44 size=192
Bucket 45 size=196
Bucket 46 size=200
Bucket 47 size=204
Bucket 48 size=208
Bucket 49 size=212
Bucket 50 size=216
Bucket 51 size=220
Bucket 52 size=224
Bucket 53 size=228
Bucket 54 size=232
Bucket 55 size=236
Bucket 56 size=240
Bucket 57 size=244
Bucket 58 size=248
Bucket 59 size=252
Bucket 60 size=256
Bucket 61 size=260
Bucket 62 size=264
Bucket 63 size=268
Bucket 64 size=272
Bucket 65 size=276
Bucket 66 size=280
Bucket 67 size=284
Bucket 68 size=288
Bucket 69 size=292
Bucket 70 size=296
Bucket 71 size=300
Bucket 72 size=304
Bucket 73 size=308
Bucket 74 size=312
Bucket 75 size=316
Bucket 76 size=320
Bucket 77 size=324
Bucket 78 size=328
Bucket 79 size=332
Bucket 80 size=336
Bucket 81 size=340
Bucket 82 size=344
Bucket 83 size=348
Bucket 84 size=352
Bucket 85 size=356
Bucket 86 size=360
Bucket 87 size=364
Bucket 88 size=368
Bucket 89 size=372
Bucket 90 size=376
Bucket 91 size=380
Bucket 92 size=384
Bucket 93 size=388
Bucket 94 size=392
Bucket 95 size=396
Bucket 96 size=400
Bucket 97 size=404
Bucket 98 size=408
Bucket 99 size=412
Bucket 100 size=416
Bucket 101 size=420
Bucket 102 size=424
Bucket 103 size=428
Bucket 104 size=432
Bucket 105 size=436
Bucket 106 size=440
Bucket 107 size=444
Bucket 108 size=448
Bucket 109 size=452
Bucket 110 size=456
Bucket 111 size=460
Bucket 112 size=464
Bucket 113 size=468
Bucket 114 size=472
Bucket 115 size=476
Bucket 116 size=480
Bucket 117 size=484
Bucket 118 size=488
Bucket 119 size=492
Bucket 120 size=496
Bucket 121 size=500
Bucket 122 size=504
Bucket 123 size=508
Bucket 124 size=512
Bucket 125 size=516
Bucket 126 size=520
Bucket 127 size=524
Bucket 128 size=528
Bucket 129 size=532
Bucket 130 size=536
Bucket 131 size=540
Bucket 132 size=544
Bucket 133 size=548
Bucket 134 size=552
Bucket 135 size=556
Bucket 136 size=560
Bucket 137 size=564
Bucket 138 size=568
Bucket 139 size=572
Bucket 140 size=576
Bucket 141 size=580
Bucket 142 size=584
Bucket 143 size=588
Bucket 144 size=592
Bucket 145 size=596
Bucket 146 size=600
Bucket 147 size=604
Bucket 148 size=608
Bucket 149 size=612
Bucket 150 size=616
Bucket 151 size=620
Bucket 152 size=624
Bucket 153 size=628
Bucket 154 size=632
Bucket 155 size=636
Bucket 156 size=640
Bucket 157 size=644
Bucket 158 size=648
Bucket 159 size=652
Bucket 160 size=656
Bucket 161 size=660
Bucket 162 size=664
Bucket 163 size=668
Bucket 164 size=672
Bucket 165 size=676
Bucket 166 size=680
Bucket 167 size=684
Bucket 168 size=688
Bucket 169 size=692
Bucket 170 size=696
Bucket 171 size=700
Bucket 172 size=704
Bucket 173 size=708
Bucket 174 size=712
Bucket 175 size=716
Bucket 176 size=720
Bucket 177 size=724
Bucket 178 size=728
Bucket 179 size=732
Bucket 180 size=736
Bucket 181 size=740
Bucket 182 size=744
Bucket 183 size=748
Bucket 184 size=752
Bucket 185 size=756
Bucket 186 size=760
Bucket 187 size=764
Bucket 188 size=768
Bucket 189 size=772
Bucket 190 size=776
Bucket 191 size=780
Bucket 192 size=784
Bucket 193 size=788
Bucket 194 size=792
Bucket 195 size=796
Bucket 196 size=800
Bucket 197 size=804
Bucket 198 size=808
Bucket 199 size=812
Bucket 200 size=876
Bucket 201 size=940
Bucket 202 size=1004
Bucket 203 size=1068
Bucket 204 size=1132
Bucket 205 size=1196
Bucket 206 size=1260
Bucket 207 size=1324
Bucket 208 size=1388
Bucket 209 size=1452
Bucket 210 size=1516
Bucket 211 size=1580
Bucket 212 size=1644
Bucket 213 size=1708
Bucket 214 size=1772
Bucket 215 size=1836
Bucket 216 size=1900
Bucket 217 size=1964
Bucket 218 size=2028
Bucket 219 size=2092
Bucket 220 size=2156
Bucket 221 size=2220
Bucket 222 size=2284
Bucket 223 size=2348
Bucket 224 size=2412
Bucket 225 size=2476
Bucket 226 size=2540
Bucket 227 size=2604
Bucket 228 size=2668
Bucket 229 size=2732
Bucket 230 size=2796
Bucket 231 size=2860
Bucket 232 size=2924
Bucket 233 size=2988
Bucket 234 size=3052
Bucket 235 size=3116
Bucket 236 size=3180
Bucket 237 size=3244
Bucket 238 size=3308
Bucket 239 size=3372
Bucket 240 size=3436
Bucket 241 size=3500
Bucket 242 size=3564
Bucket 243 size=3628
Bucket 244 size=3692
Bucket 245 size=3756
Bucket 246 size=3820
Bucket 247 size=3884
Bucket 248 size=3948
Bucket 249 size=4012
Bucket 250 size=4108
Bucket 251 size=8204
Bucket 252 size=16396
Bucket 253 size=32780
Bucket 254 size=65548

我们看到,在Oracle9i中,Free Lists被划分为0~254,共255个Bucket
每个Bucket容纳的size范围
Bucket 0~199 容纳size以 4 递增
Bucket 200~249 容纳size以 64 递增

从Bucket 249开始,Oracle各Bucket步长进一步增加:

Bucket 249: 4012 ~4107 = 96
Bucket 250: 4108 ~8203 = 4096
Bucket 251: 8204 ~16395 = 8192
Bucket 252: 16396~32779 = 16384
Bucket 253: 32780~65547 = 32768
Bucket 254: >=65548

在Oracle9i中,对于小的chunk,Oracle增加了更多的Bucket来管理
0~199共200个Bucket,size以4为步长递增;200~249共50个Bucket,size以64递增.
这样每个Bucket中容纳的chunk数量大大减少,查找的效率得以提高.

这就是Oracle9i中shared pool管理的增强,通过这个算法的改进
Oracle8i中,过大shared pool带来的栓锁争用等性能问题在某种程度上得以解决.


关于shared pool的深入探讨(二)-www.eygle.com

关于shared pool的深入探讨(二)

Sunday, 2004-08-22 21:23 Eygle

我们继续把前面的问题展开一下.

其实我们可以从数据库内部监控shared pool的空间碎片情况.
这涉及到一个内部视图x$ksmsp

X$KSMSP的名称含义为: [K]ernal [S]torage [M]emory Management [S]GA Hea[P]
其中每一行都代表着shared pool中的一个chunk

首先记录一下测试环境：

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
PL/SQL Release 9.2.0.3.0 - Production
CORE 9.2.0.3.0 Production
TNS for Linux: Version 9.2.0.3.0 - Production
NLSRTL Version 9.2.0.3.0 - Production

我们看一下x$ksmsp的结构:

SQL> desc x$ksmsp
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ADDR                                                   RAW(4)
 INDX                                                    NUMBER
 INST_ID                                               NUMBER
 KSMCHIDX                                           NUMBER
 KSMCHDUR                                           NUMBER
 KSMCHCOM                                          VARCHAR2(16)
 KSMCHPTR                                           RAW(4)
 KSMCHSIZ                                            NUMBER
 KSMCHCLS                                           VARCHAR2(8)
 KSMCHTYP                                            NUMBER
 KSMCHPAR                                           RAW(4)

我们关注以下几个字段:

KSMCHCOM是注释字段,每个内存块被分配以后，注释会添加在该字段中.
x$ksmsp.ksmchsiz代表块大小

x$ksmsp.ksmchcls列代表类型，主要有四类，说明如下:

free
Free chunks--不包含任何对象的chunk,可以不受限制的被分配.

recr
Recreatable chunks--包含可以被临时移出内存的对象,在需要的时候，这个对象可以
被重新创建.例如,许多存储共享sql代码的内存都是可以重建的.

freeabl
Freeable chunks--包含session周期或调用的对象,随后可以被释放.这部分内存有时候
可以全部或部分提前释放.但是注意，由于某些对象是中间过程产生的，这些对象不能
临时被移出内存(因为不可重建).

perm
Permanent memory chunks--包含永久对象.通常不能独立释放.

我们可以通过查询x$ksmsp视图来考察shared pool中存在的内存片的数量
不过注意:Oracle的某些版本(如:10.1.0.2)在某些平台上(如:HP-UX PA-RISC 64-bit)查
询该视图可能导致过度的CPU耗用,这是由于bug引起的.

我们看一下测试:

初始启动数据库,x$ksmsp中存在2259个chunk

SQL> select count(*) from x$ksmsp;

  COUNT(*)
----------
      2259

执行查询:

SQL> select count(*) from dba_objects;

  COUNT(*)
----------
     10491

此时shared pool中的chunk数量增加

SQL> select count(*) from x$ksmsp;

  COUNT(*)
----------
      2358

这就是由于shared pool中进行sql解析，请求空间，进而导致请求free空间,分配、分割
从而产生了更多，更细碎的内存chunk

由此我们可以看出，如果数据库系统中存在大量的硬解析，不停请求分配free的shred pool内存
除了必须的shared pool latch等竞争外，还不可避免的会导致shared pool中产生更多的内存碎片
(当然，在内存回收时，你可能看到chunk数量减少的情况)

我们看以下测试:

首先重新启动数据库:

SQL> startup force;
ORACLE instance started.

Total System Global Area   47256168 bytes
Fixed Size                          451176 bytes
Variable Size                      29360128 bytes
Database Buffers               16777216 bytes
Redo Buffers                      667648 bytes
Database mounted.
Database opened.

创建一张临时表用以保存之前x$ksmsp的状态:

SQL> CREATE GLOBAL TEMPORARY TABLE e$ksmsp ON COMMIT PRESERVE ROWS AS
  2  SELECT      a.ksmchcom,
  3           SUM (a.CHUNK) CHUNK,
  4           SUM (a.recr) recr,
  5           SUM (a.freeabl) freeabl,
  6           SUM (a.SUM) SUM
  7      FROM (SELECT   ksmchcom, COUNT (ksmchcom) CHUNK,
  8                     DECODE (ksmchcls, 'recr', SUM (ksmchsiz), NULL) recr,
  9                     DECODE (ksmchcls, 'freeabl', SUM (ksmchsiz), NULL) freeabl,
 10                     SUM (ksmchsiz) SUM
 11                FROM x$ksmsp GROUP BY ksmchcom, ksmchcls) a
 12  where 1 = 0
 13  GROUP BY a.ksmchcom;

Table created.

保存当前shared pool状态:

SQL> INSERT INTO E$KSMSP
  2  SELECT      a.ksmchcom,
  3           SUM (a.CHUNK) CHUNK,
  4           SUM (a.recr) recr,
  5           SUM (a.freeabl) freeabl,
  6           SUM (a.SUM) SUM
  7      FROM (SELECT   ksmchcom, COUNT (ksmchcom) CHUNK,
  8                     DECODE (ksmchcls, 'recr', SUM (ksmchsiz), NULL) recr,
  9                     DECODE (ksmchcls, 'freeabl', SUM (ksmchsiz), NULL) freeabl,
 10                     SUM (ksmchsiz) SUM
 11                FROM x$ksmsp
 12            GROUP BY ksmchcom, ksmchcls) a
 13  GROUP BY a.ksmchcom
 14  /

41 rows created.

执行查询:

SQL> select count(*) from dba_objects;

  COUNT(*)
----------
     10492

比较前后shared pool内存分配的变化:

SQL> select a.ksmchcom,a.chunk,a.sum,b.chunk,b.sum,(a.chunk - b.chunk) c_diff,(a.sum -b.sum) s_diff
  2  from
  3  (SELECT   a.ksmchcom,
  4           SUM (a.CHUNK) CHUNK,
  5           SUM (a.recr) recr,
  6           SUM (a.freeabl) freeabl,
  7           SUM (a.SUM) SUM
  8      FROM (SELECT   ksmchcom, COUNT (ksmchcom) CHUNK,
  9                     DECODE (ksmchcls, 'recr', SUM (ksmchsiz), NULL) recr,
 10                     DECODE (ksmchcls, 'freeabl', SUM (ksmchsiz), NULL) freeabl,
 11                     SUM (ksmchsiz) SUM
 12                FROM x$ksmsp
 13            GROUP BY ksmchcom, ksmchcls) a
 14  GROUP BY a.ksmchcom) a,e$ksmsp b
 15  where a.ksmchcom = b.ksmchcom and (a.chunk - b.chunk) <>0
 16  /

KSMCHCOM              CHUNK        SUM      CHUNK        SUM     C_DIFF     S_DIFF
---------------- ---------- ---------- ---------- ---------- ---------- ----------
KGL handles             313     102080        302      98416         11       3664
KGLS heap               274     365752        270     360424          4       5328
KQR PO                    389     198548        377     192580         12       5968
free memory              93    2292076         90    2381304          3     -89228
library cache          1005     398284        965     381416         40      16868
sql area                   287     547452        269     490052         18      57400

6 rows selected.

我们简单分析一下以上结果:
首先free memory的大小减少了89228(增加到另外五个组件中),这说明sql解析存储占用了一定的内存空间
而chunk从90增加为93，这说明内存碎片增加了.

在下面的部分中,我会着手介绍一下KGL handles, KGLS heap这两个非常重要的shared pool中的内存结构.


关于shared pool的深入探讨(三)-www.eygle.com

关于shared pool的深入探讨(三)

Thursday, 2004-09-09 10:26 Eygle

基本命令：

ALTER SESSION SET EVENTS 'immediate trace name LIBRARY_CACHE level LL';

其中LL代表Level级别,对于9.2.0及以后版本,不同Level含义如下:
Level =1 ,转储Library cache统计信息
Level =2 ,转储hash table概要
Level =4 ,转储Library cache对象，只包含基本信息
Level =8 ,转储Library cache对象，包含详细信息(包括child references,pin waiters等)
Level =16,增加heap sizes信息
Level =32,增加heap信息

Library cache由一个hash表组成,而hash表是一个由hash buckets组成的数组.

每个hash bucket都是包含library cache handle的一个双向链表。
Library Cache Handle指向Library Cache Object和一个引用列表.
library cache对象进一步分为:依赖表、子表和授权表等

我们看一下library cache的结构:

通过
ALTER SESSION SET EVENTS 'immediate trace name LIBRARY_CACHE level 4'
获得以下输出(这部分信息来自Oracle8i,Trace文件可以从http://www.eygle.com/上找到)

点击这里下载: hsbi_ora_4614.trc

第一部分(等价于Level 1):

LIBRARY CACHE STATISTICS:
      gets hit ratio       pins hit ratio    reloads   invalids namespace
---------- --------- ---------- --------- ---------- ---------- ---------
 619658171 0.9999160 2193292112 0.9999511       9404        380 CRSR
  79698558 0.9998832  424614847 0.9999108      13589          0 TABL/PRCD/TYPE
    163399 0.9979926     163402 0.9978948         16          0 BODY/TYBD
         0 0.0000000          0 0.0000000          0          0 TRGR
        34 0.0294118         35 0.0571429          0          0 INDX
     18948 0.9968862      24488 0.9953855          0          0 CLST
         0 0.0000000          0 0.0000000          0          0 OBJE
         0 0.0000000          0 0.0000000          0          0 PIPE
         0 0.0000000          0 0.0000000          0          0 LOB
         0 0.0000000          0 0.0000000          0          0 DIR
         0 0.0000000          0 0.0000000          0          0 QUEU
         0 0.0000000          0 0.0000000          0          0 OBJG
         0 0.0000000          0 0.0000000          0          0 PROP
         0 0.0000000          0 0.0000000          0          0 JVSC
         0 0.0000000          0 0.0000000          0          0 JVRE
         0 0.0000000          0 0.0000000          0          0 ROBJ
         0 0.0000000          0 0.0000000          0          0 REIP
         0 0.0000000          0 0.0000000          0          0 CPOB
    115071 0.9992179     115071 0.9930999        704          0 EVNT
         0 0.0000000          0 0.0000000          0          0 SUMM
         0 0.0000000          0 0.0000000          0          0 DIMN
         0 0.0000000          0 0.0000000          0          0 CTX
         0 0.0000000          0 0.0000000          0          0 OUTL
         0 0.0000000          0 0.0000000          0          0 RULS
         0 0.0000000          0 0.0000000          0          0 RMGR
         0 0.0000000          0 0.0000000          0          0 UNUSED
         0 0.0000000          0 0.0000000          0          0 PPLN
         0 0.0000000          0 0.0000000          0          0 PCLS
         0 0.0000000          0 0.0000000          0          0 SUBS
         0 0.0000000          0 0.0000000          0          0 LOCS
         0 0.0000000          0 0.0000000          0          0 RMOB
         0 0.0000000          0 0.0000000          0          0 RSMD
 699654181 0.9999117 2618209955 0.9999440      23713        380 CUMULATIVE

这部分信息也就是v$librarycache中显示的.

第二部分(等价于Level 2中的输出):

LIBRARY CACHE HASH TABLE: size=509 count=354
BUCKET    0:
BUCKET    1:
BUCKET    2: *
BUCKET    3:
BUCKET    4:
BUCKET    5: *
BUCKET    6: *
BUCKET    7:
BUCKET    8: **
BUCKET    9: ***
BUCKET   10: *
BUCKET   11: *
BUCKET   12: ***
BUCKET   13: *
BUCKET   14: *
BUCKET   15:
BUCKET   16: *
BUCKET   17:
BUCKET   18: *
BUCKET   19:
BUCKET   20:
BUCKET   21: *
BUCKET   22:
BUCKET   23:
BUCKET   24: *
BUCKET   25:
BUCKET   26:
BUCKET   27: ***
BUCKET   28:
BUCKET   29: **
BUCKET   30:
BUCKET   31:
BUCKET   32: ***
BUCKET   33: *
BUCKET   34:
BUCKET   35:
BUCKET   36: **
BUCKET   37:
BUCKET   38: **
BUCKET   39: *
BUCKET   40: *
BUCKET   41:
BUCKET   42:
BUCKET   43:
BUCKET   44:
BUCKET   45:
BUCKET   46: ****
BUCKET   47:
BUCKET   48:
BUCKET   49: *
BUCKET   50: *
BUCKET   51:
BUCKET   52: ***
BUCKET   53: **
BUCKET   54:
BUCKET   55: *
BUCKET   56:
BUCKET   57:
BUCKET   58:
BUCKET   59: *
BUCKET   60: **
BUCKET   61:
BUCKET   62: *
BUCKET   63:
BUCKET   64: *
BUCKET   65:
BUCKET   66:
BUCKET   67: *
BUCKET   68:
BUCKET   69: **
BUCKET   70:
BUCKET   71:
BUCKET   72: *
BUCKET   73:
BUCKET   74:
BUCKET   75: *
BUCKET   76: **
BUCKET   77:
BUCKET   78: ****
BUCKET   79:
BUCKET   80: *
BUCKET   81: *
BUCKET   82:
BUCKET   83: **
BUCKET   84: *
BUCKET   85:
BUCKET   86:
BUCKET   87:
BUCKET   88:
BUCKET   89: *
BUCKET   90: *
BUCKET   91:
BUCKET   92: *
BUCKET   93: *
BUCKET   94: *
BUCKET   95:
BUCKET   96: *
BUCKET   97:
BUCKET   98:
BUCKET   99: ***
BUCKET  100: *
BUCKET  101:
BUCKET  102: *
BUCKET  103:
BUCKET  104: *
BUCKET  105:
BUCKET  106:
BUCKET  107: ****
BUCKET  108:
BUCKET  109:
BUCKET  110:
BUCKET  111: *
BUCKET  112: **
BUCKET  113:
BUCKET  114:
BUCKET  115:
BUCKET  116: *
BUCKET  117:
BUCKET  118: *****
BUCKET  119:
BUCKET  120: *
BUCKET  121:
BUCKET  122:
BUCKET  123:
BUCKET  124:
BUCKET  125: *
BUCKET  126:
BUCKET  127:
BUCKET  128: *
BUCKET  129:
BUCKET  130: *
BUCKET  131: *
BUCKET  132:
BUCKET  133:
BUCKET  134:
BUCKET  135: *
BUCKET  136:
BUCKET  137:
BUCKET  138:
BUCKET  139: *
BUCKET  140: *
BUCKET  141: *
BUCKET  142:
BUCKET  143: *
BUCKET  144:
BUCKET  145: ***
BUCKET  146:
BUCKET  147: *
BUCKET  148:
BUCKET  149:
BUCKET  150: **
BUCKET  151:
BUCKET  152:
BUCKET  153: *
BUCKET  154:
BUCKET  155:
BUCKET  156:
BUCKET  157:
BUCKET  158:
BUCKET  159:
BUCKET  160:
BUCKET  161:
BUCKET  162:
BUCKET  163:
BUCKET  164: *
BUCKET  165: *
BUCKET  166:
BUCKET  167:
BUCKET  168:
BUCKET  169:
BUCKET  170: **
BUCKET  171:
BUCKET  172: *
BUCKET  173:
BUCKET  174:
BUCKET  175: *
BUCKET  176: *
BUCKET  177:
BUCKET  178:
BUCKET  179:
BUCKET  180:
BUCKET  181: *
BUCKET  182:
BUCKET  183:
BUCKET  184:
BUCKET  185: *
BUCKET  186:
BUCKET  187:
BUCKET  188: **
BUCKET  189:
BUCKET  190: *
BUCKET  191: *
BUCKET  192:
BUCKET  193:
BUCKET  194: *
BUCKET  195: **
BUCKET  196: *
BUCKET  197: **
BUCKET  198: ****
BUCKET  199: *
BUCKET  200: *
BUCKET  201: *
BUCKET  202: **
BUCKET  203:
BUCKET  204:
BUCKET  205: **
BUCKET  206:
BUCKET  207:
BUCKET  208: *
BUCKET  209: **
BUCKET  210:
BUCKET  211: *
BUCKET  212: *
BUCKET  213: *
BUCKET  214:
BUCKET  215:
BUCKET  216:
BUCKET  217: *
BUCKET  218: *
BUCKET  219:
BUCKET  220:
BUCKET  221: *
BUCKET  222:
BUCKET  223: *
BUCKET  224:
BUCKET  225:
BUCKET  226: *
BUCKET  227:
BUCKET  228: *
BUCKET  229: **
BUCKET  230: *
BUCKET  231:
BUCKET  232: **
BUCKET  233:
BUCKET  234: *
BUCKET  235: *
BUCKET  236:
BUCKET  237:
BUCKET  238: *
BUCKET  239:
BUCKET  240: **
BUCKET  241: **
BUCKET  242: **
BUCKET  243: ***
BUCKET  244:
BUCKET  245: *
BUCKET  246:
BUCKET  247:
BUCKET  248: **
BUCKET  249:
BUCKET  250:
BUCKET  251: **
BUCKET  252:
BUCKET  253: *
BUCKET  254: *
BUCKET  255:
BUCKET  256:
BUCKET  257: **
BUCKET  258: *
BUCKET  259:
BUCKET  260:
BUCKET  261: *
BUCKET  262: **
BUCKET  263: ***
BUCKET  264:
BUCKET  265: *
BUCKET  266:
BUCKET  267: *
BUCKET  268: *
BUCKET  269:
BUCKET  270:
BUCKET  271: **
BUCKET  272: *
BUCKET  273:
BUCKET  274: *
BUCKET  275: *
BUCKET  276: **
BUCKET  277:
BUCKET  278:
BUCKET  279:
BUCKET  280:
BUCKET  281: **
BUCKET  282: *
BUCKET  283: *
BUCKET  284: *
BUCKET  285: *
BUCKET  286:
BUCKET  287: *
BUCKET  288:
BUCKET  289:
BUCKET  290: **
BUCKET  291:
BUCKET  292: *
BUCKET  293:
BUCKET  294: *
BUCKET  295:
BUCKET  296: *
BUCKET  297:
BUCKET  298:
BUCKET  299: **
BUCKET  300: *
BUCKET  301:
BUCKET  302: *
BUCKET  303: *
BUCKET  304: **
BUCKET  305: **
BUCKET  306:
BUCKET  307:
BUCKET  308: *
BUCKET  309:
BUCKET  310:
BUCKET  311: **
BUCKET  312: *
BUCKET  313:
BUCKET  314: *
BUCKET  315:
BUCKET  316:
BUCKET  317:
BUCKET  318:
BUCKET  319: ***
BUCKET  320: *
BUCKET  321: **
BUCKET  322: **
BUCKET  323:
BUCKET  324: *
BUCKET  325:
BUCKET  326: *
BUCKET  327: *
BUCKET  328: **
BUCKET  329:
BUCKET  330: *
BUCKET  331:
BUCKET  332:
BUCKET  333: *
BUCKET  334: *
BUCKET  335: ***
BUCKET  336: *
BUCKET  337: **
BUCKET  338: *
BUCKET  339: *
BUCKET  340:
BUCKET  341: *
BUCKET  342: *
BUCKET  343: **
BUCKET  344:
BUCKET  345:
BUCKET  346:
BUCKET  347: *
BUCKET  348:
BUCKET  349: ***
BUCKET  350: *
BUCKET  351:
BUCKET  352:
BUCKET  353:
BUCKET  354: *
BUCKET  355: **
BUCKET  356:
BUCKET  357:
BUCKET  358: **
BUCKET  359: *
BUCKET  360: *
BUCKET  361: **
BUCKET  362:
BUCKET  363:
BUCKET  364: *
BUCKET  365: *
BUCKET  366: **
BUCKET  367: *
BUCKET  368:
BUCKET  369: *
BUCKET  370:
BUCKET  371: ***
BUCKET  372:
BUCKET  373: *
BUCKET  374:
BUCKET  375:
BUCKET  376: *
BUCKET  377:
BUCKET  378:
BUCKET  379:
BUCKET  380:
BUCKET  381:
BUCKET  382:
BUCKET  383: **
BUCKET  384:
BUCKET  385:
BUCKET  386:
BUCKET  387: ***
BUCKET  388: *
BUCKET  389:
BUCKET  390:
BUCKET  391:
BUCKET  392:
BUCKET  393: *
BUCKET  394: *
BUCKET  395: *
BUCKET  396:
BUCKET  397:
BUCKET  398:
BUCKET  399:
BUCKET  400: **
BUCKET  401:
BUCKET  402:
BUCKET  403:
BUCKET  404:
BUCKET  405:
BUCKET  406:
BUCKET  407: *
BUCKET  408: *
BUCKET  409: *
BUCKET  410:
BUCKET  411: *
BUCKET  412:
BUCKET  413:
BUCKET  414:
BUCKET  415:
BUCKET  416: *
BUCKET  417:
BUCKET  418: *
BUCKET  419:
BUCKET  420: **
BUCKET  421: *
BUCKET  422:
BUCKET  423: **
BUCKET  424: ***
BUCKET  425:
BUCKET  426: *
BUCKET  427: *
BUCKET  428: **
BUCKET  429:
BUCKET  430:
BUCKET  431:
BUCKET  432:
BUCKET  433: *
BUCKET  434:
BUCKET  435: **
BUCKET  436: *
BUCKET  437: *
BUCKET  438:
BUCKET  439: *
BUCKET  440:
BUCKET  441:
BUCKET  442:
BUCKET  443: *
BUCKET  444:
BUCKET  445: *
BUCKET  446:
BUCKET  447: *
BUCKET  448:
BUCKET  449: *
BUCKET  450:
BUCKET  451:
BUCKET  452: *
BUCKET  453: *
BUCKET  454: *
BUCKET  455:
BUCKET  456:
BUCKET  457:
BUCKET  458: *
BUCKET  459: **
BUCKET  460:
BUCKET  461: **
BUCKET  462: *
BUCKET  463:
BUCKET  464: *
BUCKET  465: *
BUCKET  466:
BUCKET  467:
BUCKET  468:
BUCKET  469: *
BUCKET  470: *
BUCKET  471:
BUCKET  472: **
BUCKET  473: **
BUCKET  474:
BUCKET  475:
BUCKET  476:
BUCKET  477: *
BUCKET  478:
BUCKET  479: *
BUCKET  480: *
BUCKET  481: ***
BUCKET  482: **
BUCKET  483:
BUCKET  484:
BUCKET  485: **
BUCKET  486: **
BUCKET  487:
BUCKET  488: *
BUCKET  489: *
BUCKET  490:
BUCKET  491: **
BUCKET  492: *
BUCKET  493:
BUCKET  494:
BUCKET  495: *
BUCKET  496:
BUCKET  497:
BUCKET  498:
BUCKET  499:
BUCKET  500: ***
BUCKET  501:
BUCKET  502: *
BUCKET  503: *
BUCKET  504: *
BUCKET  505:
BUCKET  506: *
BUCKET  507:
BUCKET  508:
BUCKET  509:
BUCKET  510:
BUCKET  511:

在Oracle8i中,Oracle以一个很长的LIBRARY CACHE HASH TABLE来记录Library Cache的使用情况
"*"代表该Bucket中包含的对象的个数

在以上输出中我们看到Bucket 198中包含四个对象.

我们在第三部分中可以找到bucket 198:

BUCKET 198:
  LIBRARY OBJECT HANDLE: handle=2c2b4ac4
  name=
SELECT a.statement_id, a.timestamp, a.remarks, a.operation, a.options,
       a.object_node, a.object_owner, a.object_name, a.object_instance,
       a.object_type, a.optimizer, a.search_columns, a.id, a.parent_id,
       a.position, a.cost, a.cardinality, a.bytes, a.other_tag,
       a.partition_start, a.partition_stop, a.partition_id, a.other,
       a.distribution
, ROWID
  FROM plan_table a
  hash=60dd47a1 timestamp=08-27-2004 10:19:28
  namespace=CRSR flags=RON/TIM/PN0/LRG/[10010001]
  kkkk-dddd-llll=0000-0001-0001 lock=0 pin=0 latch=0
  lwt=2c2b4adc[2c2b4adc,2c2b4adc] ltm=2c2b4ae4[2c2b4ae4,2c2b4ae4]
  pwt=2c2b4af4[2c2b4af4,2c2b4af4] ptm=2c2b4b4c[2c2b4b4c,2c2b4b4c]
  ref=2c2b4acc[2c2b4acc,2c2b4acc]
    LIBRARY OBJECT: object=2c0b1430
    type=CRSR flags=EXS[0001] pflags= [00] status=VALD load=0
    CHILDREN: size=16
    child#    table reference   handle
    ------ -------- --------- --------
         0 2c0b15ec  2c0b15b4 2c2c0d50
    DATA BLOCKS:
    data#     heap  pointer status pins change
    ----- -------- -------- ------ ---- ------
        0 2c362290 2c0b14b4 I/-/A     0 NONE
  LIBRARY OBJECT HANDLE: handle=2c3675d4
  name=SYS.DBMS_STANDARD
  hash=50748ddb timestamp=NULL
  namespace=BODY/TYBD flags=TIM/SML/[02000000]
  kkkk-dddd-llll=0000-0011-0011 lock=0 pin=0 latch=0
  lwt=2c3675ec[2c3675ec,2c3675ec] ltm=2c3675f4[2c3675f4,2c3675f4]
  pwt=2c367604[2c367604,2c367604] ptm=2c36765c[2c36765c,2c36765c]
  ref=2c3675dc[2c3675dc,2c3675dc]
    LIBRARY OBJECT: object=2c1528e8
    flags=NEX[0002] pflags= [00] status=VALD load=0
    DATA BLOCKS:
    data#     heap  pointer status pins change
    ----- -------- -------- ------ ---- ------
        0 2c367564 2c1529cc I/-/A     0 NONE
        4 2c15297c        0 -/P/-     0 NONE
  LIBRARY OBJECT HANDLE: handle=2c347dd8
  name=select pos#,intcol#,col#,spare1 from icol$ where obj#=:1
  hash=fa15ebe3 timestamp=07-28-2004 18:04:43
  namespace=CRSR flags=RON/TIM/PN0/SML/[12010000]
  kkkk-dddd-llll=0000-0001-0001 lock=0 pin=0 latch=0
  lwt=2c347df0[2c347df0,2c347df0] ltm=2c347df8[2c347df8,2c347df8]
  pwt=2c347e08[2c347e08,2c347e08] ptm=2c347e60[2c347e60,2c347e60]
  ref=2c347de0[2c347de0,2c347de0]
    LIBRARY OBJECT: object=2c1cd1a0
    type=CRSR flags=EXS[0001] pflags= [00] status=VALD load=0
    CHILDREN: size=16
    child#    table reference   handle
    ------ -------- --------- --------
         0 2c1cd35c  2c1cd324 2c281678
         1 2c1cd35c  2c352c50 2c0eeb8c
         2 2c1cd35c  2c352c6c 2c2bb05c
    DATA BLOCKS:
    data#     heap  pointer status pins change
    ----- -------- -------- ------ ---- ------
        0 2c2e8c58 2c1cd224 I/-/A     0 NONE
  LIBRARY OBJECT HANDLE: handle=2c3a6484
  name=SYS.TS$
  hash=bb42852e timestamp=04-24-2002 00:04:15
  namespace=TABL/PRCD/TYPE flags=PKP/TIM/KEP/SML/[02900000]
  kkkk-dddd-llll=0111-0111-0119 lock=0 pin=0 latch=0
  lwt=2c3a649c[2c3a649c,2c3a649c] ltm=2c3a64a4[2c3a64a4,2c3a64a4]
  pwt=2c3a64b4[2c3a64b4,2c3a64b4] ptm=2c3a650c[2c3a650c,2c3a650c]
  ref=2c3a648c[2c0d4b14,2c09353c]
    LIBRARY OBJECT: object=2c3a626c
    type=TABL flags=EXS/LOC[0005] pflags= [00] status=VALD load=0
    DATA BLOCKS:
    data#     heap  pointer status pins change
    ----- -------- -------- ------ ---- ------
        0 2c3a8ea4 2c3a63b0 I/P/A     0 NONE
        3 2c3a5828        0 -/P/-     0 NONE
        4 2c3a6300 2c3a5960 I/P/A     0 NONE
        8 2c3a6360 2c3a4f00 I/P/A     0 NONE

我们看到这里包含了四个对象.

我们再来看看Oracle9i中的情况:

参考文件: hsjf_ora_15800.trc

LIBRARY CACHE HASH TABLE: size=131072 count=217
Buckets with more than 20 objects:
NONE
Hash Chain Size     Number of Buckets
---------------     -----------------
              0                130855
              1                   217
              2                     0
              3                     0
              4                     0
              5                     0
              6                     0
              7                     0
              8                     0
              9                     0
             10                     0
             11                     0
             12                     0
             13                     0
             14                     0
             15                     0
             16                     0
             17                     0
             18                     0
             19                     0
             20                     0
            >20                     0

Oracle9i中通过新的方式记录Library Cache的使用状况.
按不同的Hash Chain Size代表Library Cache中包含不同对象的个数.
0表示Free的Bucket,>20表示包含超过20个对象的Bucket的个数.

从以上列表中我们看到,包含一个对象的Buckets有217个,包含0个对象的Buckets有130855个.

我们来验证一下:

  [oracle@jumper udump]$ cat hsjf_ora_15800.trc |grep BUCKET|more
  BUCKET 12:
  BUCKET 12 total object count=1
  BUCKET 385:
  BUCKET 385 total object count=1
  BUCKET 865:
  BUCKET 865 total object count=1
  ...

  [oracle@jumper udump]$ cat hsjf_ora_15800.trc |grep BUCKET|wc -l

  434

  [oracle@jumper udump]$

434/2 = 217，证实了我们的猜想.

通过HASH TABLE算法的改进,Oracle Library Cache管理的效率大大提高.


关于shared pool的深入探讨(五)-www.eygle.com

关于shared pool的深入探讨(五)

Thursday, 2004-09-09 10:25 Eygle

Oracle使用两种数据结构来进行shared pool的并发控制:lock 和 pin.
Lock比pin具有更高的级别.

Lock在handle上获得,在pin一个对象之前,必须首先获得该handle的锁定.
锁定主要有三种模式: Null,share,Exclusive.
在读取访问对象时,通常需要获取Null(空)模式以及share(共享)模式的锁定.
在修改对象时,需要获得Exclusive(排他)锁定.

在锁定了Library Cache对象以后,一个进程在访问之前必须pin该对象.
同样pin有三种模式,Null,shared和exclusive.
只读模式时获得共享pin,修改模式获得排他pin.

通常我们访问、执行过程、Package时获得的都是共享pin,如果排他pin被持有,那么数据库此时就要产生等待.
在很多statspack的report中,我们可能看到以下等待事件:

Top 5 Wait Events
~~~~~~~~~~~~~~~~~                                             Wait     % Total
Event                                               Waits  Time (cs)   Wt Time
-------------------------------------------- ------------ ------------ -------
library cache lock                                 75,884    1,409,500   48.44
latch free                                     34,297,906    1,205,636   41.43
library cache pin                                     563      142,491    4.90
db file scattered read                            146,283       75,871    2.61
enqueue                                             2,211       13,003     .45
          -------------------------------------------------------------

这里的library cache lock和library cache pin都是我们关心的.接下来我们就研究一下这几个等待事件.

(一).LIBRARY CACHE PIN等待事件

Oracle文档上这样介绍这个等待事件:
"library cache pin" 是用来管理library cache的并发访问的,pin一个object会引起相应的heap被
载入内存中(如果此前没有被加载),Pins可以在三个模式下获得:NULL,SHARE,EXCLUSIVE,可以认为pin是一种特定
形式的锁.
当Library Cache Pin等待事件出现时,通常说明该Pin被其他用户已非兼容模式持有.

"library cache pin"的等待时间为3秒钟,其中有1秒钟用于PMON后台进程,即在取得pin之前最多等待3秒钟,否则就超时.
"library cache pin"的参数如下,有用的主要是P1和P2:
                P1 - KGL Handle address.
                P2 - Pin address
                P3 - Encoded Mode & Namespace

"LIBRARY CACHE PIN"通常是发生在编译或重新编译PL/SQL,VIEW,TYPES等object时.编译通常都是显性的,
如安装应用程序,升级,安装补丁程序等,另外,"ALTER","GRANT","REVOKE"等操作也会使object变得无效,
可以通过object的"LAST_DDL"观察这些变化.
当object变得无效时,Oracle 会在第一次访问此object时试图去重新编译它,如果此时其他session已经把此object pin
到library cache中,就会出现问题,特别时当有大量的活动session并且存在较复杂的dependence时.在某种情况下,重新
编译object可能会花几个小时时间,从而阻塞其它试图去访问此object的进程.

下面让我们通过一个例子来模拟及解释这个等待:

1.创建测试用存储过程

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Mon Sep 6 14:16:57 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area   47256168 bytes
Fixed Size                   451176 bytes
Variable Size              29360128 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
SQL> create or replace PROCEDURE pining
  2  IS
  3  BEGIN
  4          NULL;
  5  END;
  6  /

Procedure created.

SQL>
SQL> create or replace procedure calling
  2  is
  3  begin
  4          pining;
  5          dbms_lock.sleep(3000);
  6  end;
  7  /

Procedure created.

SQL>

2.模拟
首先执行calling过程,在calling过程中调用pining过程
此时pining过程上获得共享Pin,如果此时尝试对pining进行授权或重新编译,将产生Library Cache Pin等待
直到calling执行完毕.

session 1:

[oracle@jumper oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Mon Sep 6 16:13:43 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> exec calling

此时calling开始执行

session 2:

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Mon Sep 6 16:14:16 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> grant execute on pining to eygle;

此时session 2挂起

ok,我们开始我们的研究:

从v$session_wait入手,我们可以得到哪些session正在经历library cache pin的等待

SQL> select sid,seq#,event,p1,p1raw,p2,p2raw,p3,p3raw,state
  2  from v$session_wait where event like 'library%';

 SID       SEQ# EVENT                       P1 P1RAW            P2 P2RAW            P3  WAIT_TIME SECONDS_IN_WAIT STATE
---- ---------- ------------------- ---------- -------- ---------- -------- ---------- ---------- --------------- -------------------
   8        268 library cache pin   1389785868 52D6730C 1387439312 52B2A4D0        301          0               2 WAITING

等待3秒就超时,seq#会发生变化

SQL>

 SID       SEQ# EVENT                       P1 P1RAW            P2 P2RAW            P3  WAIT_TIME SECONDS_IN_WAIT STATE
---- ---------- ------------------- ---------- -------- ---------- -------- ---------- ---------- --------------- -------------------
   8        269 library cache pin   1389785868 52D6730C 1387439312 52B2A4D0        301          0               2 WAITING

SQL>

 SID       SEQ# EVENT                       P1 P1RAW            P2 P2RAW            P3  WAIT_TIME SECONDS_IN_WAIT STATE
---- ---------- ------------------- ---------- -------- ---------- -------- ---------- ---------- --------------- -------------------
   8        270 library cache pin   1389785868 52D6730C 1387439312 52B2A4D0        301          0               0 WAITING

在这个输出中,P1 列是Library Cache Handle Address,Pn字段是10进制表示,PnRaw字段是16进制表示

我们看到,library cache pin等待的对象的handle地址为:52D6730C
通过这个地址,我们查询X$KGLOB视图就可以得到对象的具体信息:

Note: X$KGLOB--[K]ernel [G]eneric [L]ibrary Cache Manager [OB]ject

col KGLNAOWN for a10
col KGLNAOBJ for a20
select ADDR,KGLHDADR,KGLHDPAR,KGLNAOWN,KGLNAOBJ,KGLNAHSH,KGLHDOBJ
from X$KGLOB
where KGLHDADR ='52D6730C'
/

ADDR     KGLHDADR KGLHDPAR KGLNAOWN   KGLNAOBJ               KGLNAHSH KGLHDOBJ
-------- -------- -------- ---------- -------------------- ---------- --------
404F9FF0 52D6730C 52D6730C SYS        PINING               2300250318 52D65BA4

这里KGLNAHSH代表该对象的Hash Value

由此我们知道,在PINING对象上正经历library cache pin的等待.

然后我们引入另外一个内部视图X$KGLPN:

Note:X$KGLPN--[K]ernel [G]eneric [L]ibrary Cache Manager object [P]i[N]s

select a.sid,a.username,a.program,b.addr,b.KGLPNADR,b.KGLPNUSE,b.KGLPNSES,b.KGLPNHDL,
b.kGLPNLCK, b.KGLPNMOD, b.KGLPNREQ
from v$session a,x$kglpn b
where a.saddr=b.kglpnuse and b.kglpnhdl = '52D6730C' and b.KGLPNMOD<>0
/

  SID USERNAME    PROGRAM                                  ADDR     KGLPNADR KGLPNUSE KGLPNSES KGLPNHDL KGLPNLCK   KGLPNMOD   KGLPNREQ
----- ----------- ---------------------------------------- -------- -------- -------- -------- -------- -------- ---------- ----------
   13 SYS         sqlplus@jumper.hurray.com.cn (TNS V1-V3) 404FA034 52B2A518 51E2013C 51E2013C 52D6730C 52B294C8          2          0

通过联合v$session,可以获得当前持有该handle的用户信息.
对于我们的测试sid=13的用户正持有该handle

那么这个用户正在等什么呢?

SQL> select * from v$session_wait where sid=13;

       SID       SEQ# EVENT               P1TEXT            P1 P1RAW    P2TEXT          P2 P2RAW    P3TEXT          P3 P3RAW     WAIT_TIME SECONDS_IN_WAIT STATE
---------- ---------- ------------------- --------- ---------- -------- ------- ---------- -------- ------- ---------- -------- ---------- --------------- -------
        13         25 PL/SQL lock timer   duration      120000 0001D4C0                  0 00                        0 00                0            1200 WAITING

Ok,这个用户正在等待一次PL/SQL lock timer计时.

得到了sid,我们就可以通过v$session.SQL_HASH_VALUE,v$session.SQL_ADDRESS等字段关联v$sqltext,v$sqlarea等视图获得当前session正在执行的操作.

SQL> select sql_text from v$sqlarea where v$sqlarea.hash_value='3045375777';

SQL_TEXT
--------------------------------------------------------------------------------
BEGIN calling; END;

这里我们得到这个用户正在执行calling这个存储过程,接下来的工作就应该去检查calling在作什么了.

我们这个calling作的工作是dbms_lock.sleep(3000)
也就是PL/SQL lock timer正在等待的原因

至此就找到了Library Cache Pin的原因.

简化一下以上查询:

1.获得Library Cache Pin等待的对象

SELECT addr, kglhdadr, kglhdpar, kglnaown, kglnaobj, kglnahsh, kglhdobj
  FROM x$kglob
 WHERE kglhdadr IN (SELECT p1raw
                      FROM v$session_wait
                     WHERE event LIKE 'library%')
/

ADDR     KGLHDADR KGLHDPAR KGLNAOWN   KGLNAOBJ               KGLNAHSH KGLHDOBJ
-------- -------- -------- ---------- -------------------- ---------- --------
404F2178 52D6730C 52D6730C SYS        PINING               2300250318 52D65BA4

2.获得持有等待对象的session信息

SELECT a.SID, a.username, a.program, b.addr, b.kglpnadr, b.kglpnuse,
       b.kglpnses, b.kglpnhdl, b.kglpnlck, b.kglpnmod, b.kglpnreq
  FROM v$session a, x$kglpn b
 WHERE a.saddr = b.kglpnuse
   AND b.kglpnmod <> 0
   AND b.kglpnhdl IN (SELECT p1raw
                        FROM v$session_wait
                       WHERE event LIKE 'library%')
/
SQL>

       SID USERNAME   PROGRAM                                          ADDR     KGLPNADR KGLPNUSE KGLPNSES KGLPNHDL KGLPNLCK   KGLPNMOD   KGLPNREQ
---------- ---------- ------------------------------------------------ -------- -------- -------- -------- -------- -------- ---------- ----------
        13 SYS        sqlplus@jumper.hurray.com.cn (TNS V1-V3)         404F6CA4 52B2A518 51E2013C 51E2013C 52D6730C 52B294C8          2          0

3.获得持有对象用户执行的代码

SELECT sql_text
  FROM v$sqlarea
 WHERE (v$sqlarea.address, v$sqlarea.hash_value) IN (
          SELECT sql_address, sql_hash_value
            FROM v$session
           WHERE SID IN (
                    SELECT SID
                      FROM v$session a, x$kglpn b
                     WHERE a.saddr = b.kglpnuse
                       AND b.kglpnmod <> 0
                       AND b.kglpnhdl IN (SELECT p1raw
                                            FROM v$session_wait
                                           WHERE event LIKE 'library%')))
/

SQL_TEXT
--------------------------------------------------------------------------------
BEGIN calling; END;

在grant之前和之后我们可以转储一下shared pool的内容观察比较一下:

SQL> ALTER SESSION SET EVENTS 'immediate trace name LIBRARY_CACHE level 32';

Session altered.

在grant之前:

从前面的查询获得pining的Handle是52D6730C:

******************************************************
BUCKET 67790:
  LIBRARY OBJECT HANDLE: handle=52d6730c
  name=SYS.PINING
  hash=891b08ce timestamp=09-06-2004 16:43:51
  namespace=TABL/PRCD/TYPE flags=KGHP/TIM/SML/[02000000]
  kkkk-dddd-llll=0000-0011-0011 lock=N pin=S latch#=1
--在Object上存在共享pin
--在handle上存在Null模式锁定,此模式允许其他用户继续以Null/shared模式锁定该对象
  lwt=0x52d67324[0x52d67324,0x52d67324] ltm=0x52d6732c[0x52d6732c,0x52d6732c]
  pwt=0x52d6733c[0x52b2a4e8,0x52b2a4e8] ptm=0x52d67394[0x52d67394,0x52d67394]
  ref=0x52d67314[0x52d67314, 0x52d67314] lnd=0x52d673a0[0x52d67040,0x52d6afcc]
    LIBRARY OBJECT: object=52d65ba4
    type=PRCD flags=EXS/LOC[0005] pflags=NST [01] status=VALD load=0
    DATA BLOCKS:
    data#     heap  pointer status pins change    alloc(K)  size(K)
    ----- -------- -------- ------ ---- ------     -------- --------
        0 52d65dac 52d65c90 I/P/A     0 NONE       0.30     0.55
        4 52d65c40 52d67c08 I/P/A     1 NONE       0.44     0.48

在发出grant命令后:

******************************************************
BUCKET 67790:
  LIBRARY OBJECT HANDLE: handle=52d6730c
  name=SYS.PINING
  hash=891b08ce timestamp=09-06-2004 16:43:51
  namespace=TABL/PRCD/TYPE flags=KGHP/TIM/SML/[02000000]
  kkkk-dddd-llll=0000-0011-0011 lock=X pin=S latch#=1
--由于calling执行未完成,在object上仍让保持共享pin
--由于grant会导致重新编译该对象,所以在handle上的排他锁已经被持有
--进一步的需要获得object上的Exclusive pin,由于shared pin被calling持有,所以library cache pin等待出现.
  lwt=0x52d67324[0x52d67324,0x52d67324] ltm=0x52d6732c[0x52d6732c,0x52d6732c]
  pwt=0x52d6733c[0x52b2a4e8,0x52b2a4e8] ptm=0x52d67394[0x52d67394,0x52d67394]
  ref=0x52d67314[0x52d67314, 0x52d67314] lnd=0x52d673a0[0x52d67040,0x52d6afcc]
    LIBRARY OBJECT: object=52d65ba4
    type=PRCD flags=EXS/LOC[0005] pflags=NST [01] status=VALD load=0
    DATA BLOCKS:
    data#     heap  pointer status pins change    alloc(K)  size(K)
    ----- -------- -------- ------ ---- ------     -------- --------
        0 52d65dac 52d65c90 I/P/A     0 NONE       0.30     0.55
        4 52d65c40 52d67c08 I/P/A     1 NONE       0.44     0.48

实际上recompile过程包含以下步骤,我们看一下lock和pin是如何交替发挥作用的:
1.存储过程的library cache object以排他模式被锁定,这个锁定是在handle上获得的
exclusive锁定可以防止其他用户执行同样的操作,同时防止其他用户创建新的引用此过程的对象.
2.以shared模式pin该对象,以执行安全和错误检查.
3.共享pin被释放,重新以排他模式pin该对象,执行重编译.
4.使所有依赖该过程的对象失效
5.释放exclusive lock和exclusive pin

(二).LIBRARY CACHE LOCK等待事件

如果此时我们再发出一条grant或compile的命令,那么library cache lock等待事件将会出现:

session 3:

[oracle@jumper oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Sep 7 17:05:25 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> alter procedure pining compile;

此进程挂起,我们查询v$session_wait视图可以获得以下信息:

SQL> select * from v$session_wait;

 SID SEQ# EVENT               P1TEXT                  P1 P1RAW    P2TEXT               P2 P2RAW    P3TEXT              P3 P3RAW     WAIT_TIME SECONDS STATE
---- ---- ------------------- --------------- ---------- -------- ------------ ---------- -------- ---------------- -------------- ---------- ------  ---
  11  143 library cache pin   handle address  1390239716 52DD5FE4 pin address  1387617456 52B55CB0 100*mode+namespace 301 0000012D          0       6 WAITING
  13   18 library cache lock  handle address  1390239716 52DD5FE4 lock address 1387433984 52B29000 100*mode+namespace 301 0000012D          0       3 WAITING
   8  415 PL/SQL lock timer   duration        120000     0001D4C0                       0 00                            0 00                0      63 WAITING
....

13 rows selected

由于handle上的lock已经被session 2以exclusive模式持有,所以session 3产生了等待.

我们可以看到,在生产数据库中权限的授予、对象的重新编译都可能会导致library cache pin等待的出现.
所以应该尽量避免在高峰期进行以上操作.

另外我们测试的案例本身就说明:如果Package或过程中存在复杂的、交互的依赖以来关系极易导致library cache pin的出现.
所以在应用开发的过程中,我们也应该注意这方面的内容.


数据块转储及RDBA的转换-www.eygle.com

数据块转储及RDBA的转换

Tuesday, 2004-08-31 17:51 Eygle

很多时候我们在进行进一步研究时需要转储(dump)Oracle的数据块,以研究其内容,Oracle提供了很好的方式,我们通过以下例子简单说明一下:

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Aug 31 17:01:27 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> select rowid,deptno,dname,loc from scott.dept;

ROWID                  DEPTNO DNAME          LOC
------------------ ---------- -------------- -------------
AAADZ7AABAAAGK6AAA         10 ACCOUNTING     NEW YORK
AAADZ7AABAAAGK6AAB         20 RESEARCH       DALLAS
AAADZ7AABAAAGK6AAC         30 SALES          CHICAGO
AAADZ7AABAAAGK6AAD         40 OPERATIONS     BOSTON

SQL> select file_id,block_id,blocks from dba_extents where segment_name='DEPT';

   FILE_ID   BLOCK_ID     BLOCKS
---------- ---------- ----------
         1      25273          8

SQL> alter system dump datafile 1 block min 25273 block max 25274;

System altered.

SQL> !
[oracle@jumper udump]$ ls -l
total 4
-rw-r-----   1 oracle   dba          3142 Aug 31 17:04 hsjf_ora_13674.trc
[oracle@jumper udump]$ more hsjf_ora_13674.trc
/opt/oracle/admin/hsjf/udump/hsjf_ora_13674.trc
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production
ORACLE_HOME = /opt/oracle/product/9.2.0
System name:    Linux
Node name:      jumper.hurray.com.cn
Release:        2.4.18-14
Version:        #1 Wed Sep 4 13:35:50 EDT 2002
Machine:        i686
Instance name: hsjf
Redo thread mounted by this instance: 1
Oracle process number: 9
Unix process pid: 13674, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** 2004-08-31 17:04:27.820
*** SESSION ID:(8.3523) 2004-08-31 17:04:27.819
Start dump data blocks tsn: 0 file#: 1 minblk 25273 maxblk 25274
buffer tsn: 0 rdba: 0x004062b9 (1/25273)
scn: 0x0000.0057c70d seq: 0x01 flg: 0x04 tail: 0xc70d1001
frmt: 0x02 chkval: 0x12e3 type: 0x10=DATA SEGMENT HEADER - UNLIMITED
  Extent Control Header
  -----------------------------------------------------------------
  Extent Header:: spare1: 0      spare2: 0      #extents: 1      #blocks: 7
                  last map  0x00000000  #maps: 0      offset: 4128
      Highwater::  0x004062bb  ext#: 0      blk#: 1      ext size: 7
  #blocks in seg. hdr's freelists: 1
  #blocks below: 1
  mapblk  0x00000000  offset: 0
                   Unlocked
     Map Header:: next  0x00000000  #extents: 1    obj#: 13947  flag: 0x40000000
  Extent Map
  -----------------------------------------------------------------
   0x004062ba  length: 7

  nfl = 1, nfb = 1 typ = 1 nxf = 0 ccnt = 1
  SEG LST:: flg: USED   lhd: 0x004062ba ltl: 0x004062ba
buffer tsn: 0 rdba: 0x004062ba (1/25274)
scn: 0x0000.0131909b seq: 0x07 flg: 0x04 tail: 0x909b0607
frmt: 0x02 chkval: 0xa8e7 type: 0x06=trans data
Block header dump:  0x004062ba
 Object id on Block? Y
 seg/obj: 0x367b  csc: 0x00.131909a  itc: 2  flg: O  typ: 1 - DATA
     fsl: 0  fnx: 0x0 ver: 0x01

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
0x01   0x0001.02a.000003f3  0x0080000b.0188.08  C---    0  scn 0x0000.0057c70e
0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000

data_block_dump,data header at 0xadb505c
===============
tsiz: 0x1fa0
hsiz: 0x1a
pbl: 0x0adb505c
bdba: 0x004062ba
     76543210
flag=--------
ntab=1
nrow=4
frre=-1
fsbo=0x1a
fseo=0x1f44
avsp=0x1f2a
tosp=0x1f2a
0xe:pti[0]      nrow=4  offs=0
0x12:pri[0]     offs=0x1f86
0x14:pri[1]     offs=0x1f70
0x16:pri[2]     offs=0x1f5c
0x18:pri[3]     offs=0x1f44
block_row_dump:
tab 0, row 0, @0x1f86
tl: 26 fb: --H-FL-- lb: 0x0  cc: 3
col  0: [ 2]  c1 0b
col  1: [10]  41 43 43 4f 55 4e 54 49 4e 47
col  2: [ 8]  4e 45 57 20 59 4f 52 4b
tab 0, row 1, @0x1f70
tl: 22 fb: --H-FL-- lb: 0x0  cc: 3
col  0: [ 2]  c1 15
col  1: [ 8]  52 45 53 45 41 52 43 48
col  2: [ 6]  44 41 4c 4c 41 53
tab 0, row 2, @0x1f5c
tl: 20 fb: --H-FL-- lb: 0x0  cc: 3
col  0: [ 2]  c1 1f
col  1: [ 5]  53 41 4c 45 53
col  2: [ 7]  43 48 49 43 41 47 4f
tab 0, row 3, @0x1f44
tl: 24 fb: --H-FL-- lb: 0x0  cc: 3
col  0: [ 2]  c1 29
col  1: [10]  4f 50 45 52 41 54 49 4f 4e 53
col  2: [ 6]  42 4f 53 54 4f 4e
end_of_block_dump
End dump data blocks tsn: 0 file#: 1 minblk 25273 maxblk 25274

很多人经常提出的一个问题是,rdba是如何转换的?

rdba: 0x004062ba (1/25274)

我们通过这个例子介绍一下.

rdba从Oracle6->Oracle7->Oracle8发生了三次改变:

在Oracle6中,rdba由6位2进制数表示,也就是说数据块最多只能有2^6=64个数据文件(去掉全0和全1, 实际上最多只能代表62个文件)

在Oracle7中,rdba中的文件号增加为10位,为了向后兼容,从Block号的高位拿出4位作为文件号的高位.这样从6->7的Rowid无需发生变化.
而数据文件的个数理论上则扩展到了1022个(去掉全0和全1),在Oracle7中,rowid格式为:BBBBBBBB.RRRR.FFFF

在Oracle8中,文件号仍然用10位表示,只是不再需要置换,为了向后兼容,同时引入了相对文件号(rfile#),所以从Oracle7到Oracle8,Rowid仍然无需发生变化.
在Oracle8i中,Oracle引入了dataobj#,rowid的格式变为:OOOOOOFFFBBBBBBSSS,Oracle通过dataobj#进一步向上定为表空间等,从而使每个表空间
的数据文件数量理论上可以达到1022个

举例说明如下:

在Oracle6中:
比如: file 8, block 56892
        26位block号==56892
      vv  vvvvvvvv  vvvvvvvv  vvvvvvvv
00100000  00000000  11011110  00111100
^^^^^^
6位文件号==8

在Oracle7中:
比如:File 255, block 56892

11111100 11000000  11011110  00111100
 F   C    C   0     D   E     3  C
\_____/\___/\_______________________/
   |     |	     |
   |     |	Block = 0xDE3C = 56892
   \_____________
         |  \
         V   V
        0011   111111 = 0xFF = 255 --注意这里高位和低位要置换才能得出正确的file#

在Oracle8中:
比如:File 255, block 56892

11111100 11000000  11011110  00111100
 F   C    C   0     D   E     3  C
\_____/\___/\_______________________/
   |     |	     |
   |     |	Block = 0xDE3C = 56892
   \_____________
         |  \
         V   V
      0011 1111 0011 = 03F3 = 1011 --这就是相对文件号

对于我们测试中的例子:

rdba: 0x004062ba (1/25274)

也就是:0000 0000 0100 0000 0110 0010 1011 1010

前10位为rfile#: 0000 0000 01 = 1

后22位为Block#:00 0000 0110 0010 1011 1010 = 25274


数据文件头信息转储分析-eygle.com

关于数据文件头信息记录

这个测试的起因是一些朋友讨论,Oracle在恢复时从何处获得日志文件名信息.

因为如果在重建控制文件的过程中,控制文件中的信息显然已经被清空了.

参考链接:

http://www.itpub.net/showthread.php?threadid=232777

下面是一些简单测试及说明.

1.转储控制文件头

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Thu Jun 17 15:27:37 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> ALTER SESSION SET EVENTS ' IMMEDIATE TRACE NAME FILE_HDRS LEVEL 10';

Session altered.

notes:

ALTER SESSION SET EVENTS ' IMMEDIATE TRACE NAME FILE_HDRS LEVEL 10';

用于转储数据文件头信息.

2.获得以下跟踪文件信息(仅摘录system表空间记录,请注意红色部分):

DATA FILE #1:
(name #4) /opt/oracle/oradata/hsjf/system01.dbf
creation size=32000 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 0, index=1 krfil=1 prev_file=0
unrecoverable scn: 0x0000.00000000 04/23/2004 01:20:52
Checkpoint cnt:1557 scn: 0x0000.014338dc 06/13/2004 01:19:38
Stop scn: 0xffff.ffffffff 06/13/2004 01:18:07
Creation Checkpointed at scn: 0x0000.000000ae 07/16/2003 03:40:10
thread:1 rba:(0x1.3.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Offline scn: 0x0000.013b46fd prev_range: 0
Online Checkpointed at scn: 0x0000.013b46fe 05/28/2004 23:37:17
thread:1 rba:(0x1.2.0)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Hot Backup end marker scn: 0x0000.00000000
aux_file is NOT DEFINED
FILE HEADER:
Software vsn=153092096=0x9200000, Compatibility Vsn=134217728=0x8000000
Db ID=1052178311=0x3eb6f787, Db Name='HSJF'
Activation ID=0=0x0
Control Seq=18062=0x468e, File size=38400=0x9600
File Number=1, Blksiz=8192, File Type=3 DATA
Tablespace #0 - SYSTEM rel_fn:1
Creation at scn: 0x0000.000000ae 07/16/2003 03:40:10
Backup taken at scn: 0x0000.01301f8d 05/12/2004 00:16:20 thread:1
reset logs count:0x1f6f3ead scn: 0x0000.013b46fe recovered at 06/06/2004 22:45:27
status:0x4 root dba:0x004001a1 chkpt cnt: 1557 ctl cnt:1556
begin-hot-backup file size: 38400
Checkpointed at scn: 0x0000.014338dc 06/13/2004 01:19:38
thread:1 rba:(0x6a.18fd.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Backup Checkpointed at scn: 0x0000.01301f8d 05/12/2004 00:16:20
thread:1 rba:(0x2ac.1f42.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
External cache id: 0x0 0x0 0x0 0x0
Absolute fuzzy scn: 0x0000.00000000
Recovery fuzzy scn: 0x0000.00000000 05/05/2004 18:09:43
Terminal Recovery Stamp scn: 0x0000.00000000 01/01/1988 00:00:00

3.注意这里的RBA信息

rba:(0x6a.18fd.10)

我们注意RBA信息由三部分组成:

1.日志文件序号 4 bytes

2.日志文件块号 4 bytes

3.日志记录偏移量 2 bytes

这部分信息可以参考Steve Adams的站点:

http://www.ixora.com.au/notes/rba.htm

那么在这里,我们就可以得到日志文件的sequence号,在重建控制文件恢复时,Oracle就可以由此获得归档信息

提示需要的归档文件号.

对于本例:

thread:1 rba:(0x6a.18fd.10)

0x6a = 106

这就是log sequence了

从数据库的日志文件序号中我们可以看到:

SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /opt/oracle/oradata/hsjf/archive
Oldest online log sequence 104
Next log sequence to archive 106
Current log sequence 106

2004年6月17日 Thursday

If you have any question,please mail to eygle@itpub.net .


关于checkpoint cnt和checkpoint scn-eygle.com

关于checkpoint cnt和checkpoint scn

通过试验说明checkpoint cnt 和checkpoint scn的关系

1.在不同条件下转储控制文件

SQL> alter session set events 'immediate trace name CONTROLF level 10';

Session altered.

SQL> alter tablespace system begin backup;

Tablespace altered.

SQL> alter session set events 'immediate trace name CONTROLF level 10';

Session altered.

SQL> alter system checkpoint;

System altered.

SQL> alter session set events 'immediate trace name CONTROLF level 10'
2 /

Session altered.

SQL> alter tablespace system end backup;

Tablespace altered.

SQL> alter session set events 'immediate trace name CONTROLF level 10';

Session altered.

notes:

alter session set events 'immediate trace name CONTROLF level 10';

用于转储控制文件.

2.获得以下跟踪文件信息(仅研究system表空间记录,请注意红色部分):

a.正常情况下转储控制文件

***************************************************************************
DATA FILE RECORDS
***************************************************************************
(blkno = 0x6, size = 180, max = 100, in-use = 24, last-recid= 574)
DATA FILE #1:
(name #4) /opt/oracle/oradata/hsjf/system01.dbf
creation size=32000 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 0, index=1 krfil=1 prev_file=0
unrecoverable scn: 0x0000.00000000 04/23/2004 01:20:52
Checkpoint cnt:1567 scn: 0x0000.0148181c 06/22/2004 18:58:46
Stop scn: 0xffff.ffffffff 06/22/2004 18:58:05
Creation Checkpointed at scn: 0x0000.000000ae 07/16/2003 03:40:10
thread:1 rba:(0x1.3.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Offline scn: 0x0000.013b46fd prev_range: 0
Online Checkpointed at scn: 0x0000.013b46fe 05/28/2004 23:37:17
thread:1 rba:(0x1.2.0)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Hot Backup end marker scn: 0x0000.00000000
aux_file is NOT DEFINED

b.执行Begin backup以后的

我们注意到Checkpoint cnt增加了1，此处触发了一次表空间检查点.

***************************************************************************
DATA FILE RECORDS
***************************************************************************
(blkno = 0x6, size = 180, max = 100, in-use = 24, last-recid= 574)
DATA FILE #1:
(name #4) /opt/oracle/oradata/hsjf/system01.dbf
creation size=32000 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 0, index=1 krfil=1 prev_file=0
unrecoverable scn: 0x0000.00000000 04/23/2004 01:20:52
Checkpoint cnt:1568 scn: 0x0000.01481939 06/22/2004 19:02:22
Stop scn: 0xffff.ffffffff 06/22/2004 18:58:05
Creation Checkpointed at scn: 0x0000.000000ae 07/16/2003 03:40:10
thread:1 rba:(0x1.3.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Offline scn: 0x0000.013b46fd prev_range: 0
Online Checkpointed at scn: 0x0000.013b46fe 05/28/2004 23:37:17
thread:1 rba:(0x1.2.0)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Hot Backup end marker scn: 0x0000.00000000
aux_file is NOT DEFINED

c.执行手工检查点

我们注意到,此时Checkpoint cnt增加，但是scn不再改变

***************************************************************************
DATA FILE RECORDS
***************************************************************************
(blkno = 0x6, size = 180, max = 100, in-use = 24, last-recid= 574)
DATA FILE #1:
(name #4) /opt/oracle/oradata/hsjf/system01.dbf
creation size=32000 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 0, index=1 krfil=1 prev_file=0
unrecoverable scn: 0x0000.00000000 04/23/2004 01:20:52
Checkpoint cnt:1569 scn: 0x0000.01481939 06/22/2004 19:02:22
Stop scn: 0xffff.ffffffff 06/22/2004 18:58:05
Creation Checkpointed at scn: 0x0000.000000ae 07/16/2003 03:40:10
thread:1 rba:(0x1.3.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Offline scn: 0x0000.013b46fd prev_range: 0
Online Checkpointed at scn: 0x0000.013b46fe 05/28/2004 23:37:17
thread:1 rba:(0x1.2.0)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Hot Backup end marker scn: 0x0000.00000000
aux_file is NOT DEFINED

d.End backup后的情况

此时数据文件头的冻结被取消,scn开始变化

***************************************************************************
DATA FILE RECORDS
***************************************************************************
(blkno = 0x6, size = 180, max = 100, in-use = 24, last-recid= 574)
DATA FILE #1:
(name #4) /opt/oracle/oradata/hsjf/system01.dbf
creation size=32000 block size=8192 status=0xe head=4 tail=4 dup=1
tablespace 0, index=1 krfil=1 prev_file=0
unrecoverable scn: 0x0000.00000000 04/23/2004 01:20:52
Checkpoint cnt:1570 scn: 0x0000.01481941 06/22/2004 19:02:39
Stop scn: 0xffff.ffffffff 06/22/2004 18:58:05
Creation Checkpointed at scn: 0x0000.000000ae 07/16/2003 03:40:10
thread:1 rba:(0x1.3.10)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Offline scn: 0x0000.013b46fd prev_range: 0
Online Checkpointed at scn: 0x0000.013b46fe 05/28/2004 23:37:17
thread:1 rba:(0x1.2.0)
enabled threads: 01000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000
Hot Backup end marker scn: 0x0000.00000000
aux_file is NOT DEFINED

Checkpoint cnt用于保证在正常操作中使用的数据文件是当前版本
在恢复时防止恢复数据文件的错误版本.Checkpoint cnt是一直递增的,即使表空间处于热备份模式.

由于表空间的创建时间不尽相同,所以不同表空间/数据文件的Checkpoint cnt通常是不同的.

我们知道:

在数据库open的过程中,Oracle要进行两次检查.

第一次检查数据文件头中的Checkpoint cnt是否与对应控制文件中的Checkpoint cnt一致.
如果相等,进行第二次检查.

第二次检查数据文件头的开始SCN和对应控制文件中的结束SCN是否一致
如果结束SCN等于开始SCN,则不需要对那个文件进行恢复.

对每个数据文件都完成检查后,打开数据库.同时将每个数据文件的结束SCN设置为无穷大.

2004年6月22日 星期二

If you have any question,please mail to eygle@itpub.net .


关于ASSM HWM的研究-eygle.com

关于ASSM HWM的研究

1. 测试基本脚本

create tablespace assm

datafile '/data1/oracle/oradata/assm01.dbf'

size 10M

extent management local uniform size 40K ----这里对于不同size分别测试

segment space management auto

/

CREATE TABLE TEST_HWM1 (ID CHAR(2000), NAME CHAR(2000) )

Tablespace ASSM

STORAGE ( MINEXTENTS 2) PCTFREE 40

/

select EXTENT_ID,FILE_ID,RELATIVE_FNO,BLOCK_ID,BLOCKS

from dba_extents

where segment_name='TEST_HWM1'

/

alter system dump datafile 7 block min 9 block max 11;

insert into test_hwm1 values('1','dlinger');

commit;

alter system dump datafile 7 block min 9 block max 11;

drop tablespace assm including contents and datafiles;

2. 测试步骤

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Jun 15 11:01:59 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

SQL> drop tablespace assm including contents and datafiles;

Tablespace dropped.

SQL> create tablespace assm

2 datafile '/data1/oracle/oradata/assm01.dbf'

3 size 10M

4 extent management local uniform size 40K

5 segment space management auto

6 /

Tablespace created.

SQL> CREATE TABLE TEST_HWM1 (ID CHAR(2000), NAME CHAR(2000) )

2 Tablespace ASSM

3 STORAGE ( MINEXTENTS 2) PCTFREE 40

4 /

Table created.

SQL> select EXTENT_ID,FILE_ID,RELATIVE_FNO,BLOCK_ID,BLOCKS

2 from dba_extents

3 where segment_name='TEST_HWM1'

4 /

EXTENT_ID FILE_ID RELATIVE_FNO BLOCK_ID BLOCKS

---------- ---------- ------------ ---------- ----------

0 7 7 9 5

1 7 7 14 5

SQL> ! vi a.sql

alter system dump datafile 7 block min 9 block max 11;

insert into test_hwm1 values('1','dlinger');

commit;

alter system dump datafile 7 block min 9 block max 11;

~

"a.sql" [New] 6L, 165C written

SQL> set echo on

SQL> @a

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL>

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> !

[oracle@jumper udump]$ ls

a.sql hsjf_ora_14222.trc

[oracle@jumper udump]$ more *.trc

/opt/oracle/admin/hsjf/udump/hsjf_ora_14222.trc

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

ORACLE_HOME = /opt/oracle/product/9.2.0

System name: Linux

Node name: jumper.hurray.com.cn

Release: 2.4.18-14

Version: #1 Wed Sep 4 13:35:50 EDT 2002

Machine: i686

Instance name: hsjf

Redo thread mounted by this instance: 1

Oracle process number: 9

Unix process pid: 14222, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** 2004-06-15 11:03:09.785

*** SESSION ID:(8.1436) 2004-06-15 11:03:09.784

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444b37 seq: 0x02 flg: 0x00 tail: 0x4b372002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 7 total: 10 first useful block: 3

owning instance : 1

instance ownership changed at

Last successful Search

Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295

First free datablock : 3

Bitmap block lock opcode 3

Locker xid: : 0x000a.017.00000aec

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 5 ---HWM H0c = 12

#blocks in seg. hdr's freelists: 0 ---文件头 8

#blocks below: 0 ---Metadata 3

mapblk 0x00000000 offset: 0 ---HWM = 8 + 3 + 1 = 12

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 5 Offset: 0

0x01c0000e Length: 5 Offset: 5

0:Metadata 1:Metadata 2:Metadata 3:unformatted

4:unformatted 5:unformatted 6:unformatted 7:unformatted

8:unformatted 9:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444b36 seq: 0x02 flg: 0x00 tail: 0x4b362102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444b3a seq: 0x01 flg: 0x00 tail: 0x4b3a2301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 10

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 5

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 5

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15685 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 5

0x01c0000e length: 5

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c0000e

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444b46 seq: 0x04 flg: 0x00 tail: 0x4b462004

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 5 total: 10 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:03:09

Last successful Search 06/15/2004 11:03:09

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 1

Extent Map Block Offset: 4294967295

First free datablock : 3

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c0000e ext#: 0 blk#: 5 ext size: 5 HWM H0e = 14

#blocks in seg. hdr's freelists: 0 HWM = 8 + 3 + 2 +1 = 14

#blocks below: 2

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 5 Offset: 0

0x01c0000e Length: 5 Offset: 5

0:Metadata 1:Metadata 2:Metadata 3:75-100% free 此处一次格式化

4:25-50% free 5:unformatted 6:unformatted 7:unformatted extents 另外2个block

8:unformatted 9:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444b36 seq: 0x02 flg: 0x00 tail: 0x4b362102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444b46 seq: 0x01 flg: 0x00 tail: 0x4b462301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 10

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c0000e ext#: 0 blk#: 5 ext size: 5

#blocks in seg. hdr's freelists: 0

#blocks below: 2

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 5

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15685 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 5

0x01c0000e length: 5

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c0000e

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

继续增加记录

[oracle@jumper udump]$ more hsjf_ora_16003.trc

/opt/oracle/admin/hsjf/udump/hsjf_ora_16003.trc

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

ORACLE_HOME = /opt/oracle/product/9.2.0

System name: Linux

Node name: jumper.hurray.com.cn

Release: 2.4.18-14

Version: #1 Wed Sep 4 13:35:50 EDT 2002

Machine: i686

Instance name: hsjf

Redo thread mounted by this instance: 1

Oracle process number: 9

Unix process pid: 16003, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** SESSION ID:(8.1438) 2004-06-15 11:14:10.331

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444c21 seq: 0x04 flg: 0x00 tail: 0x4c212004

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 0 total: 10 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:14:07

Last successful Search 06/15/2004 11:14:07

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 4

Extent Map Block Offset: 4294967295

First free datablock : 5

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00013 ext#: 1 blk#: 5 ext size: 5

#blocks in seg. hdr's freelists: 0 HWM = H13 = 19

#blocks below: 7 HWM=19=8 + 3 + 2 + 5 + 1 =19

mapblk 0x00000000 offset: 1

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 5 Offset: 0

0x01c0000e Length: 5 Offset: 5

---Oracle 选择格式化第二个extents 5个block

0:Metadata 1:Metadata 2:Metadata 3:FULL

4:FULL 5:75-100% free 6:75-100% free 7:75-100% free

8:75-100% free 9:25-50% free

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444b36 seq: 0x02 flg: 0x00 tail: 0x4b362102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444c21 seq: 0x01 flg: 0x00 tail: 0x4c212301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 10

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00013 ext#: 1 blk#: 5 ext size: 5

#blocks in seg. hdr's freelists: 0

#blocks below: 7

mapblk 0x00000000 offset: 1

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 5

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15685 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 5

0x01c0000e length: 5

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c0000e

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

测试第二种情况:

[oracle@jumper udump]$ sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Jun 15 11:26:08 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

SQL> drop tablespace assm including contents and datafiles;

Tablespace dropped.

SQL> @a

SQL> create tablespace assm

2 datafile '/data1/oracle/oradata/assm01.dbf'

3 size 10M

4 extent management local uniform size 64K

5 segment space management auto

6 /

Tablespace created.

SQL>

SQL> CREATE TABLE TEST_HWM1 (ID CHAR(2000), NAME CHAR(2000) )

2 Tablespace ASSM

3 STORAGE ( MINEXTENTS 2) PCTFREE 40

4 /

Table created.

SQL>

SQL>

SQL> select EXTENT_ID,FILE_ID,RELATIVE_FNO,BLOCK_ID,BLOCKS

2 from dba_extents

3 where segment_name='TEST_HWM1'

4 /

EXTENT_ID FILE_ID RELATIVE_FNO BLOCK_ID BLOCKS

---------- ---------- ------------ ---------- ----------

0 7 7 9 8

1 7 7 17 8

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL>

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> exit

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

[oracle@jumper udump]$ ls -sort

total 60

16 -rw-r----- 1 oracle 15744 6月 15 11:13 hsjf_ora_14222.trc

4 -rw-r--r-- 1 oracle 109 6月 15 11:14 b.sql

12 -rw-r----- 1 oracle 11888 6月 15 11:14 hsjf_ora_16003.trc

4 -rw-r--r-- 1 oracle 546 6月 15 11:22 a.sql

12 -rw-r----- 1 oracle 8325 6月 15 11:22 hsjf_ora_16983.trc

12 -rw-r----- 1 oracle 8326 6月 15 11:26 hsjf_ora_17568.trc

[oracle@jumper udump]$ more hsjf_ora_17568.trc

/opt/oracle/admin/hsjf/udump/hsjf_ora_17568.trc

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

ORACLE_HOME = /opt/oracle/product/9.2.0

System name: Linux

Node name: jumper.hurray.com.cn

Release: 2.4.18-14

Version: #1 Wed Sep 4 13:35:50 EDT 2002

Machine: i686

Instance name: hsjf

Redo thread mounted by this instance: 1

Oracle process number: 10

Unix process pid: 17568, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** SESSION ID:(11.587) 2004-06-15 11:26:20.196

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444d6b seq: 0x02 flg: 0x00 tail: 0x4d6b2002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 13 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at

Last successful Search

Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295

First free datablock : 3

Bitmap block lock opcode 3

Locker xid: : 0x0009.020.00000aca

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:unformatted

4:unformatted 5:unformatted 6:unformatted 7:unformatted

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444d6e seq: 0x01 flg: 0x00 tail: 0x4d6e2301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444d71 seq: 0x04 flg: 0x00 tail: 0x4d712004

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 8 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:26:20

Last successful Search 06/15/2004 11:26:20

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 4

Extent Map Block Offset: 4294967295

First free datablock : 3

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:25-50% free --5 个block被格式化

4:75-100% free 5:75-100% free 6:75-100% free 7:75-100% free

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444d71 seq: 0x01 flg: 0x00 tail: 0x4d712301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Jun 15 11:29:14 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

SQL> @b

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> @b

SQL> set echo on

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> @b

SQL> set echo on

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> @b

SQL> set echo on

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> @b

SQL> set echo on

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> @b

SQL> set echo on

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> !

[oracle@jumper udump]$ ls -sort

total 84

16 -rw-r----- 1 oracle 15744 6月 15 11:13 hsjf_ora_14222.trc

12 -rw-r----- 1 oracle 11888 6月 15 11:14 hsjf_ora_16003.trc

4 -rw-r--r-- 1 oracle 546 6月 15 11:22 a.sql

12 -rw-r----- 1 oracle 8325 6月 15 11:22 hsjf_ora_16983.trc

12 -rw-r----- 1 oracle 8326 6月 15 11:26 hsjf_ora_17568.trc

4 -rw-r--r-- 1 oracle 121 6月 15 11:29 b.sql

24 -rw-r----- 1 oracle 23800 6月 15 11:29 hsjf_ora_18039.trc

[oracle@jumper udump]$ more hsjf_ora_18039.trc

/opt/oracle/admin/hsjf/udump/hsjf_ora_18039.trc

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

ORACLE_HOME = /opt/oracle/product/9.2.0

System name: Linux

Node name: jumper.hurray.com.cn

Release: 2.4.18-14

Version: #1 Wed Sep 4 13:35:50 EDT 2002

Machine: i686

Instance name: hsjf

Redo thread mounted by this instance: 1

Oracle process number: 10

Unix process pid: 18039, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** SESSION ID:(11.591) 2004-06-15 11:29:15.312

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444dab seq: 0x02 flg: 0x00 tail: 0x4dab2002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 8 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:26:20

Last successful Search 06/15/2004 11:26:20

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 3

Extent Map Block Offset: 4294967295

First free datablock : 4

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:FULL

4:75-100% free 5:75-100% free 6:25-50% free 7:75-100% free

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444d71 seq: 0x01 flg: 0x00 tail: 0x4d712301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444dad seq: 0x02 flg: 0x00 tail: 0x4dad2002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 8 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:26:20

Last successful Search 06/15/2004 11:26:20

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 2

Extent Map Block Offset: 4294967295

First free datablock : 4

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:FULL

4:75-100% free 5:75-100% free 6:FULL 7:25-50% free

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444d71 seq: 0x01 flg: 0x00 tail: 0x4d712301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444daf seq: 0x02 flg: 0x00 tail: 0x4daf2002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 8 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:26:20

Last successful Search 06/15/2004 11:26:20

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 1

Extent Map Block Offset: 4294967295

First free datablock : 4

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:FULL

4:25-50% free 5:75-100% free 6:FULL 7:FULL

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444d71 seq: 0x01 flg: 0x00 tail: 0x4d712301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444db1 seq: 0x02 flg: 0x00 tail: 0x4db12002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 8 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:26:20

Last successful Search 06/15/2004 11:26:20

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 0

Extent Map Block Offset: 4294967295

First free datablock : 5

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:FULL

4:FULL 5:25-50% free 6:FULL 7:FULL

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444d71 seq: 0x01 flg: 0x00 tail: 0x4d712301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00011 ext#: 0 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 5

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444db3 seq: 0x04 flg: 0x00 tail: 0x4db32004

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 0 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:29:19

Last successful Search 06/15/2004 11:29:19

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 7

Extent Map Block Offset: 4294967295

First free datablock : 8

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00019 ext#: 1 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 13

mapblk 0x00000000 offset: 1

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:FULL --格式化第二个extetns8个block

4:FULL 5:FULL 6:FULL 7:FULL

8:75-100% free 9:75-100% free 10:25-50% free 11:75-100% free

12:75-100% free 13:75-100% free 14:75-100% free 15:75-100% free

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444db3 seq: 0x01 flg: 0x00 tail: 0x4db32301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00019 ext#: 1 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 13

mapblk 0x00000000 offset: 1

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444db5 seq: 0x02 flg: 0x00 tail: 0x4db52002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 2 parent dba: 0x01c0000a poffset: 0

unformatted: 0 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:29:19

Last successful Search 06/15/2004 11:29:19

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 6

Extent Map Block Offset: 4294967295

First free datablock : 8

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00019 ext#: 1 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 13

mapblk 0x00000000 offset: 1

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 8 Offset: 0

0x01c00011 Length: 8 Offset: 8

0:Metadata 1:Metadata 2:Metadata 3:FULL

4:FULL 5:FULL 6:FULL 7:FULL

8:75-100% free 9:75-100% free 10:FULL 11:25-50% free

12:75-100% free 13:75-100% free 14:75-100% free 15:75-100% free

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444d6a seq: 0x02 flg: 0x00 tail: 0x4d6a2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 1 nfree: 1 ffree: 0 pdba: 0x01c0000b

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444db3 seq: 0x01 flg: 0x00 tail: 0x4db32301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 16

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00019 ext#: 1 blk#: 8 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 13

mapblk 0x00000000 offset: 1

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 8

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00009

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15687 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 8

0x01c00011 length: 8

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00009 Data dba: 0x01c00011

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

第三种情况

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Jun 15 11:34:15 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

SQL> @a

SQL> drop tablespace assm including contents and datafiles;

Tablespace dropped.

SQL> create tablespace assm

2 datafile '/data1/oracle/oradata/assm01.dbf'

3 size 10M

4 extent management local uniform size 128K

5 segment space management auto

6 /

Tablespace created.

SQL>

SQL> CREATE TABLE TEST_HWM1 (ID CHAR(2000), NAME CHAR(2000) )

2 Tablespace ASSM

3 STORAGE ( MINEXTENTS 2) PCTFREE 40

4 /

Table created.

SQL>

SQL>

SQL> select EXTENT_ID,FILE_ID,RELATIVE_FNO,BLOCK_ID,BLOCKS

2 from dba_extents

3 where segment_name='TEST_HWM1'

4 /

EXTENT_ID FILE_ID RELATIVE_FNO BLOCK_ID BLOCKS

---------- ---------- ------------ ---------- ----------

0 7 7 9 16

1 7 7 25 16

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL>

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> !

[oracle@jumper udump]$ ls

a.sql hsjf_ora_14222.trc hsjf_ora_16983.trc hsjf_ora_18039.trc

b.sql hsjf_ora_16003.trc hsjf_ora_17568.trc hsjf_ora_18807.trc

[oracle@jumper udump]$ ls -sort

total 96

16 -rw-r----- 1 oracle 15744 6月 15 11:13 hsjf_ora_14222.trc

12 -rw-r----- 1 oracle 11888 6月 15 11:14 hsjf_ora_16003.trc

12 -rw-r----- 1 oracle 8325 6月 15 11:22 hsjf_ora_16983.trc

12 -rw-r----- 1 oracle 8326 6月 15 11:26 hsjf_ora_17568.trc

4 -rw-r--r-- 1 oracle 121 6月 15 11:29 b.sql

24 -rw-r----- 1 oracle 23800 6月 15 11:29 hsjf_ora_18039.trc

4 -rw-r--r-- 1 oracle 602 6月 15 11:34 a.sql

12 -rw-r----- 1 oracle 8305 6月 15 11:34 hsjf_ora_18807.trc

[oracle@jumper udump]$ more hsjf_ora_18807.trc

/opt/oracle/admin/hsjf/udump/hsjf_ora_18807.trc

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

ORACLE_HOME = /opt/oracle/product/9.2.0

System name: Linux

Node name: jumper.hurray.com.cn

Release: 2.4.18-14

Version: #1 Wed Sep 4 13:35:50 EDT 2002

Machine: i686

Instance name: hsjf

Redo thread mounted by this instance: 1

Oracle process number: 11

Unix process pid: 18807, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** SESSION ID:(9.116) 2004-06-15 11:34:19.132

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444e3e seq: 0x02 flg: 0x00 tail: 0x4e3e2002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000a poffset: 0

unformatted: 13 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at

Last successful Search

Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295

First free datablock : 3

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 16

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 16 Offset: 0

0:Metadata 1:Metadata 2:Metadata 3:unformatted

4:unformatted 5:unformatted 6:unformatted 7:unformatted

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444e3f seq: 0x02 flg: 0x00 tail: 0x4e3f2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 2 nfree: 2 ffree: 0 pdba: 0x01c0000b

opcode:1

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

0x01c00019 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444e42 seq: 0x01 flg: 0x00 tail: 0x4e422301

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 32

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 16

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c0000c ext#: 0 blk#: 3 ext size: 16

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00019

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15688 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 16

0x01c00019 length: 16

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00019 Data dba: 0x01c0001a

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444e45 seq: 0x03 flg: 0x00 tail: 0x4e452003

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000a poffset: 0

unformatted: 0 total: 16 first useful block: 3

owning instance : 1

instance ownership changed at 06/15/2004 11:34:19

Last successful Search 06/15/2004 11:34:19

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 12

Extent Map Block Offset: 4294967295

First free datablock : 3

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00019 ext#: 0 blk#: 16 ext size: 16

#blocks in seg. hdr's freelists: 0

#blocks below: 13

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 16 Offset: 0

--一次格式化13个block,第一个exntets

0:Metadata 1:Metadata 2:Metadata 3:75-100% free

4:75-100% free 5:75-100% free 6:75-100% free 7:75-100% free

8:75-100% free 9:75-100% free 10:75-100% free 11:75-100% free

12:75-100% free 13:75-100% free 14:25-50% free 15:75-100% free

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444e3f seq: 0x02 flg: 0x00 tail: 0x4e3f2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 2 nfree: 2 ffree: 0 pdba: 0x01c0000b

opcode:1

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

0x01c00019 Free: 5 Inst: 1

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444e45 seq: 0x02 flg: 0x00 tail: 0x4e452302

frmt: 0x02 chkval: 0x0000 type: 0x23=PAGETABLE SEGMENT HEADER

Extent Control Header

-----------------------------------------------------------------

Extent Header:: spare1: 0 spare2: 0 #extents: 2 #blocks: 32

last map 0x00000000 #maps: 0 offset: 2716

Highwater:: 0x01c00019 ext#: 0 blk#: 16 ext size: 16

#blocks in seg. hdr's freelists: 0

#blocks below: 13

mapblk 0x00000000 offset: 0

Unlocked

--------------------------------------------------------

Low HighWater Mark :

Highwater:: 0x01c00019 ext#: 0 blk#: 16 ext size: 16

#blocks in seg. hdr's freelists: 0

#blocks below: 13

mapblk 0x00000000 offset: 0

Level 1 BMB for High HWM block: 0x01c00009

Level 1 BMB for Low HWM block: 0x01c00009

--------------------------------------------------------

Segment Type: 1 nl2: 1 blksz: 8192 fbsz: 0

L2 Array start offset: 0x00001434

First Level 3 BMB: 0x00000000

L2 Hint for inserts: 0x01c0000a

Last Level 1 BMB: 0x01c00019

Last Level II BMB: 0x01c0000a

Last Level III BMB: 0x00000000

Map Header:: next 0x00000000 #extents: 2 obj#: 15688 flag: 0x20000000

Extent Map

-----------------------------------------------------------------

0x01c00009 length: 16

0x01c00019 length: 16

Auxillary Map

--------------------------------------------------------

Extent 0 : L1 dba: 0x01c00009 Data dba: 0x01c0000c

Extent 1 : L1 dba: 0x01c00019 Data dba: 0x01c0001a

--------------------------------------------------------

Second Level Bitmap block DBAs

--------------------------------------------------------

DBA 1: 0x01c0000a

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

再测试J

[oracle@jumper udump]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Jun 15 11:37:12 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

SQL> @a

SQL> drop tablespace assm including contents and datafiles;

Tablespace dropped.

SQL> create tablespace assm

2 datafile '/data1/oracle/oradata/assm01.dbf'

3 size 10M

4 extent management local uniform size 256K

5 segment space management auto

6 /

Tablespace created.

SQL>

SQL> CREATE TABLE TEST_HWM1 (ID CHAR(2000), NAME CHAR(2000) )

2 Tablespace ASSM

3 STORAGE ( MINEXTENTS 2) PCTFREE 40

4 /

Table created.

SQL>

SQL>

SQL> select EXTENT_ID,FILE_ID,RELATIVE_FNO,BLOCK_ID,BLOCKS

2 from dba_extents

3 where segment_name='TEST_HWM1'

4 /

EXTENT_ID FILE_ID RELATIVE_FNO BLOCK_ID BLOCKS

---------- ---------- ------------ ---------- ----------

0 7 7 9 32

1 7 7 41 32

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL>

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

SQL> !

[oracle@jumper udump]$ ls -sort

total 104

16 -rw-r----- 1 oracle 15744 6月 15 11:13 hsjf_ora_14222.trc

12 -rw-r----- 1 oracle 11888 6月 15 11:14 hsjf_ora_16003.trc

12 -rw-r----- 1 oracle 8325 6月 15 11:22 hsjf_ora_16983.trc

12 -rw-r----- 1 oracle 8326 6月 15 11:26 hsjf_ora_17568.trc

4 -rw-r--r-- 1 oracle 121 6月 15 11:29 b.sql

24 -rw-r----- 1 oracle 23800 6月 15 11:29 hsjf_ora_18039.trc

12 -rw-r----- 1 oracle 8305 6月 15 11:34 hsjf_ora_18807.trc

4 -rw-r--r-- 1 oracle 602 6月 15 11:37 a.sql

8 -rw-r----- 1 oracle 7410 6月 15 11:37 hsjf_ora_19159.trc

[oracle@jumper udump]$ more hsjf_ora_19159.trc

/opt/oracle/admin/hsjf/udump/hsjf_ora_19159.trc

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

ORACLE_HOME = /opt/oracle/product/9.2.0

System name: Linux

Node name: jumper.hurray.com.cn

Release: 2.4.18-14

Version: #1 Wed Sep 4 13:35:50 EDT 2002

Machine: i686

Instance name: hsjf

Redo thread mounted by this instance: 1

Oracle process number: 11

Unix process pid: 19159, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** SESSION ID:(9.118) 2004-06-15 11:37:16.067

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444ea9 seq: 0x02 flg: 0x00 tail: 0x4ea92002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000b poffset: 0

unformatted: 12 total: 16 first useful block: 4

owning instance : 1

instance ownership changed at

Last successful Search

Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295

First free datablock : 4

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c0000d ext#: 0 blk#: 4 ext size: 32

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 16 Offset: 0

0:Metadata 1:Metadata 2:Metadata 3:Metadata

4:unformatted 5:unformatted 6:unformatted 7:unformatted

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444ea9 seq: 0x02 flg: 0x00 tail: 0x4ea92002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000b poffset: 1

unformatted: 16 total: 16 first useful block: 0

owning instance : 1

instance ownership changed at

Last successful Search

Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295

First free datablock : 0

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x00000000 ext#: 0 blk#: 0 ext size: 0

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

HWM Flag: Not Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00019 Length: 16 Offset: 0

0:unformatted 1:unformatted 2:unformatted 3:unformatted

4:unformatted 5:unformatted 6:unformatted 7:unformatted

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444eac seq: 0x02 flg: 0x00 tail: 0x4eac2102

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 4 nfree: 4 ffree: 0 pdba: 0x01c0000c

opcode:1

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

0x01c0000a Free: 5 Inst: 1

0x01c00029 Free: 5 Inst: 1

0x01c0002a Free: 5 Inst: 1

--------------------------------------------------------

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444eb2 seq: 0x02 flg: 0x00 tail: 0x4eb22002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000b poffset: 0

unformatted: 12 total: 16 first useful block: 4

owning instance : 1

instance ownership changed at

Last successful Search

Freeness Status: nf1 0 nf2 0 nf3 0 nf4 0

Extent Map Block Offset: 4294967295

First free datablock : 4

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x00000000 ext#: 0 blk#: 0 ext size: 0

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

HWM Flag: Not Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 16 Offset: 0

0:Metadata 1:Metadata 2:Metadata 3:Metadata

4:unformatted 5:unformatted 6:unformatted 7:unformatted

8:unformatted 9:unformatted 10:unformatted 11:unformatted

12:unformatted 13:unformatted 14:unformatted 15:unformatted

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444eb2 seq: 0x03 flg: 0x00 tail: 0x4eb22003

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000b poffset: 1

unformatted: 0 total: 16 first useful block: 0

owning instance : 1

instance ownership changed at 06/15/2004 11:37:16

Last successful Search 06/15/2004 11:37:16

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 15

Extent Map Block Offset: 4294967295

First free datablock : 0

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00029 ext#: 0 blk#: 32 ext size: 32

#blocks in seg. hdr's freelists: 0 HWM=H29 = 41

#blocks below: 28 HWM= 16 + 16 + 8 + 1= 41

mapblk 0x00000000 offset: 0 注意此HWM下包含了未格式化的block

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00019 Length: 16 Offset: 0 ---此处一次格式化16个block

---这是一次格式化的最大值

0:75-100% free 1:75-100% free 2:75-100% free 3:75-100% free

4:75-100% free 5:75-100% free 6:75-100% free 7:75-100% free

8:75-100% free 9:75-100% free 10:75-100% free 11:25-50% free

12:75-100% free 13:75-100% free 14:75-100% free 15:75-100% free

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444eb2 seq: 0x01 flg: 0x00 tail: 0x4eb22101

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 4 nfree: 4 ffree: 0 pdba: 0x01c0000c

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

0x01c0000a Free: 5 Inst: 1

0x01c00029 Free: 5 Inst: 1

0x01c0002a Free: 5 Inst: 1

--------------------------------------------------------

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

继续插入数据

SQL> @b

SQL> set echo on

SQL> insert into test_hwm1 values('1','dlinger');

1 row created.

SQL> commit;

Commit complete.

SQL>

SQL> alter system dump datafile 7 block min 9 block max 11;

System altered.

[oracle@jumper udump]$ more hsjf_ora_20288.trc

/opt/oracle/admin/hsjf/udump/hsjf_ora_20288.trc

Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

ORACLE_HOME = /opt/oracle/product/9.2.0

System name: Linux

Node name: jumper.hurray.com.cn

Release: 2.4.18-14

Version: #1 Wed Sep 4 13:35:50 EDT 2002

Machine: i686

Instance name: hsjf

Redo thread mounted by this instance: 1

Oracle process number: 12

Unix process pid: 20288, image: oracle@jumper.hurray.com.cn (TNS V1-V3)

*** SESSION ID:(13.32) 2004-06-15 11:44:38.947

Start dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

buffer tsn: 16 rdba: 0x01c00009 (7/9)

scn: 0x0000.01444f44 seq: 0x02 flg: 0x00 tail: 0x4f442002

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000b poffset: 0

unformatted: 0 total: 16 first useful block: 4

owning instance : 1

instance ownership changed at 06/15/2004 11:44:37

Last successful Search 06/15/2004 11:44:37

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 11

Extent Map Block Offset: 4294967295

First free datablock : 4

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x00000000 ext#: 0 blk#: 0 ext size: 0

#blocks in seg. hdr's freelists: 0

#blocks below: 0

mapblk 0x00000000 offset: 0

HWM Flag: Not Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00009 Length: 16 Offset: 0

0:Metadata 1:Metadata 2:Metadata 3:Metadata

4:25-50% free 5:75-100% free 6:75-100% free 7:75-100% free

8:75-100% free 9:75-100% free 10:75-100% free 11:75-100% free

12:75-100% free 13:75-100% free 14:75-100% free 15:75-100% free

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000a (7/10)

scn: 0x0000.01444eb2 seq: 0x03 flg: 0x00 tail: 0x4eb22003

frmt: 0x02 chkval: 0x0000 type: 0x20=FIRST LEVEL BITMAP BLOCK

Dump of First Level Bitmap Block

--------------------------------

nbits : 4 nranges: 1 parent dba: 0x01c0000b poffset: 1

unformatted: 0 total: 16 first useful block: 0

owning instance : 1

instance ownership changed at 06/15/2004 11:37:16

Last successful Search 06/15/2004 11:37:16

Freeness Status: nf1 0 nf2 1 nf3 0 nf4 15

Extent Map Block Offset: 4294967295

First free datablock : 0

Bitmap block lock opcode 0

Locker xid: : 0x0000.000.00000000

Highwater:: 0x01c00029 ext#: 0 blk#: 32 ext size: 32

#blocks in seg. hdr's freelists: 0

#blocks below: 28

mapblk 0x00000000 offset: 0

HWM Flag: HWM Set

--------------------------------------------------------

DBA Ranges :

--------------------------------------------------------

0x01c00019 Length: 16 Offset: 0

0:75-100% free 1:75-100% free 2:75-100% free 3:75-100% free

4:75-100% free 5:75-100% free 6:75-100% free 7:75-100% free

8:75-100% free 9:75-100% free 10:75-100% free 11:25-50% free

12:75-100% free 13:75-100% free 14:75-100% free 15:75-100% free

--------------------------------------------------------

buffer tsn: 16 rdba: 0x01c0000b (7/11)

scn: 0x0000.01444eb2 seq: 0x01 flg: 0x00 tail: 0x4eb22101

frmt: 0x02 chkval: 0x0000 type: 0x21=SECOND LEVEL BITMAP BLOCK

Dump of Second Level Bitmap Block

number: 4 nfree: 4 ffree: 0 pdba: 0x01c0000c

opcode:0

xid:

L1 Ranges :

--------------------------------------------------------

0x01c00009 Free: 5 Inst: 1

0x01c0000a Free: 5 Inst: 1

0x01c00029 Free: 5 Inst: 1

0x01c0002a Free: 5 Inst: 1

--------------------------------------------------------

End dump data blocks tsn: 16 file#: 7 minblk 9 maxblk 11

3. 结论

对于 extents <= 16 blocks

HWM 移动遵循:

1----à extent blocks – metadata

2----à extent blocks

对于 extents > 16 blocks

HWM移动遵循:

每次移动32个blocks，但是HWM包含未格式化的block，每次格式化16个block或者16 –metadata blocks


丢失所有文件、拥有全备份,缺少后增加的文件-www.eygle.com

丢失所有文件、拥有全备份,缺少后增加的文件

Thursday, 2004-10-14 0:15 Eygle

演示几种情况，不做过多说明.

归档模式

拥有所有归档文件及日志文件，丢失所有数据文件及控制文件，后增加的文件无备份，丢失这个文件，拥有控制文件及所有其他文件的历史
备份，以下是一种恢复情况.

1.测试,移除当前所有文件

从备份中恢复数据文件及控制文件(丢失后增加的文件)

SQL> startup;
ORACLE 例程已经启动。

Total System Global Area   47259136 bytes
Fixed Size                   454144 bytes
Variable Size              29360128 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
数据库已经打开。
SQL> archive log start;
已处理的语句
SQL> archive log list;
数据库日志模式            存档模式
自动存档             启用
存档终点            e:\oracle\ora92\RDBMS
最早的概要日志序列     30
下一个存档日志序列   32
当前日志序列           32
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
E:\ORACLE\ORADATA\EYGLE\SYSTEM01.DBF
E:\ORACLE\ORADATA\EYGLE\UNDOTBS01.DBF
E:\ORACLE\ORADATA\EYGLE\EYGLE01.DBF

SQL> create tablespace test datafile 'e:\oracle\oradata\eygle\test01.dbf'
  2  size 5m;

表空间已创建。

SQL> alter system switch logfile;

系统已更改。

SQL> create table t tablespace test as select * from dba_users;

表已创建。

SQL> alter system switch logfile;

系统已更改。

SQL> shutdown abort;
ORACLE 例程已经关闭。
SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production中断开

E:\Oracle\oradata\eygle>mv TEST01.DBF bak

E:\Oracle\oradata\eygle>mkdir bak2

E:\Oracle\oradata\eygle>mv *.* bak2

E:\Oracle\oradata\eygle>ls
bak   bak2

E:\Oracle\oradata\eygle>mv bak\*.* . --从备份中恢复

E:\Oracle\oradata\eygle>ls
CONTROL01.CTL  CONTROL03.CTL  REDO01.LOG     REDO03.LOG     TEMP01.DBF     UNDOTBS01.DBF  bak2
CONTROL02.CTL  EYGLE01.DBF    REDO02.LOG     SYSTEM01.DBF   TEST01.DBF     bak            sqlnet.log

E:\Oracle\oradata\eygle>mv TEST01.DBF bak --移除后增加的这个文件

E:\Oracle\oradata\eygle>ls
CONTROL01.CTL  CONTROL03.CTL  REDO01.LOG     REDO03.LOG     TEMP01.DBF     bak            sqlnet.log
CONTROL02.CTL  EYGLE01.DBF    REDO02.LOG     SYSTEM01.DBF   UNDOTBS01.DBF  bak2

2.开始恢复

E:\Oracle\oradata\eygle>sqlplus "sys/oracle as sysdba"

SQL*Plus: Release 9.2.0.5.0 - Production on 星期三 10月 13 23:50:06 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

已连接到空闲例程。

SQL> startup mount;
ORACLE 例程已经启动。

Total System Global Area   47259136 bytes
Fixed Size                   454144 bytes
Variable Size              29360128 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。

SQL> recover database using backup controlfile until cancel;
ORA-00279: 更改 134694 (在 10/13/2004 22:14:13 生成) 对于线程 1 是必需的
ORA-00289: 建议: E:\ORACLE\ORA92\RDBMS\ARC00032.001
ORA-00280: 更改 134694 对于线程 1 是按序列 # 32 进行的

指定日志: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00283: 恢复会话因错误而取消
ORA-01244: 未命名的数据文件由介质恢复添加至控制文件
ORA-01110: 数据文件 4: 'E:\ORACLE\ORADATA\EYGLE\TEST01.DBF'

ORA-01112: 未启动介质恢复

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
E:\ORACLE\ORADATA\EYGLE\SYSTEM01.DBF
E:\ORACLE\ORADATA\EYGLE\UNDOTBS01.DBF
E:\ORACLE\ORADATA\EYGLE\EYGLE01.DBF
E:\ORACLE\ORA92\DATABASE\UNNAMED00004

注意:由于使用的是备份的控制文件进行恢复，该文件中不包含后增加的文件，恢复过程中会缺省的赋予一个文件名，本案例时:UNNAMED00004

3.更改文件名称继续恢复

SQL> alter database create datafile 'E:\ORACLE\ORA92\DATABASE\UNNAMED00004'
 as 'E:\ORACLE\ORADATA\EYGLE\TEST01.DBF';

数据库已更改。

SQL> recover database using backup controlfile until cancel;
ORA-00279: 更改 134923 (在 10/13/2004 22:40:10 生成) 对于线程 1 是必需的
ORA-00289: 建议: E:\ORACLE\ORA92\RDBMS\ARC00032.001
ORA-00280: 更改 134923 对于线程 1 是按序列 # 32 进行的

指定日志: {=suggested | filename | AUTO | CANCEL}

ORA-00279: 更改 134967 (在 10/13/2004 22:40:40 生成) 对于线程 1 是必需的
ORA-00289: 建议: E:\ORACLE\ORA92\RDBMS\ARC00033.001
ORA-00280: 更改 134967 对于线程 1 是按序列 # 33 进行的
ORA-00278: 此恢复不再需要日志文件 'E:\ORACLE\ORA92\RDBMS\ARC00032.001'

指定日志: {=suggested | filename | AUTO | CANCEL}
E:\Oracle\oradata\eygle\bak2\REDO03.LOG
ORA-00279: 更改 134998 (在 10/13/2004 22:41:05 生成) 对于线程 1 是必需的
ORA-00289: 建议: E:\ORACLE\ORA92\RDBMS\ARC00034.001
ORA-00280: 更改 134998 对于线程 1 是按序列 # 34 进行的
ORA-00278: 此恢复不再需要日志文件 'E:\Oracle\oradata\eygle\bak2\REDO03.LOG'

指定日志: {=suggested | filename | AUTO | CANCEL}
E:\Oracle\oradata\eygle\bak2\REDO01.LOG
ORA-00279: 更改 155020 (在 10/13/2004 22:44:30 生成) 对于线程 1 是必需的
ORA-00289: 建议: E:\ORACLE\ORA92\RDBMS\ARC00035.001
ORA-00280: 更改 155020 对于线程 1 是按序列 # 35 进行的
ORA-00278: 此恢复不再需要日志文件 'E:\Oracle\oradata\eygle\bak2\REDO01.LOG'

指定日志: {=suggested | filename | AUTO | CANCEL}
E:\Oracle\oradata\eygle\bak2\REDO02.LOG
已应用的日志。
完成介质恢复。

SQL> alter database open resetlogs;

数据库已更改。

SQL>

总结:

此案例丢失控制文件，从备份控制文件进行恢复，在进行恢复中，会向控制文件中以缺省规则增加文件，我们可以通过CREATE AS方式修改控制文件中记录.
继续应用所有归档和日志文件可以完成恢复.

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过mailto:eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

原文出处:

http://www.eygle.com/ha/recover.with.backup.except.one.missing.datafile.htm


无备份文件、拥有所有归档的备份-www.eygle.com

无文件备份、拥有所有归档的恢复

Wednesday, 2004-10-13 23:47 Eygle

演示几种情况，不做过多说明.

归档模式

拥有所有归档文件，后增加文件无备份，丢失这个文件，拥有控制文件及所有其他文件，以下是一种恢复情况.

1.启用归档模式,备份

E:\sqlplus "sys/oracle as sysdba"

SQL> startup mount;
ORACLE 例程已经启动。

Total System Global Area   47259136 bytes
Fixed Size                   454144 bytes
Variable Size              29360128 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
SQL> alter database archivelog;

数据库已更改。

SQL> shutdown immediate;
ORA-01109: 数据库未打开

已经卸载数据库。
ORACLE 例程已经关闭。
SQL> host

Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

E:\Oracle\oradata\eygle>dir
 驱动器 E 中的卷是 PRIVATE
 卷的序列号是 ACC3-4340

 E:\Oracle\oradata\eygle 的目录

...
2004-10-13  22:15         1,613,824 CONTROL01.CTL
2004-10-13  22:15         1,613,824 CONTROL02.CTL
2004-10-13  22:15         1,613,824 CONTROL03.CTL
2004-10-13  22:14        10,493,952 EYGLE01.DBF
2004-10-13  22:14        10,486,272 REDO01.LOG
2004-10-13  22:14        10,486,272 REDO02.LOG
2004-10-13  22:14        10,486,272 REDO03.LOG
2004-10-13  22:10               811 sqlnet.log
2004-10-13  22:14       262,152,192 SYSTEM01.DBF
2004-07-03  16:50        41,951,232 TEMP01.DBF
2004-10-13  22:14       209,723,392 UNDOTBS01.DBF
              11 个文件    560,621,867 字节
               2 个目录  1,286,344,704 可用字节

E:\Oracle\oradata\eygle>mkdir bak

E:\Oracle\oradata\eygle>cp *.* bak

E:\Oracle\oradata\eygle>exit

2.创建文件、建表

SQL> startup;
ORACLE 例程已经启动。

Total System Global Area   47259136 bytes
Fixed Size                   454144 bytes
Variable Size              29360128 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
数据库已经打开。
SQL> archive log start;
已处理的语句
SQL> archive log list;
数据库日志模式            存档模式
自动存档             启用
存档终点            e:\oracle\ora92\RDBMS
最早的概要日志序列     30
下一个存档日志序列   32
当前日志序列           32
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
E:\ORACLE\ORADATA\EYGLE\SYSTEM01.DBF
E:\ORACLE\ORADATA\EYGLE\UNDOTBS01.DBF
E:\ORACLE\ORADATA\EYGLE\EYGLE01.DBF

SQL> create tablespace test datafile 'e:\oracle\oradata\eygle\test01.dbf'
  2  size 5m;

表空间已创建。

SQL> alter system switch logfile;

系统已更改。

SQL> create table t tablespace test as select * from dba_users;

表已创建。

SQL> alter system switch logfile;

系统已更改。

SQL> shutdown abort;
ORACLE 例程已经关闭。
SQL> exit
从Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.5.0 - Production中断开

E:\Oracle\oradata\eygle>mv TEST01.DBF bak

3.恢复

E:\Oracle\oradata\eygle>sqlplus "sys/oracle as sysdba"

SQL*Plus: Release 9.2.0.5.0 - Production on 星期三 10月 13 22:41:48 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

已连接到空闲例程。

SQL> startup
ORACLE 例程已经启动。

Total System Global Area   47259136 bytes
Fixed Size                   454144 bytes
Variable Size              29360128 bytes
Database Buffers           16777216 bytes
Redo Buffers                 667648 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 4 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 4: 'E:\ORACLE\ORADATA\EYGLE\TEST01.DBF'

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
E:\ORACLE\ORADATA\EYGLE\SYSTEM01.DBF
E:\ORACLE\ORADATA\EYGLE\UNDOTBS01.DBF
E:\ORACLE\ORADATA\EYGLE\EYGLE01.DBF
E:\ORACLE\ORADATA\EYGLE\TEST01.DBF

SQL> alter database create datafile 'E:\ORACLE\ORADATA\EYGLE\TEST01.DBF';

数据库已更改。

SQL> recover datafile 'E:\ORACLE\ORADATA\EYGLE\TEST01.DBF';
完成介质恢复。
SQL> alter database open;

数据库已更改。

SQL> host
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

E:\Oracle\oradata\eygle>ls -l
total 1105221
-rwxrwxrwa   1 Administrators  SYSTEM          1613824 Oct 13 23:42 CONTROL01.CTL
-rwxrwxrwa   1 Administrators  SYSTEM          1613824 Oct 13 23:42 CONTROL02.CTL
-rwxrwxrwa   1 Administrators  SYSTEM          1613824 Oct 13 23:42 CONTROL03.CTL
-rwxrwxrwa   1 Administrators  SYSTEM          10493952 Oct 13 23:44 EYGLE01.DBF
-rwxrwxrwa   1 Administrators  SYSTEM          10486272 Oct 13 23:44 REDO01.LOG
-rwxrwxrwa   1 Administrators  SYSTEM          10486272 Oct 13 23:44 REDO02.LOG
-rwxrwxrwa   1 Administrators  SYSTEM          10486272 Oct 13 23:44 REDO03.LOG
-rwxrwxrwa   1 Administrators  SYSTEM          262152192 Oct 13 23:44 SYSTEM01.DBF
-rwxrwxrwa   1 Administrators  SYSTEM          41951232 Jul  3 17:50 TEMP01.DBF
-rwxrwxrwa   1 Administrators  SYSTEM          5251072 Oct 13 23:44 TEST01.DBF
-rwxrwxrwa   1 Administrators  SYSTEM          209723392 Oct 13 23:44 UNDOTBS01.DBF
drwxrwxrwx   1 gqgai           None                  0 Oct 13 23:41 bak
-rwxrwxrwa   1 gqgai           None                811 Oct 13 23:10 sqlnet.log

E:\Oracle\oradata\eygle>ls -l TEST01.DBF
-rwxrwxrwa   1 Administrators  SYSTEM          5251072 Oct 13 23:44 TEST01.DBF

E:\Oracle\oradata\eygle>

总结:

此案例拥有当前控制文件，控制文件中包含了丢失文件信息，所以可以通过create datafile方式重新创建文件，通过控制文件中记录的文件
信息、SCN、检查点等信息，应用归档日志进行恢复，可以完成完全恢复.

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过mailto:eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

原文出处:

http://www.eygle.com/ha/recover.without.datafile.backup.htm


How.To.Delete.obsolete.Backupset-www.eygle.com

Use RMAN to Manage BackupSet

Tuesday, 2004-10-12 14:12 Eygle

With Oracle 9iR2, We have a new way to let RMAN to manage backupset better.
That is CONFIGURE RETENTION POLICY command .

If we have enough backups to meet a specific recovery window.
We can also tell RMAN to keep a specific number of copies of datafiles and controlfiles.

For example:
If I have enough backupset to recover the database to seven days ago, we can issue:

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

Moreover, to insure that we have at least two copies of each datafile and controlfile backup, we can issue:

CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

RMAN will keeps all archived redo logs and incremental backups necessary to insure the retention policies can be met.
When a backup piece is no longer needed, RMAN marks it as obsolete.

If we want to clear out all obsolete backup files, we can simply issue DELETE OBSOLETE;
RMAN command and RMAN handles the deletion of the corresponding physical files.

So,Under Oracle9iR2,We can use RMAN to manage all of us backupset. It's very easy and convenience.

Some testing is following:

1.Use CONFIGURE to change the setting

RMAN> show all;

RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
RMAN configuration has no stored or default parameters
RMAN configuration has no stored or default parameters
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/opt/oracle/product/9.2.0/dbs/snapcf_avatar.f'; # default

RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters are successfully stored

RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 2;

old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
new RMAN configuration parameters are successfully stored

2.You may Need CROSSCHECK

If you have delete your backupset manual ,you may need to CROSSCHECK first.

RMAN> crosscheck backupset;

using channel ORA_DISK_1
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/full_1_531282606 recid=262 stamp=531282620
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/full_1_531283153 recid=263 stamp=531283155
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/full_1_531887405 recid=278 stamp=531887428
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/full_1_531887992 recid=279 stamp=531887995
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/full_1_532492206 recid=293 stamp=532492220
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/full_1_532492817 recid=294 stamp=532492820
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533097005 recid=310 stamp=533097011
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533097101 recid=311 stamp=533097108
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533097286 recid=312 stamp=533097293
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533097643 recid=313 stamp=533097643
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533701806 recid=328 stamp=533701808
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533701901 recid=329 stamp=533701910
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533702110 recid=330 stamp=533702118
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_533702477 recid=331 stamp=533702477
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_534306605 recid=346 stamp=534306608
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_534306700 recid=347 stamp=534306710
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_534306927 recid=348 stamp=534306934
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_534307344 recid=349 stamp=534307345
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_534911405 recid=362 stamp=534911428
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_535516204 recid=370 stamp=535516227
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_536121006 recid=382 stamp=536121028
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_536725806 recid=397 stamp=536725824
crosschecked backup piece: found to be 'EXPIRED'
backup piece handle=/data1/orabak/current/full_1_537330605 recid=412 stamp=537330625
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538540208.arc recid=436 stamp=538540209
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538713016.arc recid=437 stamp=538713017
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538713196.arc recid=438 stamp=538713198
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538713364.arc recid=439 stamp=538713365
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538799412.arc recid=440 stamp=538799413
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538799577.arc recid=441 stamp=538799578
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538885808.arc recid=442 stamp=538885809
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538885931.arc recid=443 stamp=538885932
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538972208.arc recid=444 stamp=538972209
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch538972344.arc recid=445 stamp=538972345
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch539058607.arc recid=446 stamp=539058608
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch539058709.arc recid=447 stamp=539058710
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch539145011.arc recid=448 stamp=539145012
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch539145126.arc recid=449 stamp=539145127
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/full_1_539231405 recid=450 stamp=539231419
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/oracle/product/9.2.0/dbs/e7g283jl_1_1 recid=451 stamp=539233910
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/opt/oracle/product/9.2.0/dbs/e8g283la_1_1 recid=452 stamp=539233963
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch539317809.arc recid=453 stamp=539317810
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/data1/orabak/current/arch539317932.arc recid=454 stamp=539317933
Crosschecked 42 objects

With this step ,Rman will check does these file is exists on your disk.

If a backup piece is unreadable or absent, then RMAN marks the backup piece EXPIRED in the output of the list command
and the recovery catalog views.
If it was marked EXPIRED but is now available, RMAN marks the backup piece as AVAILABLE in the output of the list
command and the recovery catalog views.

3.DELETE OBSOLETE

Now you can use rman to list and delete obsolete file from disk.

RMAN> delete obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to redundancy 2
using channel ORA_DISK_1
Deleting the following obsolete backups and copies:
Type                 Key    Completion Time    Filename/Handle
-------------------- ------ ------------------ --------------------
Backup Set           262    12-JUL-04
  Backup Piece       262    12-JUL-04          /data1/orabak/full_1_531282606
Backup Set           263    12-JUL-04
  Backup Piece       263    12-JUL-04          /data1/orabak/full_1_531283153
Backup Set           278    19-JUL-04
  Backup Piece       278    19-JUL-04          /data1/orabak/full_1_531887405
Backup Set           279    19-JUL-04
  Backup Piece       279    19-JUL-04          /data1/orabak/full_1_531887992
Backup Set           293    26-JUL-04
  Backup Piece       293    26-JUL-04          /data1/orabak/full_1_532492206
Backup Set           294    26-JUL-04
  Backup Piece       294    26-JUL-04          /data1/orabak/full_1_532492817
Backup Set           310    02-AUG-04
  Backup Piece       310    02-AUG-04          /data1/orabak/current/full_1_533097005
Backup Set           311    02-AUG-04
  Backup Piece       311    02-AUG-04          /data1/orabak/current/full_1_533097101
Backup Set           312    02-AUG-04
  Backup Piece       312    02-AUG-04          /data1/orabak/current/full_1_533097286
Backup Set           313    02-AUG-04
  Backup Piece       313    02-AUG-04          /data1/orabak/current/full_1_533097643
Backup Set           328    09-AUG-04
  Backup Piece       328    09-AUG-04          /data1/orabak/current/full_1_533701806
Backup Set           329    09-AUG-04
  Backup Piece       329    09-AUG-04          /data1/orabak/current/full_1_533701901
Backup Set           330    09-AUG-04
  Backup Piece       330    09-AUG-04          /data1/orabak/current/full_1_533702110
Backup Set           331    09-AUG-04
  Backup Piece       331    09-AUG-04          /data1/orabak/current/full_1_533702477
Backup Set           346    16-AUG-04
  Backup Piece       346    16-AUG-04          /data1/orabak/current/full_1_534306605
Backup Set           347    16-AUG-04
  Backup Piece       347    16-AUG-04          /data1/orabak/current/full_1_534306700
Backup Set           348    16-AUG-04
  Backup Piece       348    16-AUG-04          /data1/orabak/current/full_1_534306927
Backup Set           349    16-AUG-04
  Backup Piece       349    16-AUG-04          /data1/orabak/current/full_1_534307344
Backup Set           362    23-AUG-04
  Backup Piece       362    23-AUG-04          /data1/orabak/current/full_1_534911405
Backup Set           370    30-AUG-04
  Backup Piece       370    30-AUG-04          /data1/orabak/current/full_1_535516204
Backup Set           382    06-SEP-04
  Backup Piece       382    06-SEP-04          /data1/orabak/current/full_1_536121006
Backup Set           397    13-SEP-04
  Backup Piece       397    13-SEP-04          /data1/orabak/current/full_1_536725806
Backup Set           412    20-SEP-04
  Backup Piece       412    20-SEP-04          /data1/orabak/current/full_1_537330605
Backup Set           436    03-OCT-04
  Backup Piece       436    03-OCT-04          /data1/orabak/current/arch538540208.arc
Backup Set           437    05-OCT-04
  Backup Piece       437    05-OCT-04          /data1/orabak/current/arch538713016.arc
Backup Set           438    05-OCT-04
  Backup Piece       438    05-OCT-04          /data1/orabak/current/arch538713196.arc
Backup Set           439    05-OCT-04
  Backup Piece       439    05-OCT-04          /data1/orabak/current/arch538713364.arc
Backup Set           440    06-OCT-04
  Backup Piece       440    06-OCT-04          /data1/orabak/current/arch538799412.arc
Backup Set           441    06-OCT-04
  Backup Piece       441    06-OCT-04          /data1/orabak/current/arch538799577.arc
Backup Set           442    07-OCT-04
  Backup Piece       442    07-OCT-04          /data1/orabak/current/arch538885808.arc
Backup Set           443    07-OCT-04
  Backup Piece       443    07-OCT-04          /data1/orabak/current/arch538885931.arc
Backup Set           444    08-OCT-04
  Backup Piece       444    08-OCT-04          /data1/orabak/current/arch538972208.arc
Backup Set           445    08-OCT-04
  Backup Piece       445    08-OCT-04          /data1/orabak/current/arch538972344.arc
Backup Set           446    09-OCT-04
  Backup Piece       446    09-OCT-04          /data1/orabak/current/arch539058607.arc
Backup Set           447    09-OCT-04
  Backup Piece       447    09-OCT-04          /data1/orabak/current/arch539058709.arc
Backup Set           448    10-OCT-04
  Backup Piece       448    10-OCT-04          /data1/orabak/current/arch539145011.arc
Backup Set           449    10-OCT-04
  Backup Piece       449    10-OCT-04          /data1/orabak/current/arch539145126.arc
Backup Set           451    11-OCT-04
  Backup Piece       451    11-OCT-04          /opt/oracle/product/9.2.0/dbs/e7g283jl_1_1

Do you really want to delete the above objects (enter YES or NO)? YES
deleted backup piece
backup piece handle=/data1/orabak/full_1_531282606 recid=262 stamp=531282620
deleted backup piece
backup piece handle=/data1/orabak/full_1_531283153 recid=263 stamp=531283155
deleted backup piece
backup piece handle=/data1/orabak/full_1_531887405 recid=278 stamp=531887428
deleted backup piece
backup piece handle=/data1/orabak/full_1_531887992 recid=279 stamp=531887995
deleted backup piece
backup piece handle=/data1/orabak/full_1_532492206 recid=293 stamp=532492220
deleted backup piece
backup piece handle=/data1/orabak/full_1_532492817 recid=294 stamp=532492820
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533097005 recid=310 stamp=533097011
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533097101 recid=311 stamp=533097108
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533097286 recid=312 stamp=533097293
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533097643 recid=313 stamp=533097643
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533701806 recid=328 stamp=533701808
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533701901 recid=329 stamp=533701910
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533702110 recid=330 stamp=533702118
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_533702477 recid=331 stamp=533702477
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_534306605 recid=346 stamp=534306608
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_534306700 recid=347 stamp=534306710
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_534306927 recid=348 stamp=534306934
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_534307344 recid=349 stamp=534307345
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_534911405 recid=362 stamp=534911428
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_535516204 recid=370 stamp=535516227
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_536121006 recid=382 stamp=536121028
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_536725806 recid=397 stamp=536725824
deleted backup piece
backup piece handle=/data1/orabak/current/full_1_537330605 recid=412 stamp=537330625
deleted backup piece
backup piece handle=/data1/orabak/current/arch538540208.arc recid=436 stamp=538540209
deleted backup piece
backup piece handle=/data1/orabak/current/arch538713016.arc recid=437 stamp=538713017
deleted backup piece
backup piece handle=/data1/orabak/current/arch538713196.arc recid=438 stamp=538713198
deleted backup piece
backup piece handle=/data1/orabak/current/arch538713364.arc recid=439 stamp=538713365
deleted backup piece
backup piece handle=/data1/orabak/current/arch538799412.arc recid=440 stamp=538799413
deleted backup piece
backup piece handle=/data1/orabak/current/arch538799577.arc recid=441 stamp=538799578
deleted backup piece
backup piece handle=/data1/orabak/current/arch538885808.arc recid=442 stamp=538885809
deleted backup piece
backup piece handle=/data1/orabak/current/arch538885931.arc recid=443 stamp=538885932
deleted backup piece
backup piece handle=/data1/orabak/current/arch538972208.arc recid=444 stamp=538972209
deleted backup piece
backup piece handle=/data1/orabak/current/arch538972344.arc recid=445 stamp=538972345
deleted backup piece
backup piece handle=/data1/orabak/current/arch539058607.arc recid=446 stamp=539058608
deleted backup piece
backup piece handle=/data1/orabak/current/arch539058709.arc recid=447 stamp=539058710
deleted backup piece
backup piece handle=/data1/orabak/current/arch539145011.arc recid=448 stamp=539145012
deleted backup piece
backup piece handle=/data1/orabak/current/arch539145126.arc recid=449 stamp=539145127
deleted backup piece
backup piece handle=/opt/oracle/product/9.2.0/dbs/e7g283jl_1_1 recid=451 stamp=539233910
Deleted 38 objects

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过mailto:eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

原文出处:

http://www.eygle.com/faq/How.To.Use.Rman.Delete.obsolete.backupset.htm


Install Oracle9iRac On Solaris + EMC + Veritas ---All the things you should know-www.eygle.com

Install Oracle9iRac On Solaris + EMC + Veritas ---All the things you should know

Wednesday, 2004-09-22 18:17 eygle

本案例用到的主要软硬件如下:

主机:Sun-Fire-V210
操作系统:SunOS 5.9 Generic_117171-07
光纤卡:Emulex LightPulse FC9002L
阵列:EMC CLARiiON CX500
Cluster软件:VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0
Oracle版本:Oracle9.2.0.4

1.安装操作系统

安装基本系统以后,应用到最新的补丁

# uname -a
SunOS cluster1 5.9 Generic_117171-07 sun4u sparc SUNW,Sun-Fire-V210

配置hosts文件,设置相应别名,配置一个浮动ip(配置Cluster时需要)

# cat /etc/hosts
#
# Internet host table
#
127.0.0.1       localhost
172.16.33.71    cluster2        cluster2.hurray.com.cn          loghost
172.16.33.70    cluster1        cluster1.hurray.com.cn
172.16.33.74    cluster         cluster.hurray.com.cn

2.安装光纤卡

本例使用的是Emulex的光线卡,Emulex LightPulse FC9002L光线卡需要到网站上下载最新的驱动安装

使用光盘上的驱动系统会莫名其妙的循环重起,极度郁闷

光线卡安装日志参考:

Emulex_LightPulse_FC9002L_Solaris9_Install

光纤卡安装以后需要配置两个参数文件:

Emulex光纤卡lpfc配置文件的修改

完成这个步骤后重新启动机器,使配置生效,把主机和光纤交换机及EMC阵列相连接

3.安装EMC Navisphere AGENT(NAVIAGENT)

安装EMC Navisphere AGENT(NAVIAGENT)

安装完成后,重新启动服务器,此时agent会自动启动,自EMC阵列控制器上应该可以看到主机节点

4.分配磁盘组

在EMC阵列端,把划好的磁盘组分配给主机

分配磁盘组(EMC阵列)

分配磁盘组后,重起主机

5.安装VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0软件

安装Veritas Storage Fundation For Oracle Rac4.0

6.配置共享磁盘

使用Volume Manager配置共享磁盘

7.修改系统内核参数

为安装Oracle做准备

在/etc/system文件末尾追加以下参数,两台主机都需要修改:

* kernal parameter for Oracle database  add by:gqgai
set shmsys:shminfo_shmmax=4294967295
set shmsys:shminfo_shmmin=1
set shmsys:shminfo_shmmni=100
set shmsys:shminfo_shmseg=10

set semsys:seminfo_semmni=1024
set semsys:seminfo_semmsl=1510
set semsys:seminfo_semmns=3010
set semsys:seminfo_semopm=100
set semsys:seminfo_semvmx=32767

修改后重新启动主机

8.划分裸设备

根据实际需要划分裸设备

vxassist -g oradg -U gen make system 800m
vxassist -g oradg -U gen make temp   1000m
vxassist -g oradg -U gen make users  1000m

vxassist -g oradg -U gen make redo101 100m
vxassist -g oradg -U gen make redo102 100m
vxassist -g oradg -U gen make redo103 100m

vxassist -g oradg -U gen make redo201 100m
vxassist -g oradg -U gen make redo202 100m
vxassist -g oradg -U gen make redo203 100m

vxassist -g oradg -U gen make undo11 1000m
vxassist -g oradg -U gen make undo21 1000m

vxassist -g oradg -U gen make spfile  100m

vxassist -g oradg -U gen make ctlfile1  100m
vxassist -g oradg -U gen make ctlfile2  100m

vxassist -g oradg -U gen make srvcfg 500m

修改属主信息:

vxedit -g oradg set user=oracle mode=644 system
vxedit -g oradg set user=oracle mode=644 temp
vxedit -g oradg set user=oracle mode=644 users

vxedit -g oradg set user=oracle mode=644 redo101
vxedit -g oradg set user=oracle mode=644 redo102
vxedit -g oradg set user=oracle mode=644 redo103

vxedit -g oradg set user=oracle mode=644 redo201
vxedit -g oradg set user=oracle mode=644 redo202
vxedit -g oradg set user=oracle mode=644 redo203

vxedit -g oradg set user=oracle mode=644 undo11
vxedit -g oradg set user=oracle mode=644 undo21

vxedit -g oradg set user=oracle mode=644 spfile

vxedit -g oradg set user=oracle mode=644 ctlfile1
vxedit -g oradg set user=oracle mode=644 ctlfile2

vxedit -g oradg set user=oracle mode=644 srvcfg

9.复制相应的库文件

# cd /opt/ORCLcluster/lib
# ls
9iR2
# cd *
# ls
libskgxn2_32.so    libskgxn2_32.so.1  libskgxn2_64.so    libskgxn2_64.so.1  libskgxp92_32.so   libskgxp92_64.so
# cp libskgxn2_64.so ../libskgxn2.so
# ls
libskgxn2_32.so    libskgxn2_32.so.1  libskgxn2_64.so    libskgxn2_64.so.1  libskgxp92_32.so   libskgxp92_64.so

10.安装Oracle软件

安装Oracle9i软件

11.检查srvcfg设置

检查/var/opt/oracle下srvConfig.loc文件,确保包含同样的链接:

srvconfig_loc=/dev/vx/rdsk/oradg/srvcfg

两边应该有同样的配置,否则gsd则不能启动.

12.配置裸设备列表

设置DBCA_RAW_CONFIG环境变量

创建DBCA_RAW_CONFIG.txt配置文件

control1=/dev/vx/rdsk/oradg/ctlfile1
control2=/dev/vx/rdsk/oradg/ctlfile2
redo1_1=/dev/vx/rdsk/oradg/redo101
redo1_2=/dev/vx/rdsk/oradg/redo102
redo1_3=/dev/vx/rdsk/oradg/redo103
redo2_1=/dev/vx/rdsk/oradg/redo201
redo2_2=/dev/vx/rdsk/oradg/redo202
redo2_3=/dev/vx/rdsk/oradg/redo203
spfile=/dev/vx/rdsk/oradg/spfile
system=/dev/vx/rdsk/oradg/system
temp=/dev/vx/rdsk/oradg/temp
users=/dev/vx/rdsk/oradg/users
undotbs1=/dev/vx/rdsk/oradg/undo11
undotbs2=/dev/vx/rdsk/oradg/undo21

在user profile文件中设置:

DBCA_RAW_CONFIG=/opt/oracle/admin/Rac9i/create/DBCA_RAW_CONFIG.txt
export DBCA_RAW_CONFIG

13.开始创建数据库

创建Oracle9i Rac数据库


安装Oracle9i RAC软件-www.eygle.com

安装Oracle9i RAC软件

Wednesday, 2004-09-22 18:17 eygle

安装Oracle软件,给出一些图例:

1. 设置Oracle用户环境变量

修改.profile文件,增加如下环境变量:

ORACLE_BASE=/opt/oracle
export ORACLE_BASE

ORACLE_HOME=/opt/oracle/product/9.2.0
export ORACLE_HOME

#you should set differnt ORACLE_SID id the different node

ORACLE_SID=Rac9i1
export ORACLE_SID

ORACLE_ADMIN=$ORACLE_HOME/admin
export ORACLE_ADMIN

PATH=$PATH:$ORACLE_HOME/bin:/opt/bin:/usr/cluster/bin:/etc/vx/bin:/opt/VRTSvxvm/bin:/bin:/usr/bin:/usr/ccs/bin:/usr/sbin
export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/openwin/lib:/usr/db/lib:/usr/lib:/usr/up/vortex/lib
export LD_LIBRARY_PATH

TNS_ADMIN=$ORACLE_HOME/network/admin
export TNS_ADMIN

NLS_LANG=AMERICAN_CHINA.ZHS16GBK

export ORACLE_BASE ORACLE_HOME ORACLE_SID NLS_LANG

SRVM_SHARED_CONFIG=/dev/vx/rdsk/oradg/srvcfg
export SRVM_SHARED_CONFIG

DBCA_RAW_CONFIG=/opt/oracle/admin/Rac9i/create/DBCA_RAW_CONFIG.txt
export DBCA_RAW_CONFIG

2.设置rsh支持

编辑.rhost文件

$ id
uid=800(oracle) gid=800(dba)
$ more $HOME/.rhosts
+
$ hostname
cluster1
$ rsh cluster2 date
Sun Sep  5 15:46:27 CST 2004FIG

两个节点都要设置.

3.用Oracle用户登录

执行 ./runInstaller

4.选择在两个节点同时安装

5.选择安装介质路径

6.安装Oracle软件

7.选择自定义安装

8.选择合适的选件

9.选择裸设备设置shared Configuration文件

10.不选择创建数据库

11.确认选件

12.开始安装

13.执行监听器典型配置

14.完成安装

15.安装补丁

先升级GUI,再安装Patchset 9.2.0.4.0

至此,软件部分安装完毕.


创建Oracle9i RAC数据库-www.eygle.com

创建Oracle9i RAC数据库

Wednesday, 2004-09-22 18:15 eygle

创建Oracle9i RAC数据库,给出一些图例:

1. 设置Oracle用户环境变量

修改.profile文件,增加如下环境变量:

DBCA_RAW_CONFIG=/opt/oracle/admin/Rac9i/create/DBCA_RAW_CONFIG.txt
export DBCA_RAW_CONFIG

2.设置rsh支持

编辑.rhost文件

$ id
uid=800(oracle) gid=800(dba)
$ more $HOME/.rhosts
+
$ hostname
cluster1
$ rsh cluster2 date
Sun Sep  5 15:46:27 CST 2004FIG

两个节点都要设置.

3.用Oracle用户登录

执行 dbca

4.选择安装Cluster Database

5.创建数据库

6.选择同时安装两个节点

7.选择新建数据库

8.选择数据库名称

9.去掉不需要的组件

10.选择合适的字符集

11. spfile选择指定的裸设备

12.各数据文件及对应裸设备

13.配置完成以后开始数据库的创建

14.生成创建脚本

15. 开始创建数据库

16.完成创建

17.更改初始口令

18.察看两个实例状态

至此,数据库的创建成功完成.


模拟及修复数据块损坏-eygle.com

Oracle中模拟及修复数据块损坏

通过试验模拟及解决数据块损坏

itpub link:

http://www.itpub.net/showthread.php?threadid=201766

1.插入数据

E:\Oracle\ora92\bin>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on 星期一 3月 8 20:27:15 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
E:\ORACLE\ORADATA\EYGLE\SYSTEM01.DBF
E:\ORACLE\ORADATA\EYGLE\UNDOTBS01.DBF
E:\ORACLE\ORADATA\EYGLE\EYGLE01.DBF

SQL> create tablespace block
2 datafile 'e:\oracle\oradata\eygle\block.dbf'
3 size 1M
4 extent management local;

表空间已创建。

SQL> alter user eygle default tablespace block;

用户已更改。

SQL> alter user eygle quota unlimited on block;

用户已更改。

SQL> connect eygle/eygle
已连接。

SQL> create table t as select * from dba_users;

表已创建。

SQL> insert into t select * from t;

已创建8行。

SQL> /

已创建16行。

SQL> /

已创建32行。

SQL> /

已创建64行。

SQL> /

已创建128行。

SQL> /

已创建256行。

SQL> /

已创建512行。

SQL> /

已创建1024行。

SQL> /

已创建2048行。

SQL> /

已创建4096行。

SQL> /
insert into t select * from t
*
ERROR 位于第 1 行:
ORA-01653: 表EYGLE.T无法通过8（在表空间BLOCK中）扩展

SQL> commit;

提交完成。

SQL> alter system checkpoint;

系统已更改。

SQL> select count(*) from t;

COUNT(*)
----------
8192

SQL> connect / as sysdba
已连接。
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。

2.损坏数据文件

关闭数据库后用Ultredit编辑数据文件，随便更改几个字符.然后启动数据库.

SQL> startup
ORACLE 例程已经启动。

Total System Global Area 101785252 bytes
Fixed Size 454308 bytes
Variable Size 75497472 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
数据库装载完毕。
数据库已经打开。
SQL> select count(*) from eygle.t;
select count(*) from eygle.t
*
ERROR 位于第 1 行:
ORA-01578: ORACLE 数据块损坏（文件号4，块号35）
ORA-01110: 数据文件 4: 'E:\ORACLE\ORADATA\EYGLE\BLOCK.DBF'

SQL>

此时如果查询该表,会出现错误,数据块损坏无法读取.

有个内部工具BBED也可以用来编辑数据块的内容

3.使用DBV检查数据文件

E:\Oracle\oradata\eygle>dbv file=block.dbf blocksize=8192

DBVERIFY: Release 9.2.0.4.0 - Production on 星期一 3月 8 20:48:50 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

DBVERIFY - 验证正在开始 : FILE = block.dbf
标记为损坏的页35
***
Corrupt block relative dba: 0x01000023 (file 4, block 35)
Bad check value found during dbv:
Data in bad block -
type: 6 format: 2 rdba: 0x01000023
last change scn: 0x0000.00049097 seq: 0x1 flg: 0x06
consistency value in tail: 0x90970601
check value in block header: 0xd6cb, computed block checksum: 0x2c0a
spare1: 0x0, spare2: 0x0, spare3: 0x0
***

标记为损坏的页69
***
Corrupt block relative dba: 0x01000045 (file 4, block 69)
Bad check value found during dbv:
Data in bad block -
type: 6 format: 2 rdba: 0x01000045
last change scn: 0x0000.00049097 seq: 0x1 flg: 0x06
consistency value in tail: 0x90970601
check value in block header: 0x33d1, computed block checksum: 0x653
spare1: 0x0, spare2: 0x0, spare3: 0x0
***

DBVERIFY - 验证完成

检查的页总数 ：128
处理的页总数（数据）：117
失败的页总数（数据）：0
处理的页总数（索引）：0
失败的页总数（索引）：0
处理的页总数（其它）：9
处理的总页数 (段) : 0
失败的总页数 (段) : 0
空的页总数 ：0
标记为损坏的总页数：2
汇入的页总数 ：0

dbv检测到坏块.

4.寻求恢复

在这种情况下，如果有备份，需要从备份中恢复
如果没有备份，那么坏块部分的数据肯定要丢失了

在这个时候导出是不允许的:

E:\>exp eygle/eygle file=t.dmp tables=t

Export: Release 9.2.0.4.0 - Production on 星期一 3月 8 20:54:15 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集

即将导出指定的表通过常规路径 ...
. . 正在导出表 T
EXP-00056: 遇到 ORACLE 错误 1578
ORA-01578: ORACLE 数据块损坏（文件号4，块号35）
ORA-01110: 数据文件 4: 'E:\ORACLE\ORADATA\EYGLE\BLOCK.DBF'
导出成功终止，但出现警告。

5.恢复步骤

当然，对于不同的情况需要区别对待

首先你需要检查损坏的对象，使用以下SQL：

SQL> SELECT tablespace_name, segment_type, owner, segment_name
2 FROM dba_extents
3 WHERE file_id = 4
4 and 35 between block_id AND block_id + blocks - 1
5 ;

TABLESPACE_NAME SEGMENT_TYPE OWNER SEGMENT_NAME
---------------------------------------------------------------------------
BLOCK TABLE EYGLE T

如果损失的是数据,ok
我们可以设置内部事件，使exp跳过这些损坏的block

SQL> ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10';

系统已更改。

note:

ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10' ;

内部事件，设置在全表扫描时跳过损坏的数据块.

然后我们可以导出未损坏的数据

SQL> host
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

E:\

E:\>exp eygle/eygle file=t.dmp tables=t

Export: Release 9.2.0.4.0 - Production on 星期一 3月 8 20:57:13 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集

即将导出指定的表通过常规路径 ...
. . 正在导出表 T 8036 行被导出
在没有警告的情况下成功终止导出。

这时候数据成功导出.
然后我们可以drop table，recreate，然后导入数据

本例中
我们损失了

8192 - 8036 = 156 行数据

SQL> connect eygle/eygle
已连接。
SQL> drop table t;

表已丢弃。

SQL> host
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

E:\Oracle\ora92\bin>cd \

E:\>imp eygle/eygle file=t.dmp tables=t

Import: Release 9.2.0.4.0 - Production on 星期一 3月 8 21:12:38 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

经由常规路径导出由EXPORT:V09.02.00创建的文件
已经完成ZHS16GBK字符集和AL16UTF16 NCHAR 字符集中的导入
. 正在将EYGLE的对象导入到 EYGLE
. . 正在导入表 "T" 8036行被导入
成功终止导入，但出现警告。

E:\>exit

SQL> select count(*) from t;

COUNT(*)
----------
8036

完成数据恢复

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Dataguard配置Step by Step-www.eygle.com

Dataguard配置Step by Step

1.主节点备份并生成备用数据库控制文件

设置主节点为force Logging模式(为了双向切换,建议备用节点也设置为force logging模式)
ALTER DATABASE FORCE LOGGING;

设置主节点为归档模式

登陆主节点,进行数据库备份，并生成备用数据库控制文件

Last login: Mon Aug  9 16:46:47 2004 from 172.16.32.65
[root@standby root]# su - oracle
[oracle@standby oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Aug 16 10:16:18 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  135337420 bytes
Fixed Size                   452044 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.

SQL> select name from v$datafile;

NAME
------------------------------------------------------------
/opt/oracle/oradata/primary/system01.dbf
/opt/oracle/oradata/primary/undotbs01.dbf
/opt/oracle/oradata/primary/users01.dbf

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
[oracle@standby oracle]$ ls
admin  dictionary.ora  jre  oradata  oraInventory  oui  product  soft

[oracle@standby oracle]$ tar -cvf oradata.tar oradata
oradata/
oradata/primary/
oradata/primary/archive/
oradata/primary/control01.ctl
oradata/primary/control02.ctl
oradata/primary/control03.ctl
oradata/primary/redo01.log
oradata/primary/redo02.log
oradata/primary/redo03.log
oradata/primary/system01.dbf
oradata/primary/undotbs01.dbf
oradata/primary/temp01.dbf
oradata/primary/users01.dbf

[oracle@standby oracle]$ ls -l *.tar
-rw-r--r--    1 oracle   dba      576512000 Aug 16 10:22 oradata.tar
[oracle@standby oracle]$ id
uid=800(oracle) gid=800(dba) groups=800(dba)
[oracle@standby oracle]$ hostname
standby
[oracle@standby oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Aug 16 10:27:54 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  135337420 bytes
Fixed Size                   452044 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /opt/oracle/oradata/primary/archive
Oldest online log sequence     88
Next log sequence to archive   90
Current log sequence           90
SQL> alter database create standby controlfile as '/opt/oracle/stdcotrl.ctl';

Database altered.

SQL> !
ls[oracle@standby oracle]$ ls
admin  dictionary.ora  jre  oradata  oradata.tar  oraInventory  oui  product  soft  stdcotrl.ctl

2.从主节点创建pfile文件

SQL> create pfile from spfile;

File created.

SQL> !

[oracle@standby oracle]$ cd $ORACLE_HOME/dbs
[oracle@standby dbs]$ ls
initdw.ora init.ora initprimary.ora lkPRIMARY orapwprimary spfileprimary.ora sqlnet.log

3.登陆备用节点,ftp获得数据库文件、备用控制文件及参数文件

Last login: Mon Aug 16 08:47:58 2004 from 172.16.32.65

[root@eygle root]# su - oracle
[oracle@eygle oracle]$ ls
admin  doc  jre  oradata  oraInventory  oui  product
[oracle@eygle oracle]$ df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1              5154852   3360600   1532396  69% /
/dev/sda7               101089     25744     70126  27% /home
/dev/sda5              4127076   2686152   1231280  69% /opt
none                    515296         0    515296   0% /dev/shm
/dev/sda2              4127108   2218172   1699288  57% /usr
/dev/sda6              2063504    107744   1850940   6% /var
[oracle@eygle oracle]$ ftp 172.16.33.58
Connected to 172.16.33.58 (172.16.33.58).
220 (vsFTPd 1.2.0)
Name (172.16.33.58:root): oracle
331 Please specify the password.
Password:
230 Login successful.
ftp> ls
227 Entering Passive Mode (172,16,33,58,222,252)
150 Here comes the directory listing.
drwxr-xr-x    3 800      800          4096 Jun 30 07:02 admin
-rw-r--r--    1 800      800       5422222 Jul 13 11:58 dictionary.ora
-rw-r--r--    1 800      800          1165 Aug 16 02:51 initprimary.ora
drwxrwxr-x    4 800      800          4096 Jun 30 06:29 jre
drwxrwxr-x   12 800      800          4096 Jun 30 06:44 oraInventory
drwxr-xr-x    3 800      800          4096 Jul 01 06:15 oradata
-rw-r--r--    1 800      800      576512000 Aug 16 02:22 oradata.tar
drwxrwxr-x    6 800      800          4096 Jun 30 06:29 oui
drwxr-xr-x    3 800      800          4096 Jun 30 05:18 product
drwxr-xr-x    6 800      800          4096 Jun 30 04:24 soft
-rw-r-----    1 800      800       1662976 Aug 16 02:37 stdcotrl.ctl
226 Directory send OK.
ftp> bin
200 Switching to Binary mode.
ftp> mget oradata.tar
mget oradata.tar? y
227 Entering Passive Mode (172,16,33,58,238,132)
150 Opening BINARY mode data connection for oradata.tar (576512000 bytes).
226 File send OK.
576512000 bytes received in 49.2 secs (1.1e+04 Kbytes/sec)
ftp> mget *.ctl
mget stdcotrl.ctl? y
227 Entering Passive Mode (172,16,33,58,73,35)
150 Opening BINARY mode data connection for stdcotrl.ctl (1662976 bytes).
226 File send OK.
1662976 bytes received in 0.14 secs (1.2e+04 Kbytes/sec)
ftp> mget initprimary.ora
mget initprimary.ora? y
227 Entering Passive Mode (172,16,33,58,194,239)
150 Opening BINARY mode data connection for initprimary.ora (1165 bytes).
226 File send OK.
1165 bytes received in 0.000325 secs (3.5e+03 Kbytes/sec)
ftp> bye
221 Goodbye.

[oracle@eygle oracle]$ ls
admin  doc  initprimary.ora  jre  oradata  oradata.tar  oraInventory  oui  product  stdcotrl.ctl
[oracle@eygle oracle]$ mv initprimary.ora $ORACLE_HOME/dbs
[oracle@eygle oracle]$ cd $ORACLE_HOME/dbs
[oracle@eygle dbs]$ ls
a.sql  initdw.ora  init.ora  initprimary.ora  initrac1.ora  initrac2.ora  initrac.ora  orapw
orapwrac1  orapwrac2  spfilerac.ora

解包数据文件

[oracle@eygle oracle]$ ls
admin  doc  jre  oradata  oradata.tar  oraInventory  oui  product  stdcotrl.ctl
[oracle@eygle oracle]$ tar -xvf oradata.tar
oradata/
oradata/primary/
oradata/primary/archive/
oradata/primary/control01.ctl
oradata/primary/control02.ctl
oradata/primary/control03.ctl
oradata/primary/redo01.log
oradata/primary/redo02.log
oradata/primary/redo03.log
oradata/primary/system01.dbf
oradata/primary/undotbs01.dbf
oradata/primary/temp01.dbf
oradata/primary/users01.dbf

修改initprimary.ora文件
修改控制文件名称及路径(如果和原配置不同)，增加几个参数,修改后如下:

[oracle@eygle dbs]$ cat initprimary.ora
*.aq_tm_processes=1
*.background_dump_dest='/opt/oracle/admin/primary/bdump'
*.compatible='9.2.0.0.0'
*.control_files='/opt/oracle/oradata/primary/stdcotrl.ctl'
*.core_dump_dest='/opt/oracle/admin/primary/cdump'
...
*.log_archive_dest_1='LOCATION=/opt/oracle/oradata/primary/archive'
*.log_archive_dest_2=''
*.log_archive_format='%t_%s.dbf'
*.log_archive_start=true
...
*.user_dump_dest='/opt/oracle/admin/primary/udump'
*.utl_file_dir='/opt/oracle'
*.standby_archive_dest='/opt/oracle/oradata/primary/stdarch'
*.fal_server='PRIMARY'
*.fal_client='STANDBY'
*.standby_file_management='AUTO'

创建必要的目录
[oracle@eygle oracle]$ cd $ORACLE_BASE/admin
[oracle@eygle admin]$ mkdir primary
[oracle@eygle admin]$ ls
primary  rac
[oracle@eygle admin]$ cd primary/
[oracle@eygle primary]$ ls
[oracle@eygle primary]$ mkdir bdump cdump udump

4.配置主节点监听器及tnsnames.ora文件
配置后如下:

[oracle@standby oracle]$ cd /opt/oracle/product/9.2.0/network/admin/
[oracle@standby admin]$ cat listener.ora
# LISTENER.ORA Network Configuration File: /opt/oracle/product/9.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
      )
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
      )
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /opt/oracle/product/9.2.0)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = primary)
      (ORACLE_HOME = /opt/oracle/product/9.2.0)
      (SID_NAME = primary)
    )
  )

[oracle@standby admin]$ cat tnsnames.ora
# TNSNAMES.ORA Network Configuration File: /opt/oracle/product/9.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

STANDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.46)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = primary)
    )
  )
PRIMARY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.58)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = primary)
    )
  )

[oracle@standby admin]$ lsnrctl start

LSNRCTL for Linux: Version 9.2.0.4.0 - Production on 16-AUG-2004 10:46:31

Copyright (c) 1991, 2002, Oracle Corporation.  All rights reserved.

Starting /opt/oracle/product/9.2.0/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 9.2.0.4.0 - Production
System parameter file is /opt/oracle/product/9.2.0/network/admin/listener.ora
Log messages written to /opt/oracle/product/9.2.0/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=standby)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 9.2.0.4.0 - Production
Start Date                16-AUG-2004 10:46:31
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  OFF
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/9.2.0/network/admin/listener.ora
Listener Log File         /opt/oracle/product/9.2.0/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=standby)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "primary" has 1 instance(s).
  Instance "primary", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

5.配置备用数据库监听器及tnsnames.ora文件

配置后文件如下:

[oracle@eygle admin]$ cd $ORACLE_HOME/network/admin
[oracle@eygle admin]$ cat listener.ora
# LISTENER.ORA Network Configuration File: /opt/oracle/product/9.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = eygle)(PORT = 1521))
      )
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = primary)
      (ORACLE_HOME = /opt/oracle/product/9.2.0)
      (SID_NAME = primary)
    )
  )
[oracle@eygle admin]$ cat tnsnames.ora
# TNSNAMES.ORA Network Configuration File: /opt/oracle/product/9.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

STANDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.46)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = primary)
    )
  )
PRIMARY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.58)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = primary)
    )
  )

[oracle@eygle admin]$

6.在主备节点用tnsping测试网络连通性

[oracle@standby admin]$ tnsping standby

TNS Ping Utility for Linux: Version 9.2.0.4.0 - Production on 16-AUG-2004 10:46:50

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

Used parameter files:
/opt/oracle/product/9.2.0/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.46)(PORT = 1521)))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primary)))
OK (10 msec)
[oracle@standby admin]$ tnsping primary

TNS Ping Utility for Linux: Version 9.2.0.4.0 - Production on 16-AUG-2004 10:46:55

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

Used parameter files:
/opt/oracle/product/9.2.0/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.58)(PORT = 1521)))
 (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primary)))
OK (0 msec)

[oracle@eygle admin]$ tnsping primary

TNS Ping Utility for Linux: Version 9.2.0.4.0 - Production on 16-AUG-2004 10:10:01

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

Used parameter files:
/opt/oracle/product/9.2.0/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.58)(PORT = 1521)))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primary)))
OK (50 msec)
[oracle@eygle admin]$ tnsping standby

TNS Ping Utility for Linux: Version 9.2.0.4.0 - Production on 16-AUG-2004 10:10:06

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

Used parameter files:
/opt/oracle/product/9.2.0/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.33.46)(PORT = 1521)))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primary)))
OK (10 msec)

7.启动备用数据库

[oracle@eygle primary]$ hostname
eygle
[oracle@eygle primary]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Aug 16 11:09:40 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 135337420 bytes
Fixed Size 452044 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database;

Database altered.

SQL> alter database recover managed standby database disconnect from session;

Database altered.

8.在主节点设置归档路径

SQL> alter system set log_archive_dest_2='service=standby mandatory reopen=60';

System altered.

SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL>

在备用节点观察日志

[oracle@eygle bdump]$ tail -f alert_primary.log
MRP0: Background Managed Standby Recovery process started
Starting datafile 1 recovery in thread 1 sequence 90
Datafile 1: '/opt/oracle/oradata/primary/system01.dbf'
Starting datafile 2 recovery in thread 1 sequence 90
Datafile 2: '/opt/oracle/oradata/primary/undotbs01.dbf'
Starting datafile 3 recovery in thread 1 sequence 90
Datafile 3: '/opt/oracle/oradata/primary/users01.dbf'
Media Recovery Waiting for thread 1 seq# 90
Mon Aug 16 11:10:50 2004
Completed: alter database recover managed standby database di
Mon Aug 16 11:13:34 2004
Media Recovery Log /opt/oracle/oradata/primary/stdarch/1_90.dbf
Media Recovery Waiting for thread 1 seq# 91
Media Recovery Log /opt/oracle/oradata/primary/stdarch/1_91.dbf
Media Recovery Waiting for thread 1 seq# 92
Mon Aug 16 12:09:38 2004
Media Recovery Log /opt/oracle/oradata/primary/stdarch/1_92.dbf

9.在主节点进行同样的配置，以便切换后继续日志传递

[oracle@standby oracle]$ ls
admin  dictionary.ora  initprimary.ora  jre  oradata  oradata.tar  oraInventory  oui  product  soft  stdcotrl.ctl
[oracle@standby oracle]$ cd oradata
[oracle@standby oradata]$ ls
primary
[oracle@standby oradata]$ cd primary/
[oracle@standby primary]$ ls
archive        control02.ctl  redo01.log  redo03.log    temp01.dbf     users01.dbf
control01.ctl  control03.ctl  redo02.log  system01.dbf  undotbs01.dbf
[oracle@standby primary]$ mkdir stdarch
[oracle@standby primary]$ exit
exit

SQL> alter system set standby_archive_dest='/opt/oracle/oradata/primary/stdarch';

System altered.

10.停止主数据库,启用备用数据库

SQL> alter database commit to switchover to physical standby;

Database altered.

SQL> shutdown immediate
ORA-01507: database not mounted

ORACLE instance shut down.

在备用模式启用主数据

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  135337420 bytes
Fixed Size                   452044 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
SQL> alter database mount standby database;

Database altered.

SQL> select name,open_mode,PROTECTION_MODE,DATABASE_ROLE from v$database;

NAME      OPEN_MODE  PROTECTION_MODE      DATABASE_ROLE
--------- ---------- -------------------- ----------------
PRIMARY   MOUNTED    MAXIMUM PERFORMANCE  PHYSICAL STANDBY

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

打开备用数据库
[oracle@eygle oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Aug 16 12:11:11 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> alter database commit to switchover to primary;

Database altered.

SQL> shutdown immediate;
ORA-01507: database not mounted

ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  135337420 bytes
Fixed Size                   452044 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
SQL> alter system switch logfile;

System altered.

在主库上观察日志应用情况

[oracle@standby bdump]$ tail -f alert_primary.log
Starting datafile 2 recovery in thread 1 sequence 93
Datafile 2: '/opt/oracle/oradata/primary/undotbs01.dbf'
Starting datafile 3 recovery in thread 1 sequence 93
Datafile 3: '/opt/oracle/oradata/primary/users01.dbf'
Media Recovery Log /opt/oracle/product/9.2.0/dbs/arch1_93.dbf
Mon Aug 16 15:08:43 2004
Media Recovery Log /opt/oracle/oradata/primary/stdarch/1_94.dbf
Media Recovery Waiting for thread 1 seq# 95
Media Recovery Log /opt/oracle/oradata/primary/stdarch/1_95.dbf
Media Recovery Waiting for thread 1 seq# 96

11.进行数据修改

SQL> create table t as select * from dba_users;

Table created.

SQL> alter system switch logfile;

System altered.

在从库上以read only打开数据库，执行查询
SQL> select username from t;
select username from t
                     *
ERROR at line 1:
ORA-01219: database not open: queries allowed on fixed tables/views only

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

Database altered.

SQL> ALTER DATABASE OPEN READ ONLY;

Database altered.

SQL> select username from t;

USERNAME
------------------------------
SYS
SYSTEM
DBSNMP
OUTLN
WMSYS

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

SQL>

12.把数据库切换回到主节点

在主节点
SQL> alter database commit to switchover to physical standby;

Database altered.

SQL> shutdown immediate
ORA-01507: database not mounted

statORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  135337420 bytes
Fixed Size                   452044 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes

SQL> alter database mount standby database;

Database altered.

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

在备用节点
SQL> alter database commit to switchover to primary;

Database altered.

SQL> shutdown immediate;
ORA-01507: database not mounted

ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  135337420 bytes
Fixed Size                   452044 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.

完成自由切换


Oracle x$ table list-eygle.com

Oracle X$ table list
Doc ID:  Note:22241.1
Subject:  List of X$ Tables and how the names are derived
Type:  REFERENCE
Status:  PUBLISHED
Content Type:  TEXT/PLAIN
Creation Date:  14-MAR-1995
Last Revision Date:  23-SEP-1999
Language:  USAENG

** INTERNAL ONLY **

This is a summary list of X$ Table Definitions - Last revision was 7.3.2
The main purpose of this note is to show the naming conventions.

  [K]ernel Layer
    [2]-Phase Commit
      [G]lobal [T]ransaction [E]ntry
        X$K2GTE  - Current 2PC tx
        X$K2GTE2 - Current 2PC tx
    [C]ache Layer
      [B]uffer Management
        Buffer [H]ash
          X$BH - Hash Table
        Buffer LRU Statistics
          X$KCBCBH - [C]urrent [B]uffers (buckets) - lru_statistics
          X$KCBRBH - [R]ecent [B]uffers (buckets) - lru_extended
        Buffer [WAIT]s
          X$KCBWAIT  - Waits by block class
          X$KCBFWAIT - Waits by File
        [W]orking Sets - 7.3 or higher
          X$KCBWDS - Set [D]escriptors
      [C]ontrol File Management
        [C]ontrol [F]ile List - 7.0.16 or higher
          X$KCCCF - Control File Names & status
        [D]atabase [I]nformation
          X$KCCDI - Database Information
        Data [F]iles
          X$KCCFE - File [E]ntries ( from control file )
          X$KCCFN - [F]ile [N]ames
        [L]og Files
          X$KCCLE - Log File [E]ntries
          X$KCCLH - Log [H]istory ( archive entries )
        Thread Information
          X$KCCRT - [R]edo [T]hread Information
      [F]ile Management
        X$KCFIO - File [IO] Statistics
      [L]ock Manager Component ( LCK )
        [H]ash and Bucket Tables - 7.0.15 to 7.1.1, and 7.2.0 or higher
          X$KCLFH - File [H]ash Table
          X$KCLFI - File Bucket Table
        X$LE - Lock [E]lements
        X$LE_STAT - Lock Conversion [STAT]istics
        X$KCLFX - Lock Element [F]ree list statistics - 7.3 or higher
        X$KCLLS - Per LCK free list statistics - 7.3 or higher
        X$KCLQN - [N]ame (hash) table statistics - 7.3 or higher
      [R]edo Component
        [M]edia recovery  - kcra.h - 7.3 or higher
          X$KCRMF - [F]ile context
          X$KCRMT - [T]hread context
          X$KCRMX - Recovery Conte[X]t
        [F]ile read
          X$KCRFX - File Read Conte[X]t -  7.3 or higher
      Reco[V]ery Component
        [F]ile [H]eaders
          X$KCVFH - All file headers
          X$KCVFHMRR - Files with [M]edia [R]ecovery [R]equired
          X$KCVFHONL - [ONL]ine File headers
      [K]ompatibility Management - 7.1.1 or higher
        X$KCKCE - [C]ompatibility Segment [E]ntries
        X$KCKTY - Compatibility [TY]pes
        X$KCKFM - Compatibility [F]or[M]ats ( index into X$KCKCE )
    [D]ata Layer
      Sequence [N]umber Component
         X$KDNCE - Sequence [C]ache [E]ntries - 7.2 or lower
        [S]equence Enqueues - common area for enqueue objects
          X$KDNSSC - [C]ache Enqueue Objects - 7.2 or lower
          X$KDNSSF - [F]lush Enqueue Objects - 7.2 or lower
        X$KDNST - Cache [ST]atistics - 7.2 or lower
      Inde[X] Block Component
        X$KDXHS - Index [H]i[S]togram
        X$KDXST - Index [ST]atistics
    [G]eneric Layer
      [H]eap Manager
        X$KGHLU - State (summary) of [L]R[U] heap(s) - defined in ksmh.h
      [I]nstantiation Manager
        [C]ursor [C]ache
          X$KGICC - Session statistics - defined in kqlf.h
          X$KGICS - System wide statistics - defined in kqlf.h
      [L]ibrary Cache Manager  ( defined and mapped from kqlf )
        Bind Variables
          X$KKSBV - Library Object [B]ind [V]ariables
        Object Cache
          X$KGLOB - All [OB]jects
          X$KGLTABLE   - Filter for [TABLE]s
          X$KGLBODY    - Filter for [BODY] ( packages )
          X$KGLTRIGGER - Filter for [TRIGGER]s
          X$KGLINDEX   - Filter for [INDEX]es
          X$KGLCLUSTER - Filter for [CLUSTER]s
          X$KGLCURSOR  - Filter for [CURSOR]s
        Cache Dependency
          X$KGLDP - Object [D]e[P]endency table
          X$KGLRD - [R]ead only [D]ependency table - 7.3 or higher
        Object Locks
          X$KGLLK - Object [L]oc[K]s
        Object Names
          X$KGLNA - Object [NA]mes (sql text)
          X$KGLNA1 - Object [NA]mes (sql text) with newlines - 7.2.0 or higher
        Object Pins
          X$KGLPN - Object [P]i[N]s
        Cache Statistics
          X$KGLST - Library cache [ST]atistics
        Translation Table
          X$KGLTR - Address [TR]anslation
        Access Table
          X$KGLXS - Object Access Table
        Authorization Table - 7.1.5 or higher
          X$KGLAU - Object Authorization table
        Latch Cleanup - 7.0.15 or higher
          X$KGLLC - [L]atch [C]leanup for Cache/Pin Latches
    [K]ompile Layer
      [S]hared Objects
        X$KKSAI - Cursor [A]llocation [I]nformation - 7.3.2 or higher
    [L]oader
      [L]ibrary
        X$KLLCNT - [C]o[NT]rol Statistics
        X$KLLTAB - [TAB]le Statistics
    [M]ulti-Threaded Layer
      [C]ircuit component
        X$KMCQS - Current [Q]ueue [S]tate
        X$KMCVC - [V]irtual [C]ircuit state
      [M]onitor Server/dispatcher
        [D]ispatcher
          X$KMMDI - [D]ispatcher [I]nfo (status)
           X$KMMDP - [D]ispatcher Config ( [P]rotocol info )
        [S]erver
          X$KMMSI - [S]erver [I]nfo ( status )
        X$KMMSG - [SG]a info ( global statistics)
        X$KMMRD - [R]equest timing [D]istributions
    s[Q]l Version and Option Layer
      Kernel [V]ersions
        X$VERSION - Library versions
      Kernel [O]ptions - 7.1.3 or higher
        X$OPTION - Server Options
    [Q]uery Layer
      [D]ictionary Cache Management
        X$KQDPG - [PG]a row cache cursor statistics
      [F]ixed Tables/views Management
        X$KQFCO - Table [CO]lumn definitions
        X$KQFDT - [D]erived [T]ables
        X$KQFSZ - Kernel Data structure type [S]i[Z]es
        X$KQFTA - Fixed [TA]bles
        X$KQFVI - Fixed [VI]ews
        X$KQFVT - [V]iew [T]ext definition - 7.2.0 or higher
      [R]ow Cache Management
        X$KQRST - Cache [ST]atistics
        X$KQRPD - [P]arent Cache [D]efinition - 7.1.5 or higher
        X$KQRSD - [S]ubordinate Cache [D]efinition - 7.1.5 or higher
    [S]ervice Layer
      [B]ackground Management
        [D]etached Process
          X$KSBDD - Detached Process [D]efinition (info)
          X$KSBDP - Detached [P]rocess Descriptor (name)
          X$MESSAGES - Background Message table
      [I]nstance [M]anagement - 7.3 or higher
        X$KSIMAT - Instance [AT]tributes
        X$KSIMAV - [A]ttribute [V]alues for all instances
        X$KSIMSI - [S]erial and [I]nstance numbers
      [L]ock Management
        [E]vent Waits
          X$KSLED - Event [D]escriptors
          X$KSLEI - [I]nstance wide statistics since startup
          X$KSLES - Current [S]ession statistics
        [L]atches
          X$KSLLD - Latch [D]escriptor (name)
          X$KSLLT - Latch statistics [ + Child latches @ 7.3 or higher ]
          X$KSLLW - Latch context ( [W]here ) descriptors - 7.3 or higher
          X$KSLPO - Latch [PO]st statistics - 7.3 or higher
          X$KSLWSC- No[W]ait and [S]leep [C]ount stats by Context -7.3 or higher
      [M]emory Management
        [C]ontext areas
          X$KSMCX - E[X]tended statistics on usage - 7.3.1 or lower
        Heap Areas
          X$KSMSP - SGA Hea[P]
          X$KSMPP - [P]GA Hea[P] - 7.3.2 and above
          X$KSMUP - [U]GA Hea[P] - 7.3.2 and above
          X$KSMHP - Any [H]ea[P] - 7.3.2 and above
          X$KSMSPR- [S]hared [P]ool [R]eserved List - 7.1.5 or higher
        [L]east recently used shared pool chunks
          X$KSMLRU - LR[U] flushes from the shared pool
        [S]GA Objects
          X$KSMSD - Size [D]efinition for Fixed/Variable summary
          X$KSMSS - Statistics (lengths) of SGA objects
        SGA [MEM]ory
           X$KSMMEM - map of the entire SGA - 7.2.0 or higher
          X$KSMFSV - Addresses of [F]ixed [S]GA [V]ariables - 7.2.1 or higher
      [P]arameter Component
          X$KSPPI  - [P]arameter [I]nfo ( Names )
          X$KSPPCV - [C]urrent Session [V]alues - 7.3.2 or above
          X$KSPPSV - [S]ystem [V]alues - 7.3.2 or above
      En[Q]ueue Management
        X$KSQDN - Global [D]atabase [N]ame
        X$KSQEQ - [E]n[Q]ueue Object
        X$KSQRS - Enqueue [R]e[S]ource
        X$KSQST - Enqueue [S]tatistics by [T]ype
      [U]ser Management
        [C]ost
          X$KSUCF - Cost [F]unction (resource limit)
        [L]icence
           X$KSULL - Licence [L]imits
        [L]anguage Manager
          X$NLS_PARAMETERS - NLS parameters
          X$KSULV - NLS [V]alid Values - 7.1.2 or higher
        [MY] [ST]atistics
          X$KSUMYSTA - [MY] [ST]atisics (current session)
        [P]rocess Info
          X$KSUPL - Process (resource) [L]imits
          X$KSUPRLAT - [LAT]ch Holder
          X$KSUPR - Process object
        [R]esource
          X$KSURU - Resource [U]sage
        [S]tatistics
          X$KSUSD - [D]escriptors (statistic names)
          X$KSUSGSTA - [G]lobal [ST]atistics
        [SE]ssions
          X$KSUSECST - Session status for events
          X$KSUSESTA - Session [STA]tistics
          X$KSUSECON - [CON]nection Authentication - 7.2.1 or higher
          X$KSUSE - [SE]ssion Info
          X$KSUSIO - [S]ystem [IO] statistics per session
        [T]imer
          X$KSUTM - Ti[M]e in 1/100th seconds
        Instance [X]
          X$KSUXSINST - [INST]ance state
        [T]race management
          X$TRACE - Current traced events
          X$TRACES - All possible traces
          X$KSTEX - Code [EX]ecution - 7.2.1 or higher
      E[X]ecution Management
        Device/Node [A]ffinity - 7.3.2 and above
          X$KSXAFA - Current File/Node Affinity
    [T]ransaction Layer
      Table [A]ccess [D]efinition
        X$KTADM - D[M]L lock
      [C]ontrol Component
        X$KTCXB - Transaction O[B]ject
      [S]or[T] Segments - 7.3 or higher
        X$KTSTSSD - [S]ort [S]egment [D]escriptor - per tablespace statistics
      [T]ablespace
        X$KTTVS - [V]alid [S]aveundo
      [U]ndo
        X$KTURD - Inuse [D]escriptors
        X$KTUXE - Transaction [E]ntry (table) - 7.3.2 or above
    Performance Layer [V] - 7.0.16 or higher
       [I]nformation tables
        X$KVII - [I]nitialisation Instance parameters
        X$KVIS - [S]izes of structure elements
        X$KVIT - [T]ransitory Instance parameters
    Security Layer [Z]
      [D]ictionary Component
        X$KZDOS - [OS] roles
      [S]ecurity State
        X$KZSPR - Enabled [PR]ivileges
        X$KZSRO - Enabled [RO]les
      [R]emote Logins - 7.1.1 or higher
        X$KZSRT - [R]emote Password File [T]able entries
    E[X]ecution Layer
      Parallel Query (Execute [F]ast) - 7.1.1 or higher
        [P]rocess and Queue Manager
          Statistics - 7.1.3 or higher
            X$KXFPYS - S[YS]tem Statistics
            X$KXFPDP - [D]etached [P]rocess (slave) statistics
            X$KXFQSROW - Table [Q]ueue Statistics - 7.3.2 or higher
          [C]oordinator Component
            X$KXFPCST - Query [ST]atistics
            X$KXFPCMS - [M]essage [S]tatistics
            X$KXFPCDS - [D]equeue [S]tatistics
          [S]lave Component
            X$KXFPSST - Query [ST]atistics
            X$KXFPSMS - [M]essage [S]tatistics
            X$KXFPCDS - [D]equeue [S]tatistics
      [S]hared Cursor
        X$KXSBD - [B]ind [D]ata - 7.3.2 and above
        X$KXSCC - SQL [C]ursor [C]ache Data - 7.3.2 and above
  [N]etwork Layer - 7.0.15 or higher
    Network [CO]nnections
      X$UGANCO - Current [N]etwork [CO]nnections
.

--------------------------------------------------------------------------------

 Copyright (c) 1995,1999 Oracle Corporation. All Rights Reserved. Legal Notices and Terms of Use.


GmailFS - Gmail Filesystem Install and Config-www.eygle.com

GmailFS - Gmail Filesystem Install and Config

Saturday, 2004-09-25 1:07 Eygle

Google推出了1G的Gmail,随后很多邮件提供商都开始提供1G的Gmail,Google再一次领导了潮流.有了1G的Mail以后,怎么使用这么大的存储空间也成了一个问题:)
于是有人写出了GmailFS,Gmail Filesystem---Gmail文件系统.

你可以在以下链接找到相关内容:
http://richard.jones.name/google-hacks/gmail-filesystem/gmail-filesystem.html

我引用一下richard的说明:

GmailFS provides a mountable Linux filesystem which uses your Gmail account as its storage medium.
GmailFS提供可装载的Linux文件系统,使用Gmail帐号你可以使用Gmail作为存储介质使用.

GmailFS is a Python application and uses the FUSE userland filesystem infrastructure to help provide the filesystem, and libgmail to communicate with Gmail.
GmailFS是使用Python技术开发的应用,使用FUSE作为文件系统的基础架构,使用libgmail和Gmail通讯.

GmailFS supports most file operations such as read, write, open, close, stat, symlink, link, unlink, truncate and rename. This means that you can use all your favourite unix command line tools to operate on files stored on Gmail (e.g. cp, ls, mv, rm, ln, grep etc. etc.).

Please be gentle on the code. This is my first foray into Python and I'm sure the code is far from elegant. I'm particularly concerned with my attempts to manipulate mutable byte arrays. I'm sure that there must be a less clumsy way of doing it than the nasty list -> array -> string path I'm currently using. Python has a reputation as an excellent language choice for rapid prototyping.
The first working version of GmailFS took about 2 days of coding. There was an additional 1.5 days spent on performance tuning and bugfixing.
第一个可以使用的GmailFS版本大约花了2天时间编码,然后用了1.5天进行性能调整和Bug修正.

Given that this includes language learning curve, the reputation seems well deserved. A special mention should go to libgmail and FUSE, both greatly contributed to the short development time.

然后关注了一下Python:
Guido van Rossum于1990年开始开发Python，最初的目的无非是一个自娱的项目。作为Monty Python的飞行马戏团节目的爱好者，他给自己开发的这种编程语言起了现在这个古怪的名字，中文意思就是大蟒。Python最初设计为一种取代 Amoeba分布式操作系统ABC的脚本语言，但不久这种新型编程语言很快就发展成可以解决相当多问题的利器，现在更引入到了多种平台。

想一想,国外的开发者往往可以开发出功能强大的语言及工具.而我们国内就缺少这样的开发人员和这样的成绩.我们不缺少程序员和聪明人,我们缺少的是富于开创的天才.

言归正传,我们一起来看一下GmailFS的安装及配置.

这里涉及的所有软件的当前版本都可以从本地下载.

1.安装Python 2.3版本

How To Install Python 2.3 On Linux

然后作一个符号链接:

[root@eygle bin]# ln -s /usr/bin/python2.3 /usr/bin/python
[root@eygle bin]# ls -l python
lrwxrwxrwx    1 root     root           18 Sep 24 23:35 python -> /usr/bin/python2.3

2.安装FUSE version 1.3
在以下地址可以下载: FUSE's SourceForge download page

安装步骤如下:

# tar zxf fuse-1.3.tar.gz
# cd fuse-1.3
# ./configure
# make
# make install

安装日志参考: FUSE Install LOG

3.安装python FUSE module

安装步骤如下:

# tar zxf fuse-python.tar.gz
# cd fuse-python
# python setup.py build
# python setup.py install

安装日志参考如下:

[root@eygle soft]# cd fuse-python
[root@eygle fuse-python]# ls
build  code.leo  CVS  _fusemodule.c  fuse.py  INSTALL  Makefile  README  setup.py  xmp.py
[root@eygle fuse-python]# python setup.py build
running build
running build_py
running build_ext
building '_fusemodule' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.3 -c _fusemodule.c -o
build/temp.linux-i686-2.3/_fusemodule.o
gcc -pthread -shared build/temp.linux-i686-2.3/_fusemodule.o -L../lib -lfuse -o build/lib.linux-i686-2.3/_fusemodule.so
[root@eygle fuse-python]# python setup.py install
running install
running build
running build_py
running build_ext
running install_lib
copying build/lib.linux-i686-2.3/fuse.py -> /usr/lib/python2.3/site-packages
copying build/lib.linux-i686-2.3/_fusemodule.so -> /usr/lib/python2.3/site-packages
byte-compiling /usr/lib/python2.3/site-packages/fuse.py to fuse.pyc

4.安装libgmail

在这里下载,注意这里下载的文件格式为gz,但实际上是个tgz文件.

安装步骤为:

# tar zxf libgmail-0.0.8.gz
# cd libgmail-0.0.8
# cp libgmail.py constants.py /usr/lib/python2.3/site-packages

5.安装gmailfs

gmailfs可以在这里下载

安装步骤为:

# tar zxf gmailfs.tar.gz
# cd gmailfs
# cp gmailfs.py /usr/local/bin
# cp mount.gmailfs /sbin
# ln -s /sbin/mount.gmailfs /sbin/mount.fuse

6.开始使用gmailfs文件系统

你可以使用如下命令mount你的GmailFS:

mount -t gmailfs /usr/local/bin/gmailfs.py /mount_point -o username=gmailuser, password=gmailpass, sname=zOlRRa

在使用之前,你可以修改 /usr/local/bin/gmailfs.py 中的 DefaultUsername, DefaultPassword,以便可以简化gmailfs的使用.

[root@eygle /]# mkdir gmail
[root@eygle /]# mount -t gmailfs /usr/local/bin/gmailfs.py /gmail -o fsname=eygle
[root@eygle /]# mount: warning, should mount with username=gmailuser option, using default
mount: warning, should mount with password=gmailpass option, using default
[root@eygle /]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1              5154852   3421812   1471184  70% /
/dev/sda7               101089     66140     29730  69% /home
/dev/sda5              4127076   3347860    569572  86% /opt
none                    515296         0    515296   0% /dev/shm
/dev/sda2              4127108   2268464   1648996  58% /usr
/dev/sda6              2063504    138360   1820324   8% /var
gmailfs                1024000     17408   1006592   2% /gmail

接下来我们就可以使用GmailFS了:

[root@eygle /]# cd /home/gqgai/soft
[root@eygle soft]# ls -l
total 10929
-rw-r--r--    1 root     root      1480750 Sep 24 18:40 db4-4.1.25-14.i386.rpm
drwxrwxrwx    8 1001     1001         1024 Sep 24 23:48 fuse-1.3
-rw-r--r--    1 gqgai    gqgai      563200 Sep 24 17:35 fuse-1.3.tar
drwxr-xr-x    4 1002     1002         1024 Sep 24 19:06 fuse-python
-rw-r--r--    1 gqgai    gqgai       71680 Sep 24 17:35 fuse-python.tar
drwxr-xr-x    2 1002     1002         1024 Aug 30 08:24 gmailfs
-rw-r--r--    1 gqgai    gqgai       61440 Sep 24 17:35 gmailfs.tar
drwxr-xr-x    3 root     root         1024 Sep 25 00:14 libgmail-0.0.8
-rw-r--r--    1 gqgai    gqgai       18803 Sep 24 19:37 libgmail-0.0.8.gz
-rw-r--r--    1 root     root      7565683 Jul 23 10:59 python2.3-2.3.4-3pydotorg.i386.rpm
-rw-r--r--    1 root     root       678130 Jul 23 11:00 python2.3-devel-2.3.4-3pydotorg.i386.rpm
-rw-r--r--    1 root     root       690451 Jul 23 11:00 python2.3-tools-2.3.4-3pydotorg.i386.rpm
[root@eygle soft]# cp libgmail-0.0.8.gz /gmail
[root@eygle soft]# cd /gmail
[root@eygle gmail]# ls -l
total 19
-rw-r--r--    0 root     root        18803 Sep 25 00:32 libgmail-0.0.8.gz
[root@eygle gmail]#

7.其他

在网上这个问题引起了广泛的讨论,参考这里.

有人认为既然有人可以用2天时间就开发出这样的程序,那么自然可以很轻易的把更多的Gmail连接起来作为网络存储.如果Google认为有必要来解决这个问题
那么所有的连接都可能被马上中断.那么这种技术就不具有稳定及可靠性.

也有人认为,这对于Google未尝不是一件好事,他们可以有更多的数据用以分析.

有人从实际观点出发,认为由于网络的问题,不具有实际价值.

这些都不是我关心的,我想说的是,这才是我们应该学习的专业精神.


FUSE Install LOG-www.eygle.com

FUSE Install LOG

Saturday, 2004-09-25 0:04 Eygle

FUSE安装日志:

[root@eygle soft]# gzip -d fuse-1.3.tar.gz
[root@eygle soft]# ls
db4-4.1.25-14.i386.rpm  fuse-python.tar    python2.3-2.3.4-3pydotorg.i386.rpm
fuse-1.3.tar            gmailfs.tar.gz     python2.3-devel-2.3.4-3pydotorg.i386.rpm
fuse-python             libgmail-0.0.8.gz  python2.3-tools-2.3.4-3pydotorg.i386.rpm
[root@eygle soft]# tar -xvf fuse-1.3.tar
fuse-1.3/
fuse-1.3/kernel/
fuse-1.3/kernel/Makefile.in
fuse-1.3/kernel/dev.c
fuse-1.3/kernel/dir.c
fuse-1.3/kernel/file.c
fuse-1.3/kernel/inode.c
fuse-1.3/kernel/util.c
fuse-1.3/kernel/fuse_i.h
fuse-1.3/README
fuse-1.3/Makefile.in
fuse-1.3/configure
fuse-1.3/AUTHORS
fuse-1.3/COPYING
fuse-1.3/COPYING.LIB
fuse-1.3/ChangeLog
fuse-1.3/INSTALL
fuse-1.3/Makefile.am
fuse-1.3/NEWS
fuse-1.3/TODO
fuse-1.3/aclocal.m4
fuse-1.3/configure.in
fuse-1.3/depcomp
fuse-1.3/install-sh
fuse-1.3/missing
fuse-1.3/mkinstalldirs
fuse-1.3/fuse.spec
fuse-1.3/README-2.4
fuse-1.3/README-2.6
fuse-1.3/README.NFS
fuse-1.3/Filesystems
fuse-1.3/BUGS
fuse-1.3/include/
fuse-1.3/include/fuse.h
fuse-1.3/include/Makefile.in
fuse-1.3/include/Makefile.am
fuse-1.3/include/config.h.in
fuse-1.3/include/linux/
fuse-1.3/include/linux/fuse.h
fuse-1.3/include/linux/Makefile.in
fuse-1.3/include/linux/Makefile.am
fuse-1.3/patch/
fuse-1.3/patch/Makefile.in
fuse-1.3/patch/Makefile.am
fuse-1.3/patch/ms_permission.patch
fuse-1.3/lib/
fuse-1.3/lib/Makefile.in
fuse-1.3/lib/Makefile.am
fuse-1.3/lib/fuse.c
fuse-1.3/lib/fuse_mt.c
fuse-1.3/lib/helper.c
fuse-1.3/lib/mount.c
fuse-1.3/lib/fuse_i.h
fuse-1.3/util/
fuse-1.3/util/Makefile.in
fuse-1.3/util/Makefile.am
fuse-1.3/util/fusermount.c
fuse-1.3/util/mount.fuse
fuse-1.3/example/
fuse-1.3/example/Makefile.in
fuse-1.3/example/Makefile.am
fuse-1.3/example/fusexmp.c
fuse-1.3/example/hello.c
fuse-1.3/example/null.c
[root@eygle soft]# cd fuse-1.3
[root@eygle fuse-1.3]# ls
aclocal.m4  ChangeLog     COPYING      example      include     kernel       Makefile.in    NEWS    README-2.4  TODO
AUTHORS     configure     COPYING.LIB  Filesystems  INSTALL     lib          missing        patch   README-2.6  util
BUGS        configure.in  depcomp      fuse.spec    install-sh  Makefile.am  mkinstalldirs  README  README.NFS

[root@eygle fuse-1.3]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for ranlib... ranlib
checking kernel source directory... /usr/src/linux-2.4.21-4.EL
checking kernel source version... 2.4.21-4.EL
checking whether i_size_read is declared... no
configure: creating ./config.status
config.status: creating Makefile
config.status: creating kernel/Makefile
config.status: creating lib/Makefile
config.status: creating util/Makefile
config.status: creating example/Makefile
config.status: creating include/Makefile
config.status: creating include/linux/Makefile
config.status: creating patch/Makefile
config.status: creating include/config.h
config.status: executing depfiles commands

[root@eygle fuse-1.3]# make
Making all in include
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
make  all-recursive
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
Making all in linux
make[3]: Entering directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[3]: Nothing to be done for `all'.
make[3]: Leaving directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[3]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
Making all in patch
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/patch'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/patch'
Making all in kernel
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/kernel'
gcc -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -pipe -I/usr/src/linux-2.4.21-4.EL/include -I../include
-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -DFUSE_VERSION=\"1.3\" -c dev.c
gcc -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -pipe -I/usr/src/linux-2.4.21-4.EL/include -I../include
-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -DFUSE_VERSION=\"1.3\" -c dir.c
gcc -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -pipe -I/usr/src/linux-2.4.21-4.EL/include -I../include
-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -DFUSE_VERSION=\"1.3\" -c file.c
gcc -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -pipe -I/usr/src/linux-2.4.21-4.EL/include -I../include
-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -DFUSE_VERSION=\"1.3\" -c inode.c
gcc -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -pipe -I/usr/src/linux-2.4.21-4.EL/include -I../include
-D__KERNEL__ -DMODULE -D_LOOSE_KERNEL_NAMES -DFUSE_VERSION=\"1.3\" -c util.c
ld -r -o fuse.o dev.o dir.o file.o inode.o util.o
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/kernel'
Making all in lib
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/lib'
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT fuse.o -MD -MP -MF ".deps/fuse.Tpo" \
  -c -o fuse.o `test -f 'fuse.c' || echo './'`fuse.c; \
then mv -f ".deps/fuse.Tpo" ".deps/fuse.Po"; \
else rm -f ".deps/fuse.Tpo"; exit 1; \
fi
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT fuse_mt.o -MD -MP -MF ".deps/fuse_mt.Tpo" \
  -c -o fuse_mt.o `test -f 'fuse_mt.c' || echo './'`fuse_mt.c; \
then mv -f ".deps/fuse_mt.Tpo" ".deps/fuse_mt.Po"; \
else rm -f ".deps/fuse_mt.Tpo"; exit 1; \
fi
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT helper.o -MD -MP -MF ".deps/helper.Tpo" \
  -c -o helper.o `test -f 'helper.c' || echo './'`helper.c; \
then mv -f ".deps/helper.Tpo" ".deps/helper.Po"; \
else rm -f ".deps/helper.Tpo"; exit 1; \
fi
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT mount.o -MD -MP -MF ".deps/mount.Tpo" \
  -c -o mount.o `test -f 'mount.c' || echo './'`mount.c; \
then mv -f ".deps/mount.Tpo" ".deps/mount.Po"; \
else rm -f ".deps/mount.Tpo"; exit 1; \
fi
rm -f libfuse.a
ar cru libfuse.a fuse.o fuse_mt.o helper.o mount.o
ranlib libfuse.a
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/lib'
Making all in util
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/util'
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT fusermount.o -MD -MP -MF ".deps/fusermount.Tpo" \
  -c -o fusermount.o `test -f 'fusermount.c' || echo './'`fusermount.c; \
then mv -f ".deps/fusermount.Tpo" ".deps/fusermount.Po"; \
else rm -f ".deps/fusermount.Tpo"; exit 1; \
fi
gcc  -Wall -W -g -O2   -o fusermount  fusermount.o
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/util'
Making all in example
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/example'
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT fusexmp.o -MD -MP -MF ".deps/fusexmp.Tpo" \
  -c -o fusexmp.o `test -f 'fusexmp.c' || echo './'`fusexmp.c; \
then mv -f ".deps/fusexmp.Tpo" ".deps/fusexmp.Po"; \
else rm -f ".deps/fusexmp.Tpo"; exit 1; \
fi
gcc  -Wall -W -g -O2   -o fusexmp  fusexmp.o ../lib/libfuse.a -lpthread
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT null.o -MD -MP -MF ".deps/null.Tpo" \
  -c -o null.o `test -f 'null.c' || echo './'`null.c; \
then mv -f ".deps/null.Tpo" ".deps/null.Po"; \
else rm -f ".deps/null.Tpo"; exit 1; \
fi
gcc  -Wall -W -g -O2   -o null  null.o ../lib/libfuse.a -lpthread
if gcc -DHAVE_CONFIG_H -I. -I. -I../include     -Wall -W -g -O2 -MT hello.o -MD -MP -MF ".deps/hello.Tpo" \
  -c -o hello.o `test -f 'hello.c' || echo './'`hello.c; \
then mv -f ".deps/hello.Tpo" ".deps/hello.Po"; \
else rm -f ".deps/hello.Tpo"; exit 1; \
fi
gcc  -Wall -W -g -O2   -o hello  hello.o ../lib/libfuse.a -lpthread
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/example'
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3'
[root@eygle fuse-1.3]# make check
Making check in include
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
Making check in linux
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[2]: Nothing to be done for `check'.
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
make[2]: Nothing to be done for `check-am'.
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
Making check in patch
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/patch'
make[1]: Nothing to be done for `check'.
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/patch'
Making check in kernel
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/kernel'
make[1]: *** No rule to make target `check'.  Stop.
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/kernel'
make: *** [check-recursive] Error 1
[root@eygle fuse-1.3]# make install
Making install in include
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
Making install in linux
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[3]: Entering directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/include/linux'
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
make[3]: Entering directory `/home/gqgai/soft/fuse-1.3/include'
make[3]: Nothing to be done for `install-exec-am'.
/bin/sh ../mkinstalldirs /usr/local/include
 /usr/bin/install -c -m 644 fuse.h /usr/local/include/fuse.h
make[3]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/include'
Making install in patch
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/patch'
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/patch'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/patch'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/patch'
Making install in kernel
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/kernel'
mkdir -p -- /lib/modules/2.4.21-4.EL/kernel/fs/fuse
/usr/bin/install -c -m 644 fuse.o /lib/modules/2.4.21-4.EL/kernel/fs/fuse/fuse.o
/sbin/depmod -a
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/kernel'
Making install in lib
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/lib'
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/lib'
/bin/sh ../mkinstalldirs /usr/local/lib
 /usr/bin/install -c -m 644 libfuse.a /usr/local/lib/libfuse.a
 ranlib /usr/local/lib/libfuse.a
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/lib'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/lib'
Making install in util
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/util'
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/util'
/bin/sh ../mkinstalldirs /usr/local/bin
  /usr/bin/install -c fusermount /usr/local/bin/fusermount
make  install-exec-hook
make[3]: Entering directory `/home/gqgai/soft/fuse-1.3/util'
chown root /usr/local/bin/fusermount
chmod u+s /usr/local/bin/fusermount
make[3]: Leaving directory `/home/gqgai/soft/fuse-1.3/util'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/util'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/util'
Making install in example
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3/example'
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3/example'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3/example'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3/example'
make[1]: Entering directory `/home/gqgai/soft/fuse-1.3'
make[2]: Entering directory `/home/gqgai/soft/fuse-1.3'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/gqgai/soft/fuse-1.3'
make[1]: Leaving directory `/home/gqgai/soft/fuse-1.3'


How To Install Python2.3 On Linux-www.eygle.com

How To Install Python2.3 On Linux

Friday, 2004-09-24 23:32 Eygle

1.下载相应的rpm包

wget http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-2.3.4-3pydotorg.i386.rpm
wget http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-devel-2.3.4-3pydotorg.i386.rpm
wget http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-tools-2.3.4-3pydotorg.i386.rpm
wget --passive ftp://rpmfind.rediris.es/sites2/fedora.us/fedora/fedora/1/i386/RPMS.os/db4-4.1.25-14.i386.rpm

[root@eygle soft]# wget http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-devel-2.3.4-3pydotorg.i386.rpm
--18:37:44--  http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-devel-2.3.4-3pydotorg.i386.rpm
           => `python2.3-devel-2.3.4-3pydotorg.i386.rpm'
Resolving www.python.org... done.
Connecting to www.python.org[194.109.137.226]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 678,130 [application/octet-stream]

100%[========================================================================================>] 678,130       28.14K/s    ETA 00:00

18:38:08 (28.14 KB/s) - `python2.3-devel-2.3.4-3pydotorg.i386.rpm' saved [678130/678130]

[root@eygle soft]# wget http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-tools-2.3.4-3pydotorg.i386.rpm
--18:38:11--  http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-tools-2.3.4-3pydotorg.i386.rpm
           => `python2.3-tools-2.3.4-3pydotorg.i386.rpm'
Resolving www.python.org... done.
Connecting to www.python.org[194.109.137.226]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 690,451 [application/octet-stream]

100%[========================================================================================>] 690,451       28.85K/s    ETA 00:00

18:38:35 (28.85 KB/s) - `python2.3-tools-2.3.4-3pydotorg.i386.rpm' saved [690451/690451]

[root@eygle soft]# wget --passive ftp://rpmfind.rediris.es/sites2/fedora.us/fedora/fedora/1/i386/RPMS.os/db4-4.1.25-14.i386.rpm
--18:39:35--  ftp://rpmfind.rediris.es/sites2/fedora.us/fedora/fedora/1/i386/RPMS.os/db4-4.1.25-14.i386.rpm
           => `db4-4.1.25-14.i386.rpm'
Resolving rpmfind.rediris.es... done.
Connecting to rpmfind.rediris.es[130.206.1.5]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /sites2/fedora.us/fedora/fedora/1/i386/RPMS.os ... done.
==> PASV ... done.    ==> RETR db4-4.1.25-14.i386.rpm ... done.

    [ <=>                                                                                     ] 1,480,750     21.89K/s

18:40:46 (21.89 KB/s) - `db4-4.1.25-14.i386.rpm' saved [1480750]

[root@eygle soft]# wget http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-2.3.4-3pydotorg.i386.rpm
--18:40:55--  http://www.python.org/ftp/python/2.3.4/rpms/fedora-1/python2.3-2.3.4-3pydotorg.i386.rpm
           => `python2.3-2.3.4-3pydotorg.i386.rpm'
Resolving www.python.org... done.
Connecting to www.python.org[194.109.137.226]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7,565,683 [application/octet-stream]

100%[========================================================================================>] 7,565,683     29.37K/s    ETA 00:00

18:45:07 (29.37 KB/s) - `python2.3-2.3.4-3pydotorg.i386.rpm' saved [7565683/7565683]

2.安装

[root@eygle soft]# rpm -ivh db4-4.1.25-14.i386.rpm
warning: db4-4.1.25-14.i386.rpm: V3 DSA signature: NOKEY, key ID 4f2a6fd2
warning: python2.3-2.3.4-3pydotorg.i386.rpm: V3 DSA signature: NOKEY, key ID 95ccbcff
Preparing...                ########################################### [100%]
        file /lib/libdb-4.1.so from install of db4-4.1.25-14 conflicts with file from package db4-4.1.25-8
        file /usr/lib/libdb_cxx-4.1.so from install of db4-4.1.25-14 conflicts with file from package db4-4.1.25-8

[root@eygle soft]# rpm -ivh python*.rpm
warning: python2.3-2.3.4-3pydotorg.i386.rpm: V3 DSA signature: NOKEY, key ID 95ccbcff
Preparing...                ########################################### [100%]
   1:python2.3              ########################################### [ 33%]
   2:python2.3-devel        ########################################### [ 67%]
   3:python2.3-tools        ########################################### [100%]

3.调用
使用python2.3来进入python,原来的版本可以使用python来调用

[root@eygle soft]# python2.3
Python 2.3.4 (#1, Jul 22 2004, 20:47:54)
[GCC 3.3.2 20031022 (Red Hat Linux 3.3.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>


Use EMC powermt to solve PowerPath Problem-www.eygle.com

Use EMC powermt to solve PowerPath Problem

Thursday, 2004-09-23 10:16 Eygle

在EMC系统中,如果你频繁的增减磁盘,重新分配规划磁盘组,那么主机可能无法正确检测到磁盘,这是后我们可以使用powermt来检测配置,
解决问题.

1.你可以会遇到如下问题

你已经分配磁盘给主机系统,但是在format时无法发现:

# format
Searching for disks...done

AVAILABLE DISK SELECTIONS:
       0. c1t0d0
          /pci@9,600000/SUNW,qlc@2/fp@0,0/ssd@w500000e0106d9781,0
       1. c1t1d0
          /pci@9,600000/SUNW,qlc@2/fp@0,0/ssd@w500000e0106ef871,0
Specify disk (enter its number): 1
selecting c1t1d0
[disk formatted]
Warning: Current Disk has mounted partitions.

FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !     - execute , then return
        quit
format> q

2.此时可以使用powermt来检测PowerPath连接状态

Powermt means:PowerPath 4.x Management Utility

# powermt display dev=all
Pseudo name=emcpower4a
CLARiiON ID=CK200041200044
Logical device ID=6006016028A610000AF03A428708D911
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP B, current=Unknown
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
2304 pci@8/fibre-channel@4     c2t0d3s0   SP B0     active  dead       0      0
2304 pci@8/fibre-channel@4     c2t1d3s0   SP A0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t0d3s0   SP B0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t1d3s0   SP A0     active  dead       0      0

Pseudo name=emcpower5a
CLARiiON ID=CK200041200044
Logical device ID=6006016028A610005ABD62655B08D911
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP A, current=Unknown
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
2304 pci@8/fibre-channel@4     c2t0d2s0   SP B0     active  dead       0      0
2304 pci@8/fibre-channel@4     c2t1d2s0   SP A0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t0d2s0   SP B0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t1d2s0   SP A0     active  dead       0      0

Pseudo name=emcpower0a
CLARiiON ID=CK200041200044
Logical device ID=6006016028A61000C65024C992D4D811
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP B, current=Unknown
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
2304 pci@8/fibre-channel@4     c2t0d0s0   SP B0     active  dead       0      0
2304 pci@8/fibre-channel@4     c2t1d0s0   SP A0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t0d0s0   SP B0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t1d0s0   SP A0     active  dead       0      0

Pseudo name=emcpower1a
CLARiiON ID=CK200041200044
Logical device ID=6006016028A61000F075BD4E93D4D811
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP A, current=Unknown
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
2304 pci@8/fibre-channel@4     c2t0d1s0   SP B0     active  dead       0      0
2304 pci@8/fibre-channel@4     c2t1d1s0   SP A0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t0d1s0   SP B0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t1d1s0   SP A0     active  dead       0      0

Pseudo name=emcpower6a
CLARiiON ID=CK200041200044
Logical device ID=6006016028A61000FC68E575620CD911
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP B, current=Unknown
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
2304 pci@8/fibre-channel@4     c2t0d4s0   SP B0     active  dead       0      0
2304 pci@8/fibre-channel@4     c2t1d4s0   SP A0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t0d4s0   SP B0     active  dead       0      0
2305 pci@8/fibre-channel@5     c3t1d4s0   SP A0     active  dead       0      0

这些active dead的状态都是错误的.

3.执行重新配置

# powermt check
Warning: CLARiiON device path c2t0d0s0 is currently dead.
Do you want to remove it (y/n/a/q)? y
Warning: CLARiiON device path c2t0d1s0 is currently dead.
Do you want to remove it (y/n/a/q)? y
Warning: CLARiiON device path c2t0d2s0 is currently dead.
Do you want to remove it (y/n/a/q)? a
Warning: CLARiiON device path c2t0d3s0 is currently dead.
Warning: CLARiiON device path c2t0d4s0 is currently dead.
Warning: CLARiiON device path c2t1d0s0 is currently dead.
Warning: CLARiiON device path c2t1d1s0 is currently dead.
Warning: CLARiiON device path c2t1d2s0 is currently dead.
Warning: CLARiiON device path c2t1d3s0 is currently dead.
Warning: CLARiiON device path c2t1d4s0 is currently dead.
Warning: CLARiiON device path c3t0d0s0 is currently dead.
Warning: CLARiiON device path c3t0d1s0 is currently dead.
Warning: CLARiiON device path c3t0d2s0 is currently dead.
Warning: CLARiiON device path c3t0d3s0 is currently dead.
Warning: CLARiiON device path c3t0d4s0 is currently dead.
Warning: CLARiiON device path c3t1d0s0 is currently dead.
Warning: CLARiiON device path c3t1d1s0 is currently dead.
Warning: CLARiiON device path c3t1d2s0 is currently dead.
Warning: CLARiiON device path c3t1d3s0 is currently dead.
Warning: CLARiiON device path c3t1d4s0 is currently dead.

# powermt config
# powermt restore
# powermt save
# powermt display dev=all
Pseudo name=emcpower7a
CLARiiON ID=CK200041200044 [Storage Group 2]
Logical device ID=6006016028A61000482F2BA9720CD911 [LUN 1]
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP B, current=SP B
==============================================================================
---------------- Host ---------------   - Stor -   -- I/O Path -  -- Stats ---
### HW Path                 I/O Paths    Interf.   Mode    State  Q-IOs Errors
==============================================================================
2304 pci@8/fibre-channel@4     c2t0d0s0   SP B0     active  alive      0      0
2304 pci@8/fibre-channel@4     c2t1d0s0   SP A0     active  alive      0      0
2305 pci@8/fibre-channel@5     c3t0d0s0   SP B0     active  alive      0      0
2305 pci@8/fibre-channel@5     c3t1d0s0   SP A0     active  alive      0      0

此时的active alive状态正常.

4.此时执行format可以看到正确的磁盘

# format
Searching for disks...done

c2t0d0: configured with capacity of 40.00GB
c2t1d0: configured with capacity of 40.00GB
c3t0d0: configured with capacity of 40.00GB
c3t1d0: configured with capacity of 40.00GB
emcpower7a: configured with capacity of 40.00GB

AVAILABLE DISK SELECTIONS:
       0. c1t0d0
          /pci@9,600000/SUNW,qlc@2/fp@0,0/ssd@w500000e0106d9781,0
       1. c1t1d0
          /pci@9,600000/SUNW,qlc@2/fp@0,0/ssd@w500000e0106ef871,0
       2. c2t0d0
          /pci@8,700000/fibre-channel@4/sd@0,0
       3. c2t1d0
          /pci@8,700000/fibre-channel@4/sd@1,0
       4. c3t0d0
          /pci@8,700000/fibre-channel@5/sd@0,0
       5. c3t1d0
          /pci@8,700000/fibre-channel@5/sd@1,0
       6. emcpower7a
          /pseudo/emcp@7
Specify disk (enter its number): ^D

具体Powermt命令参考:

http://blog.csdn.net/eygle/archive/2004/09/23/113881.aspx


Veritas Volume Manager(VxVM)-vxassist命令手册 -www.eygle.com

Veritas Volume Manager(VxVM)-vxassist命令手册

Tuesday, 2004-09-14 13:10 Eygle

vxassist是VxVM中非常重要的一个工具,使用非常频繁,我这里给出一个命令手册,并作了一些简单的翻译和注释,仅供参考.

General
1. Creating a Volume
1.1 Creating a Concatenated Volume
1.2 Creating a Striped Volume
1.3 Creating a RAID-5 Volume
2. Extending a Volume
2.1 Extending a volume up to certain length
2.2 Extending by a Given Length
 3. Shrinking a Volume
3.1 Shrinking to a Given Length
 3.2 Shrinking by a Given Length
 4. Removing a Volume
 5. Mirroring a Volume
 5.1 Creating & Mirroring a New Volume
 5.2 Mirroring an Existing Volume
 5.3 Mirroring All Volumes
 6.Removing a Mirror
 7.Adding a RAID-5 Log
 8.Adding a DRL Log
 9.Removing a RAID-5 Log
10.Preparing a Volume for Online Backup
 11.Displaying Volume Configuration Information

General
vxassist工具是VxVM中用于进行卷管理的工具,可以用于创建卷、增加镜像、扩展或者收缩存在的卷等,是非常重要的一个工具.
The vxassist utility in Veritas Volume Manager is used to create volumes, add mirrors and logs to existing volumes, extend and shrink existing volumes, provides for the migration of data from a specified set of disks, and provides facilities for the on-line backup of existing volumes.
vxassist在创建卷组时,如果不指定,缺省的会把卷分配给rootdg(note:在VxVM4.0中rootdg不再必须,但是你可以指定一个default dg具有类似的功能).
vxassist的缺省单位是blocks,但是你可以指定K 或 M 或 G 为单位,这都是合法的.
The default behavior of vxassist is to create volumes in the rootdg diskgroup if diskgroup is not specified . The default length is taken as number of blocks but this can be specified in Kilobytes or Megabytes or Gigabytes.
vxassist command syntax :

vxassist <option> <Keyword> volume_name [attributes]

Commonly used options are given below (See man vxassist for complete list of supported options) -g for specifying diskgroups -b for background operation -d file containing defaults for vxassist if not specified /etc/default/vxassist is used Keywords used are make , mirror , move , growto ,growby ,shrintto ,shirnkby ,snapstart , snapshot ,snapwait Attributes specify volumes layout disks controllar to include exclude etc

Device Nodes :

Default rootdg disk group.
Block Device Node /dev/vx/dsk/volume_name
Raw Device Node /dev/vx/rdsk/volume_name
Other DiskGroups
Block Device Node /dev/vx/dsk/diskgroup_name/volume_name
Raw Device Node /dev/vx/rdsk/diskgroup_name/volume_name

_______________________________________

1. Creating a Volume :

1.1 Creating a Concatenated Volume

缺省的,vxassist把一个卷组里的所有磁盘统一看待,如果创建的volume大于单个磁盘,那么空间分配自动的跨越磁盘.
By default, vxassist creates a concatenated volume using the space available on a disk or on the number of disks in a diskgroup if the volume size specified is more then the one available on a single disk.

Disks can be specified from a diskgroup for a volume group but if not mentioned available disks are selected by the volume manager.

Command syntax :

· vxassist make volume_name volume_length

To create a new volume appvol of 100 MB in the default disk group rootdg with available disks:
· #vxassist make appvol 100m

To create the volume appvol of 100MB on disk03

· #vxassist make appvol 100m disk03

1.2 Creating a Striped Volume

A striped volume contains at least one plex that consists of two or more subdisks located on two or more physical disks.

Command Syntax :

· vxassist make volume_name length layout=stripe

To create a striped volume appvol2 with the default stripe unit size on the default number of disks

· #vxassist make appvol2 100m layout=stripe

To create a striped volume appvol2 100MB striped volume on three specific disks.

· #vxassist make appvol2 100m layout=stripe disk04 disk05 disk06

1.3 Creating a RAID-5 Volume

A RAID-5 volume contains a RAID-5 plex that consists of two or more subdisks located on two or more physical disks. Only one RAID-5 plex can exist per volume. A RAID-5 volume may also contain one or more RAID-5 log plexes, which are used to log information about data and parity being written to the volume.

Command Syntax :

· vxassist make volume_name length layout=raid5

To create the RAID-5 volume appvol4 with the default stripe unit size on the default number of disks with RAID-5 log,

· #vxassist make appvol4 100m layout=raid5.

2. Extending a Volume--扩展一个建好的Volume

Caution : If you plan to use volume size change (grow or shrink ) on a volume with data make sure you have the good backup of the volume available before carrying out such operation .

2.1 Extending a volume up to certain length

Command syntax

· vxassist growto volume_name length

To extend vol3 upto 8000 sectors, type:--例如,扩展vol3到8000个扇区

· #vxassist growto vol3 8000

Note:这里可以指定大小,例如:

vxassist growto redo101 100M

如果使用的是非缺省DG,还需要指定磁盘组:

vxassist -g oradg growto redo101 100M

2.2 Extending by a Given Length

Command Syntax

· vxassist growby volume_name length

To extend volapp by 1000 sectors, type:

· #vxassist growby volapp 1000

3. Shrinking a Volume

Caution - Do not shrink a volume below the size of the file system. If you have a VxFS file system, you can shrink the file system and then shrink the volume. If you do not shrink the file system first, you risk unrecoverable data loss.

Always make sure you have a good backup of the data volume to be shirnked.

3.1 Shrinking to a Given Length

Shrink a volume to a specific length as follows:

· vxassist shrinkto volume_name length

Make sure you do not shrink the volume below the current size of the file system or database using the volume. This command can be safely used on empty volumes.

To shrink volcat to 1300 sectors, type:

· #vxassist shrinkto volcat 1300

3.2 Shrinking by a Given Length

Shrink a volume by a specific length as follows:

· vxassist shrinkby volume_name length

To shrink volcat by 8000 sectors, type:

· #vxassist shrinkby volapp2 8000

4. Removing a Volume

Removing a volume requires removing all references to the volumes to be removed like unmounting the volume if mounted and removing its reference from /etc/vfstab .

如果你需要remove一个volume,那么首先你需要stop这个卷组,停止其上的所有活动事务.
An active volume has to be stopped first to stop all the activities to the volume only then it can be removed.

Stopping Volume :

Command Syntax

· vxvol stop volume_name

To stop appvol1

· #vxvol stop appvol1

Removing Volume

Command Syntax

· vxedit -rf rm volume_name

To remove the volume appvol1

· #vxedit -rf rm appvol11

5. Mirroring a Volume

Mirroring allow data to be written simultaneously to two disks so that in case of failure of one disk data is available from the other mirrored disk. Boot disks can be mirriored to provide alternate booting disk .

5.1 Creating & Mirroring a New Volume

Command Syntax :

· vxassist make volume_name length layout=mirror

To create the mirrored volume, appvol22 of 100mb

· #vxassist make appvol22 100m layout=mirror

To create a volume with Dirty Region Logging enabled

· #vxassist make volume_name length layout=mirror,log

5.2 Mirroring an Existing Volume

Command syntax

· vxassist mirror volume_name

Creating a mirror of volume vol44:

· #vxassist mirror vol44

5.3 Mirroring All Volumes

To mirror all existing volumes to available disk space

· /etc/vx/bin/vxmirror -a

6. Removing a Mirror

Removing a mirror involves first dissociating the plex from its volume and then removing the plex and any associated subdisks completely.The last valid mirror plex associated with a volume cannot be removed.

Dissociate and remove the plex from its volume as follows:

· vxplex -o rm dis plex_name

vxprint -h shows the volume and associated plexes :

Disk group: rootdg TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0 v volm fsgen ENABLED 10240 - ACTIVE - - pl volm-01 volm ENABLED 10240 - ACTIVE - - sd disk01-02 volm-01 - 10240 0 - - - pl volm-02 volm ENABLED 10240 - ACTIVE - - sd disk02-03 volm-02 - 10240 0 - - -

To disassociate and remove volmir-02 from volmir, type:

· #vxplex -o rm dis volm-02

The output of vxprint -h for volm now shows volume volm with only one plex::

Disk group: rootdg TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0 v volm fsgen ENABLED 10240 - ACTIVE - - pl volm-01 volmir ENABLED 10240 - ACTIVE - - sd disk01-02 volmir-01 - 10240 0 - - -

7. Adding a RAID-5 Log

A RAID-5 log maintains a copy of the data and parity being written to the volume at any given time. If a system failure occurs, VxVM can replay the RAID-5 log to resynchronize the volume. This copies the data and parity that was being written at the time of failure from the log to the appropriate areas of the RAID-5 volume.

RAID-5 log plexes are used to log information about data and parity being written to the raid volume. A log plex is created for the volume by default when a raid volume is created but additional ones can be added by following command .

· vxassist addlog name_of_raid5_vol

8. Adding a DRL Log

Dirty region logging (DRL) is used with mirrored volume layouts. DRL keeps track of the regions that have changed due to I/O writes to a mirrored volume. Prior to every write, a bitmap is written to a log to record the area of the disk that is being changed. In case of system failure, DRL uses this information to recover only the portions of the volume that need to be recovered.

To put Dirty Region Logging into effect for a volume, a log subdisk must be added to that volume and the volume must be mirrored. Only one log subdisk can exist per plex.

The following example creates a log for the mirrored volume vol03:

· #vxassist addlog vol03

When vxassist is used to add a log subdisk to a volume, a log plex is also created to contain the log subdisk, by default.

Once created, the plex containing a log subdisk can be treated as a regular plex. Data subdisks can be added to the log plex. The log plex and log subdisk can be removed using the same procedures used to remove ordinary plexes and subdisks.

9. Removing a RAID-5 Log

Removing a RAID-5 log involves first dissociating the log from its volume and then removing the log and any associated subdisks completely.

Dissociate the log from its volume as follows:

· #vxplex -o rm dis plex_name

To identify the log plex, use the command:

· vxprint -ht raid5_volume_name

To disassociate the log plex volrd-02 from volrd, type:

· #vxplex -o rm dis volrd-02

The output of vxprint -h for volrd now shows:

Disk group: rootdg TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0 v volrd raid5 ENABLED 32 - ACTIVE - - pl volrd-01 volrd ENABLED 32 - ACTIVE - - sd disk01-02 volrd-01 - 32 0 - - - sd disk02-03 volrd-01 - 32 0 - - -

10. Preparing a Volume for Online Backup

Volume manager provides an easy way to take backup of the online data by creating an offline snapshot mirror of the volume .

The vxassist snapstart operation creates a write-only backup mirror, which is attached to and synchronized with the volume to be backed up and later detached and made offline by vxassist snapshot command . The snapshot volume can be used by backup utilities while the original volume continues to be available for applications and users.

The volume backup method described here does not apply to RAID-5 volumes.

Backing up a volume with vxassist involves the following procedure

Create a snapshot mirror

snapstart starts creating a online snapshot mirror of the volume using the available disk space . The snapshot is completed with vxassist snapshot command when offline snapshot volume is created with a userdefined name .

Command Syntax:

  • vxassist snapstart volume_name

To create a snapshot mirror of a volume called vol8, type

  • #vxassist snapstart vol8

Create a snapshot volume

Command Syntax

vxassist snapshot volume_name new_volume_name

To create a snapshot volume of vol8, type:

#vxassist snapshot vol8 snapvol8

You can now back up the snapshot volume by whatever means you prefer. To avoid wasting space, you can then remove the snapshot volume, which occupies as much space as the original volume

11 Displaying Volume Configuration Information

The vxprint command can be used to display information about how a volume is configured.

Display the volume, mirror, and subdisk record information for all volumes as follows:

#vxprint -ht

  Disk group: rootdg

  DG  NAME        NCONFIG    NLOG      MINORS     GROUP-ID
  DM  NAME        DEVICE     TYPE      PRIVLEN    PUBLEN     STATE
  V   NAME        USETYPE    KSTATE    STATE      LENGTH     READPOL      PREFPLEX
  PL  NAME        VOLUME     KSTATE    STATE      LENGTH     LAYOUT       NCOL/WID MODE
  SD  NAME        PLEX       DISK      DISKOFFS LENGTH       [COL/]OFF    DEVICE     MODE

  dg  rootdg      759096729.1025.tweety

  dm  disk10      c1t0d0s2 sliced      559        1044400     -
  dm  disk20      c2t0d0s2 sliced      559        1044400     -

  v   pubs        fsgen      ENABLED ACTIVE       2288       SELECT       -
  pl  pubs-01     pubs       ENABLED ACTIVE       2288       CONCAT       -          RW
  sd  disk10-01 pubs-01      disk10    0          2288       0            c0t0d0     ENA

  v   vol8      fsgen      ENABLED ACTIVE       20480      SELECT       -
  pl  vol8-01   vol8       ENABLED ACTIVE       20480      CONCAT       -          RW
  sd  disk10-02 vol8-0 disk10        2288       20480      0            c0t1d0     ENA

where dg is a disk group, dm is a disk, v is a volume, pl is a plex, and sd is a subdisk. The top few lines indicate the headers that match each type of output line that follows. Each volume is listed along with its associated plex(es) and subdisk(s).

Display volume-related information for a specific volume as follows:

#vxprint -t volume_name

To display information about vol8, type:

#vxprint -t vol8


如何在VCS中创建共享磁盘-www.eygle.com

如何在VCS中创建共享磁盘

Monday, 2004-09-20 16:22 Eygle

1.创建磁盘组

# vxdiskadm

Volume Manager Support Operations
Menu: VolumeManager/Disk

 1      Add or initialize one or more disks
 2      Encapsulate one or more disks
 3      Remove a disk
 4      Remove a disk for replacement
 5      Replace a failed or removed disk
 6      Mirror volumes on a disk
 7      Move volumes from a disk
 8      Enable access to (import) a disk group
 9      Remove access to (deport) a disk group
 10     Enable (online) a disk device
 11     Disable (offline) a disk device
 12     Mark a disk as a spare for a disk group
 13     Turn off the spare flag on a disk
 14     Unrelocate subdisks back to a disk
 15     Exclude a disk from hot-relocation use
 16     Make a disk available for hot-relocation use
 17     Prevent multipathing/Suppress devices from VxVM's view
 18     Allow multipathing/Unsuppress devices from VxVM's view
 19     List currently suppressed/non-multipathed devices
 20     Change the disk naming scheme
 21     Get the newly connected/zoned disks in VxVM view
 22     Change/Display the default disk layouts
 23     Mark a disk as allocator-reserved for a disk group
 24     Turn off the allocator-reserved flag on a disk
 list   List disk information

 ?      Display help about menu
 ??     Display help about the menuing system
 q      Exit from menus

Select an operation to perform: 1

Add or initialize disks
Menu: VolumeManager/Disk/AddDisks
  Use this operation to add one or more disks to a disk group.  You can
  add the selected disks to an existing disk group or to a new disk group
  that will be created as a part of the operation. The selected disks may
  also be added to a disk group as spares. Or they may be added as
  nohotuses to be excluded from hot-relocation use. The selected
  disks may also be initialized without adding them to a disk group
  leaving the disks available for use as replacement disks.

  More than one disk or pattern may be entered at the prompt.  Here are
  some disk selection examples:

  all:          all disks
  c3 c4t2:      all disks on both controller 3 and controller 4, target 2
  c3t4d2:       a single disk (in the c#t#d# naming scheme)
  xyz_0 :       a single disk (in the enclosure based naming scheme)
  xyz_ :        all disks on the enclosure whose name is xyz

Select disk devices to add: [,all,list,q,?] list

DEVICE       DISK         GROUP        STATUS
c0t0d0       -            -            online invalid
c0t1d0       -            -            online invalid
c2t0d2       -            -            online

Select disk devices to add: [,all,list,q,?] c2t0d2
  Here is the disk selected.  Output format: [Device_Name]

  c2t0d2

Continue operation? [y,n,q,?] (default: y)
  You can choose to add this disk to an existing disk group, a
  new disk group, or leave the disk available for use by future
  add or replacement operations.  To create a new disk group,
  select a disk group name that does not yet exist.  To leave
  the disk available for future use, specify a disk group name
  of "none".

Which disk group [,none,list,q,?] (default: 9iRac) oradg
  There is no active disk group named oradg.

Create a new group named oradg? [y,n,q,?] (default: y)

Create the disk group as a CDS disk group? [y,n,q,?] (default: y)

Use a default disk name for the disk? [y,n,q,?] (default: y)

Add disk as a spare disk for oradg? [y,n,q,?] (default: n)

Exclude disk from hot-relocation use? [y,n,q,?] (default: n)
  A new disk group will be created named oradg and the selected disks
  will be added to the disk group with default disk names.

  c2t0d2

Continue with operation? [y,n,q,?] (default: y)
  The following disk device appears to have been initialized already.
  The disk is currently available as a replacement disk.
  Output format: [Device_Name]

  c2t0d2

Use this device? [y,n,q,?] (default: y)
  The following disk you selected for use appears to already have
  been initialized for the Volume Manager.  If you are certain the
  disk has already been initialized for the Volume Manager, then you
  do not need to reinitialize the disk device.
  Output format: [Device_Name]

  c2t0d2

Reinitialize this device? [y,n,q,?] (default: y)
  Initializing device c2t0d2.

Enter desired private region length
[,q,?] (default: 2048)
  VxVM  NOTICE V-5-2-120
Creating a new disk group named oradg containing the disk
  device c2t0d2 with the name oradg01.

Add or initialize other disks? [y,n,q,?] (default: n)

Volume Manager Support Operations
Menu: VolumeManager/Disk

 1      Add or initialize one or more disks
 2      Encapsulate one or more disks
 3      Remove a disk
 4      Remove a disk for replacement
 5      Replace a failed or removed disk
 6      Mirror volumes on a disk
 7      Move volumes from a disk
 8      Enable access to (import) a disk group
 9      Remove access to (deport) a disk group
 10     Enable (online) a disk device
 11     Disable (offline) a disk device
 12     Mark a disk as a spare for a disk group
 13     Turn off the spare flag on a disk
 14     Unrelocate subdisks back to a disk
 15     Exclude a disk from hot-relocation use
 16     Make a disk available for hot-relocation use
 17     Prevent multipathing/Suppress devices from VxVM's view
 18     Allow multipathing/Unsuppress devices from VxVM's view
 19     List currently suppressed/non-multipathed devices
 20     Change the disk naming scheme
 21     Get the newly connected/zoned disks in VxVM view
 22     Change/Display the default disk layouts
 23     Mark a disk as allocator-reserved for a disk group
 24     Turn off the allocator-reserved flag on a disk
 list   List disk information

 ?      Display help about menu
 ??     Display help about the menuing system
 q      Exit from menus

Select an operation to perform: q

Goodbye.

2.设置共享磁盘组

# vxdg list
NAME STATE ID
oradg enabled,cds 1094209675.12.cluster2
# vxdg free
GROUP DISK DEVICE TAG OFFSET LENGTH FLAGS
oradg oradg01 c2t0d2s2 c2t0d2 0 244143872 -

3.通过以下方式验证主节点:

# vxclustadm -v nodestate
state: cluster member
        nodeId=1
        masterId=1 --这就是主节点id
        neighborId=0
        members=0x3
        joiners=0x0
        leavers=0x0
        reconfig_seqnum=0x2a9209
        vxfen=off
# fsclustadm idtoname 1
cluster1

或者使用:
# vxdctl -c mode
mode: enabled: cluster active - SLAVE
master: cluster1

如果你的输出出现以下提示:

# ./vxclustadm -v nodestate
state: out of cluster

这说明你没有正确配置IO Fencing.我们可以通过如下方式禁用IO Fencing.

创建/etc/vxfenmode 文件

增加一行:

vxfen_mode=disabled

重起Cluster既可.

4.在master节点上进行以下操作

# vxdg deport oradg
# vxdg -s import oradg
# vxdg list
NAME         STATE           ID
oradg        enabled,shared,cds   1094209675.12.cluster2
#

5.此时在另外节点上
应该可以看到此共享磁盘组

# vxdg list
NAME         STATE           ID
oradg        enabled,shared,cds   1094209675.12.cluster2
# hostname
cluster1
#


安装Veritas Storage Fundation For Oracle Rac4.0 -www.eygle.com

安装Veritas Storage Fundation For Oracle Rac4.0

Friday, 2004-09-03 23:35 Eygle

1.设置rsh许可
可以简单的配置.rhosts文件
# cat /.rhosts
+
#

在两台主机分别执行以下命令测试设置是否生效
# rsh cluster2 date
Fri Sep 3 04:06:56 CST 2004

2.使用安装工具进行安装

# ls
cluster_file_solutions_gsg.pdf          perl                                    storage_foundation_for_oracle_rac
gnu                                     rr_moved                                support
installer                               storage_foundation_cluster_file_system  windows
# ./installer

                                                 VERITAS Cluster File Solutions 4.0

Copyright (c) 2004 VERITAS Software Corporation. All rights reserved.

VERITAS, the VERITAS Logo and all other VERITAS product names and slogans are trademarks or registered trademarks of VERITAS
Software Corporation. VERITAS and the VERITAS Logo Reg. U.S. Pat. & Tm. Off. Other product names and/or slogans mentioned herein
may be trademarks or registered trademarks of their respective companies.

                                                 VERITAS Cluster File Solutions 4.0

VERITAS Product                             Version Installed   Licensed
===========================================================================
Storage Foundation for Cluster File System        no              yes
Storage Foundation for Oracle RAC                 no              yes
Enterprise Administrator GUI                      no

Selection Menu:

    I) Install/Upgrade a Product    C) Configure an Installed Product
    L) License a Product            P) Perform a Preinstallation Check
    U) Uninstall a Product          D) View a Product Description
    Q) Quit                         ?) Help

Enter a Selection: [I,C,L,P,U,D,Q,?] I

--选择安装软件,最好在此前使用L,输入有效的License或Demo License

                                                 VERITAS Cluster File Solutions 4.0

     1)  VERITAS Storage Foundation for Cluster File System
     2)  VERITAS Storage Foundation for Oracle RAC
     3)  VERITAS Enterprise Administrator GUI
     B)    Back to previous menu

Select a product to install: [1-3,b,q] 2

--此处安装的是For Oracle RAC的版本

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Copyright (c) 2004 VERITAS Software Corporation. All rights reserved.

VERITAS, the VERITAS Logo and all other VERITAS product names and slogans are trademarks or registered trademarks of VERITAS
Software Corporation. VERITAS and the VERITAS Logo Reg. U.S. Pat. & Tm. Off. Other product names and/or slogans mentioned herein
may be trademarks or registered trademarks of their respective companies.

Enter the system names separated by spaces on which to install SFRAC: cluster1 cluster2

--输入需要安装Cluster的节点名称

Checking system communication:

    Checking OS version on cluster1 ................................................................................. SunOS 5.9
    Checking VRTSdbac package ................................................................................... not installed
    Verifying communication with cluster2 ..................................................................... ping successful
    Attempting rsh with cluster2 ............................................................................... rsh successful
    Attempting rcp with cluster2 ............................................................................... rcp successful
    Checking OS version on cluster2 ................................................................................. SunOS 5.9
    Checking VRTSdbac package ................................................................................... not installed
    Creating log directory on cluster2 ................................................................................... Done

Logs for installer are being created in /var/tmp/installer902153656.

Using /usr/bin/rsh and /usr/bin/rcp to communicate with remote systems.

Initial system check completed successfully.

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

VERITAS Infrastructure package installation:

Installing VERITAS Infrastructure packages on cluster1:

    Checking VRTScpi package .......................................................................... version 4.0.5 installed
    Checking VRTSvlic package ..................................................................... version 3.02.005d installed

Installing VERITAS Infrastructure packages on cluster2:

    Checking VRTScpi package .......................................................................... version 4.0.5 installed
    Checking VRTSvlic package ..................................................................... version 3.02.005d installed

VERITAS Infrastructure packages installed successfully.

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Each system requires a SFRAC product license before installation.  License keys for additional product features should also be
added at this time.

Some license keys are node locked and are unique per system.  Other license keys, such as demo keys and site license keys, are
registered on all systems and must be entered on the first system.

SFRAC Licensing Verification:

    Checking SFRAC license key on cluster1 ............................................. Storage Foundation for Oracle RAC Demo

Do you want to enter another license key for cluster1? [y,n,q,?] (n)

    Checking SFRAC license key on cluster2 ............................................. Storage Foundation for Oracle RAC Demo

Do you want to enter another license key for cluster2? [y,n,q,?] (n)

--此处进行的是License验证,我的此前已经输入了Demo License

SFRAC licensing verified successfully.

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

installer will install the following SFRAC packages:
VRTSperl     VERITAS Perl 5.8.0 Redistribution
VRTSob       VERITAS Enterprise Administrator Service
VRTSmuob     VERITAS Enterprise Administrator Service Localized Package
VRTSobgui    VERITAS Enterprise Administrator
VRTSvxvm     VERITAS Volume Manager Binaries
VRTSvmman    VERITAS Volume Manager Manual Pages
VRTSvmdoc    VERITAS Volume Manager Documentation
VRTSvmpro    VERITAS Volume Manager Management Services Provider
VRTSfspro    VERITAS File System Management Services Provider
VRTSalloc    VERITAS Volume Manager Intelligent Storage Provisioning
VRTSddlpr    VERITAS Device Discovery Layer Services Provider
VRTSvxfs     VERITAS File System
VRTStep      VERITAS Task Provider
VRTSap       VERITAS Action Provider
VRTSfppm     VERITAS File Placement Policy Manager
VRTSfsman    VERITAS File System Manual Pages
VRTSfsdoc    VERITAS File System Documentation
VRTSllt      VERITAS Low Latency Transport
VRTSgab      VERITAS Group Membership and Atomic Broadcast

Press [Return] to continue:
...continued:
VRTSvxfen    VERITAS I/O Fencing
VRTSvcs      VERITAS Cluster Server
VRTSvcsmg    VERITAS Cluster Server Message Catalogs
VRTSvcsag    VERITAS Cluster Server Bundled Agents
VRTSvcsmn    VERITAS Cluster Server Man Pages
VRTScspro    VERITAS Cluster Server VEA Provider
VRTSvcsdc    VERITAS Cluster Server Documentation
VRTSjre      VERITAS Java Runtime Environment Redistribution
VRTScutil    VERITAS Cluster Utilities
VRTScssim    VERITAS Cluster Server Simulator
VRTScscw     VERITAS Cluster Server Configuration Wizards
VRTSweb      VERITAS Java Web Server
VRTSvcsw     VERITAS Cluster Manager (Web Console)
VRTScscm     VERITAS Cluster Server Cluster Manager
VRTScavf     VERITAS Cluster Server Agents for Cluster File System
VRTSglm      VERITAS Group Lock Manager
VRTSgms      VERITAS Group Messaging Services
VRTSodm      VERITAS Oracle Disk Manager
VRTSvail     VERITAS Array Provider
VRTSdbac     VERITAS Oracle Real Application Cluster Support Package

Press [Return] to continue:
...continued:
VRTSracdc    VERITAS Storage Foundation 4.0 for Oracle RAC Documentation
VRTSvcsor    VERITAS Cluster Server Oracle Enterprise Extension
VRTScsocw    VERITAS Cluster Server Oracle 9i RAC Wizard
VRTSvcsvr    VERITAS Cluster Server VVR Agent
VRTSdbckp    VERITAS Storage Foundation Checkpoint Scripts
VRTSvxmsa    VERITAS Mapping Service, Application Libraries

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Checking system installation requirements:

Checking SFRAC installation requirements on cluster1:

    Checking VRTSperl package ................................................................................... not installed
    Checking VRTSob package ..................................................................................... not installed
    Checking VRTSmuob package ................................................................................... not installed
    Checking VRTSobgui package .................................................................................. not installed
    Checking VRTSvxvm package ................................................................................... not installed
    Checking VRTSvmman package .................................................................................. not installed
    Checking VRTSvmdoc package .................................................................................. not installed
    Checking VRTSvmpro package .................................................................................. not installed
    Checking VRTSfspro package .................................................................................. not installed
    Checking VRTSalloc package .................................................................................. not installed
    Checking VRTSddlpr package .................................................................................. not installed
    Checking VRTSvxfs package ................................................................................... not installed
    Checking VRTStep package .................................................................................... not installed
    Checking VRTSap package ..................................................................................... not installed
    Checking VRTSfppm package ................................................................................... not installed
    Checking VRTSfsman package .................................................................................. not installed
    Checking VRTSfsdoc package .................................................................................. not installed
    Checking VRTSllt package .................................................................................... not installed
    Checking VRTSgab package .................................................................................... not installed
    Checking VRTSvxfen package .................................................................................. not installed
    Checking VRTSvcs package .................................................................................... not installed
    Checking VRTSvcsmg package .................................................................................. not installed
    Checking VRTSvcsag package .................................................................................. not installed
    Checking VRTSvcsmn package .................................................................................. not installed
    Checking VRTScspro package .................................................................................. not installed
    Checking VRTSvcsdc package .................................................................................. not installed
    Checking VRTSjre package .................................................................................... not installed
    Checking VRTScutil package .................................................................................. not installed
    Checking VRTScssim package .................................................................................. not installed
    Checking VRTScscw package ................................................................................... not installed
    Checking VRTSweb package .................................................................................... not installed
    Checking VRTSvcsw package ................................................................................... not installed
    Checking VRTScscm package ................................................................................... not installed
    Checking VRTScavf package ................................................................................... not installed
    Checking VRTSglm package .................................................................................... not installed
    Checking VRTSgms package .................................................................................... not installed
    Checking VRTSodm package .................................................................................... not installed
    Checking VRTSvail package ................................................................................... not installed
    Checking VRTSdbac package ................................................................................... not installed
    Checking VRTSracdc package .................................................................................. not installed
    Checking VRTSvcsor package .................................................................................. not installed
    Checking VRTScsocw package .................................................................................. not installed
    Checking VRTSvcsvr package .................................................................................. not installed
    Checking VRTSdbckp package .................................................................................. not installed
    Checking VRTSvxmsa package .................................................................................. not installed
    Checking required SunOS patch 113277-08 on cluster1 ................................................... 113277-24 installed
    Checking VERITAS patch 115209 ............................................................................... not installed
    Checking VERITAS patch 115212 ............................................................................... not installed
    Checking VERITAS patch 115210 ............................................................................... not installed
    Checking VERITAS patch 115217 ............................................................................... not installed
    Checking for any Solaris patch issues ................................................................................ None
    Checking file system space .................................................................... required space is available
    Checking odm driver ........................................................................................... not running
    Checking vxgms driver ......................................................................................... not running
    Checking vxportal driver ...................................................................................... not running
    Checking fdd driver ........................................................................................... not running
    Checking qlog driver .......................................................................................... not running
    Checking vxfs driver .......................................................................................... not running
    Checking VRTSweb process ...................................................................................... not running
    Checking had process .......................................................................................... not running
    Checking hashadow process ..................................................................................... not running
    Checking CmdServer process .................................................................................... not running
    Checking notifier process ..................................................................................... not running
    Checking vxsvc process ........................................................................................ not running
    Checking vcsmm driver ......................................................................................... not running
    Checking lmx driver ........................................................................................... not running
    Checking odm driver ........................................................................................... not running
    Checking vxgms driver ......................................................................................... not running
    Checking vxfen driver ......................................................................................... not running
    Checking gab driver ........................................................................................... not running
    Checking llt driver ........................................................................................... not running
    Checking vxportal driver ...................................................................................... not running
    Checking fdd driver ........................................................................................... not running
    Checking qlog driver .......................................................................................... not running
    Checking vxfs driver .......................................................................................... not running

Checking SFRAC installation requirements on cluster2:

    Checking VRTSperl package ................................................................................... not installed
    Checking VRTSob package ..................................................................................... not installed
    Checking VRTSmuob package ................................................................................... not installed
    Checking VRTSobgui package .................................................................................. not installed
    Checking VRTSvxvm package ................................................................................... not installed
    Checking VRTSvmman package .................................................................................. not installed
    Checking VRTSvmdoc package .................................................................................. not installed
    Checking VRTSvmpro package .................................................................................. not installed
    Checking VRTSfspro package .................................................................................. not installed
    Checking VRTSalloc package .................................................................................. not installed
    Checking VRTSddlpr package .................................................................................. not installed
    Checking VRTSvxfs package ................................................................................... not installed
    Checking VRTStep package .................................................................................... not installed
    Checking VRTSap package ..................................................................................... not installed
    Checking VRTSfppm package ................................................................................... not installed
    Checking VRTSfsman package .................................................................................. not installed
    Checking VRTSfsdoc package .................................................................................. not installed
    Checking VRTSllt package .................................................................................... not installed
    Checking VRTSgab package .................................................................................... not installed
    Checking VRTSvxfen package .................................................................................. not installed
    Checking VRTSvcs package .................................................................................... not installed
    Checking VRTSvcsmg package .................................................................................. not installed
    Checking VRTSvcsag package .................................................................................. not installed
    Checking VRTSvcsmn package .................................................................................. not installed
    Checking VRTScspro package .................................................................................. not installed
    Checking VRTSvcsdc package .................................................................................. not installed
    Checking VRTSjre package .................................................................................... not installed
    Checking VRTScutil package .................................................................................. not installed
    Checking VRTScssim package .................................................................................. not installed
    Checking VRTScscw package ................................................................................... not installed
    Checking VRTSweb package .................................................................................... not installed
    Checking VRTSvcsw package ................................................................................... not installed
    Checking VRTScscm package ................................................................................... not installed
    Checking VRTScavf package ................................................................................... not installed
    Checking VRTSglm package .................................................................................... not installed
    Checking VRTSgms package .................................................................................... not installed
    Checking VRTSodm package .................................................................................... not installed
    Checking VRTSvail package ................................................................................... not installed
    Checking VRTSdbac package ................................................................................... not installed
    Checking VRTSracdc package .................................................................................. not installed
    Checking VRTSvcsor package .................................................................................. not installed
    Checking VRTScsocw package .................................................................................. not installed
    Checking VRTSvcsvr package .................................................................................. not installed
    Checking VRTSdbckp package .................................................................................. not installed
    Checking VRTSvxmsa package .................................................................................. not installed
    Checking required SunOS patch 113277-08 on cluster2 ................................................... 113277-24 installed
    Checking VERITAS patch 115209 ............................................................................... not installed
    Checking VERITAS patch 115212 ............................................................................... not installed
    Checking VERITAS patch 115210 ............................................................................... not installed
    Checking VERITAS patch 115217 ............................................................................... not installed
    Checking for any Solaris patch issues ................................................................................ None
    Checking file system space .................................................................... required space is available
    Checking odm driver ........................................................................................... not running
    Checking vxgms driver ......................................................................................... not running
    Checking vxportal driver ...................................................................................... not running
    Checking fdd driver ........................................................................................... not running
    Checking qlog driver .......................................................................................... not running
    Checking vxfs driver .......................................................................................... not running
    Checking VRTSweb process ...................................................................................... not running
    Checking had process .......................................................................................... not running
    Checking hashadow process ..................................................................................... not running
    Checking CmdServer process .................................................................................... not running
    Checking notifier process ..................................................................................... not running
    Checking vxsvc process ........................................................................................ not running
    Checking vcsmm driver ......................................................................................... not running
    Checking lmx driver ........................................................................................... not running
    Checking odm driver ........................................................................................... not running
    Checking vxgms driver ......................................................................................... not running
    Checking vxfen driver ......................................................................................... not running
    Checking gab driver ........................................................................................... not running
    Checking llt driver ........................................................................................... not running
    Checking vxportal driver ...................................................................................... not running
    Checking fdd driver ........................................................................................... not running
    Checking qlog driver .......................................................................................... not running
    Checking vxfs driver .......................................................................................... not running

Installation requirement checks completed successfully.

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Before SFRAC is installed, be sure you have reviewed the VERITAS Storage Foundation 4.0 for Oracle RAC Installation and
Configuration Guide

A copy of a previous VxVM configuration is present on the system cluster2.

Do you want to restore and reuse the previous VxVM configuration of system cluster2 [y,n,q,?] (y) n

--如果之前安装过,配置文件有备份，可以重用，也可以重新配置

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

It is possible to install SFRAC packages without performing configuration.

SFRAC cannot be started without proper configuration.

It is optional to configure SFRAC now. If you choose to configure SFRAC later, you can either do so manually or run the
installsfrac -configure command.
Are you ready to configure SFRAC? [y,n,q] (y)

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

installer will now ask sets of SFRAC configuration-related questions.

When a [b] is presented after a question, 'b' may be entered to go back to the first question of the configuration set.

When a [?] is presented after a question, '?' may be entered for help or additional information about the question.

Following each set of questions, the information you have entered will be presented for confirmation.  To repeat the set of
questions and correct any previous errors, enter 'n' at the confirmation prompt.

No configuration changes are made to the systems until all configuration questions are completed and SFRAC is installed
successfully.

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

To configure VCS for SFRAC the following is required:

        A unique Cluster name
        A unique Cluster ID number between 0-255
        Two or more NIC cards per system used for heartbeat links

All systems are being configured to create one cluster

Enter the unique cluster name: [?] ora9i
Enter the unique Cluster ID number between 0-255: [b,?] 1

--输入Cluster名称及ID号

    Discovering NICs on cluster1 ......... discovered bge0 bge1 bge2 bge3 chipid driverinfo lpfc0 parameters phydata statistics

Enter the NIC for the first private heartbeat link on cluster1: [b,?] bge1
Would you like to configure a second private heartbeat link? [y,n,q,b,?] (y)
Enter the NIC for the second private heartbeat link on cluster1: [b,?] bge2
Would you like to configure a third private heartbeat link? [y,n,q,b,?] (n)
Are you using the same NICs for private heartbeat links on all systems? [y,n,q,b,?] (y)

--选择心跳网卡,最好有两块

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Cluster information verification:

        Cluster Name: ora9i
        Cluster ID Number: 1
        Private Heartbeat NICs for cluster1: link1=bge1 link2=bge2
        Private Heartbeat NICs for cluster2: link1=bge1 link2=bge2

Is this information correct? [y,n,q] (y)

--确认配置信息后继续

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

The following information is required to configure Cluster Manager:

        A public NIC used by each system in the cluster
        A Virtual IP address and netmask for Cluster Manager

Do you want to configure Cluster Manager (Web Console) [y,n,q] (y)
Active NIC devices discovered on cluster1: bge0
Enter the NIC for Cluster Manager (Web Console) to use on cluster1: [b,?] (bge0)
Is bge0 to be the public NIC used by all systems [y,n,q,b,?] (y)
Enter the Virtual IP address for Cluster Manager: [b,?] 172.16.33.74
Enter the netmask for IP 172.16.33.74: [b,?] (255.255.255.0)

--设置虚拟浮动ip地址

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Cluster Manager (Web Console) verification:

        NIC: bge0
        IP: 172.16.33.74
        Netmask: 255.255.255.0

Is this information correct? [y,n,q] (y)

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

The following information is required to configure SMTP notification:

        The domain-based hostname of the SMTP server
        The email address of each SMTP recipient
        A minimum severity level of messages to send to each recipient

Do you want to configure SMTP notification? [y,n,q] (y) n

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

The following information is required to configure SNMP notification:

        System names of SNMP consoles to receive VCS trap messages
        SNMP trap daemon port numbers for each console
        A minimum severity level of messages to send to each console

Do you want to configure SNMP notification? [y,n,q] (y) n

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Enter Cluster Volume Manager cluster reconfiguration timeout (sec): (200)

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

SFRAC packages can be installed on systems consecutively or simultaneously. Installing packages on systems consecutively takes
more time but allows for better error handling.

Would you like to install Storage Foundation for Oracle RAC packages on all systems simultaneously? [y,n,q,?] (y)

--是否同时安装两个节点,此前配置好了rsh才有效

Installing Storage Foundation for Oracle RAC 4.0 on all systems simultaneously:

    Copying VRTSperl.tar.gz to cluster2 ................................................................... Done 1 of 147 steps
    Installing VRTSperl 4.0.2 on cluster1 ................................................................. Done 2 of 147 steps
    Installing VRTSperl 4.0.2 on cluster2 ................................................................. Done 3 of 147 steps
    Copying VRTSob.tar.gz to cluster2 ..................................................................... Done 4 of 147 steps
    Installing VRTSob 3.2.514.0 on cluster1 ............................................................... Done 5 of 147 steps
    Installing VRTSmuob 3.2.514.0 on cluster1 ............................................................. Done 6 of 147 steps
    Installing VRTSob 3.2.514.0 on cluster2 ............................................................... Done 7 of 147 steps
    Copying VRTSmuob.tar.gz to cluster2 ................................................................... Done 8 of 147 steps
    Installing VRTSobgui 3.2.514.0 on cluster1 ............................................................ Done 9 of 147 steps
    Installing VRTSmuob 3.2.514.0 on cluster2 ............................................................ Done 10 of 147 steps
    Copying VRTSobgui.tar.gz to cluster2 ................................................................. Done 11 of 147 steps
    Installing VRTSobgui 3.2.514.0 on cluster2 ........................................................... Done 12 of 147 steps
    Copying VRTSvxvm.tar.gz to cluster2 .................................................................. Done 13 of 147 steps
    Installing VRTSvxvm 4.0 on cluster1 .................................................................. Done 14 of 147 steps
    Installing VRTSvmman 4.0 on cluster1 ................................................................. Done 15 of 147 steps
    Installing VRTSvmdoc 4.0 on cluster1 ................................................................. Done 16 of 147 steps
    Installing VRTSvmpro 4.0 on cluster1 ................................................................. Done 17 of 147 steps
    Installing VRTSfspro 4.0 on cluster1 ................................................................. Done 18 of 147 steps
    Installing VRTSalloc 4.0 on cluster1 ................................................................. Done 19 of 147 steps
    Installing VRTSddlpr 4.0 on cluster1 ................................................................. Done 20 of 147 steps
    Installing VRTSvxvm 4.0 on cluster2 .................................................................. Done 21 of 147 steps
    Copying VRTSvmman.tar.gz to cluster2 ................................................................. Done 22 of 147 steps
    Installing VRTSvmman 4.0 on cluster2 ................................................................. Done 23 of 147 steps
    Installing VRTSvxfs 4.0 on cluster1 .................................................................. Done 24 of 147 steps
    Installing VRTStep 1.20.025 on cluster1 .............................................................. Done 25 of 147 steps
    Copying VRTSvmdoc.tar.gz to cluster2 ................................................................. Done 26 of 147 steps
    Installing VRTSap 2.00.015 on cluster1 ............................................................... Done 27 of 147 steps
    Installing VRTSfppm 4.0 on cluster1 .................................................................. Done 28 of 147 steps
    Installing VRTSvmdoc 4.0 on cluster2 ................................................................. Done 29 of 147 steps
    Installing VRTSfsman 4.0 on cluster1 ................................................................. Done 30 of 147 steps
    Copying VRTSvmpro.tar.gz to cluster2 ................................................................. Done 31 of 147 steps
    Installing VRTSfsdoc 4.0 on cluster1 ................................................................. Done 32 of 147 steps
    Installing VRTSllt 4.0 on cluster1 ................................................................... Done 33 of 147 steps
    Installing VRTSgab 4.0 on cluster1 ................................................................... Done 34 of 147 steps
    Installing VRTSvmpro 4.0 on cluster2 ................................................................. Done 35 of 147 steps
    Copying VRTSfspro.tar.gz to cluster2 ................................................................. Done 36 of 147 steps
    Installing VRTSvxfen 4.0 on cluster1 ................................................................. Done 37 of 147 steps
    Installing VRTSfspro 4.0 on cluster2 ................................................................. Done 38 of 147 steps
    Copying VRTSalloc.tar.gz to cluster2 ................................................................. Done 39 of 147 steps
    Installing VRTSvcs 4.0 on cluster1 ................................................................... Done 40 of 147 steps
    Installing VRTSvcsmg 4.0 on cluster1 ................................................................. Done 41 of 147 steps
    Installing VRTSvcsag 4.0 on cluster1 ................................................................. Done 42 of 147 steps
    Installing VRTSvcsmn 4.0 on cluster1 ................................................................. Done 43 of 147 steps
    Installing VRTScspro 4.0 on cluster1 ................................................................. Done 44 of 147 steps
    Installing VRTSvcsdc 4.0 on cluster1 ................................................................. Done 45 of 147 steps
    Installing VRTSalloc 4.0 on cluster2 ................................................................. Done 46 of 147 steps
    Copying VRTSddlpr.tar.gz to cluster2 ................................................................. Done 47 of 147 steps
    Installing VRTSddlpr 4.0 on cluster2 ................................................................. Done 48 of 147 steps
    Installing VRTSjre 1.4 on cluster1 ................................................................... Done 49 of 147 steps
    Installing VRTScutil 4.0 on cluster1 ................................................................. Done 50 of 147 steps
    Copying VRTSvxfs.tar.gz to cluster2 .................................................................. Done 51 of 147 steps
    Installing VRTScssim 4.0 on cluster1 ................................................................. Done 52 of 147 steps
    Installing VRTScscw 4.0 on cluster1 .................................................................. Done 53 of 147 steps
    Installing VRTSweb 4.0 on cluster1 ................................................................... Done 54 of 147 steps
    Installing VRTSvcsw 4.0 on cluster1 .................................................................. Done 55 of 147 steps
    Installing VRTScscm 4.0 on cluster1 .................................................................. Done 56 of 147 steps
    Installing VRTScavf 4.0 on cluster1 .................................................................. Done 57 of 147 steps
    Installing VRTSglm 4.0 on cluster1 ................................................................... Done 58 of 147 steps
    Installing VRTSgms 4.0 on cluster1 ................................................................... Done 59 of 147 steps
    Installing VRTSodm 4.0 on cluster1 ................................................................... Done 60 of 147 steps
    Installing VRTSvxfs 4.0 on cluster2 .................................................................. Done 61 of 147 steps
    Copying VRTStep.tar.gz to cluster2 ................................................................... Done 62 of 147 steps
    Installing VRTStep 1.20.025 on cluster2 .............................................................. Done 63 of 147 steps
    Copying VRTSap.tar.gz to cluster2 .................................................................... Done 64 of 147 steps
    Installing VRTSap 2.00.015 on cluster2 ............................................................... Done 65 of 147 steps
    Copying VRTSfppm.tar.gz to cluster2 .................................................................. Done 66 of 147 steps
    Installing VRTSvail 4.0.0 on cluster1 ................................................................ Done 67 of 147 steps
    Installing VRTSfppm 4.0 on cluster2 .................................................................. Done 68 of 147 steps
    Installing VRTSdbac 4.0 on cluster1 .................................................................. Done 69 of 147 steps
    Copying VRTSfsman.tar.gz to cluster2 ................................................................. Done 70 of 147 steps
    Installing VRTSracdc 4.0 on cluster1 ................................................................. Done 71 of 147 steps
    Installing VRTSvcsor 4.0 on cluster1 ................................................................. Done 72 of 147 steps
    Installing VRTScsocw 4.0 on cluster1 ................................................................. Done 73 of 147 steps
    Installing VRTSvcsvr 4.0 on cluster1 ................................................................. Done 74 of 147 steps
    Installing VRTSdbckp 4.0 on cluster1 ................................................................. Done 75 of 147 steps
    Installing VRTSfsman 4.0 on cluster2 ................................................................. Done 76 of 147 steps
    Installing VRTSvxmsa 4.0 on cluster1 ................................................................. Done 77 of 147 steps
    Copying VRTSfsdoc.tar.gz to cluster2 ................................................................. Done 78 of 147 steps
    Installing VRTSfsdoc 4.0 on cluster2 ................................................................. Done 79 of 147 steps
    Copying VRTSllt.tar.gz to cluster2 ................................................................... Done 80 of 147 steps
    Adding patch 115209-05 on cluster1 ................................................................... Done 81 of 147 steps
    Installing VRTSllt 4.0 on cluster2 ................................................................... Done 82 of 147 steps
    Copying VRTSgab.tar.gz to cluster2 ................................................................... Done 83 of 147 steps
    Adding patch 115212-05 on cluster1 ................................................................... Done 84 of 147 steps
    Adding patch 115210-05 on cluster1 ................................................................... Done 85 of 147 steps
    Installing VRTSgab 4.0 on cluster2 ................................................................... Done 86 of 147 steps
    Copying VRTSvxfen.tar.gz to cluster2 ................................................................. Done 87 of 147 steps
    Installing VRTSvxfen 4.0 on cluster2 ................................................................. Done 88 of 147 steps
    Copying VRTSvcs.tar.gz to cluster2 ................................................................... Done 89 of 147 steps
    Installing VRTSvcs 4.0 on cluster2 ................................................................... Done 90 of 147 steps
    Copying VRTSvcsmg.tar.gz to cluster2 ................................................................. Done 91 of 147 steps
    Installing VRTSvcsmg 4.0 on cluster2 ................................................................. Done 92 of 147 steps
    Adding patch 115217-01 on cluster1 ................................................................... Done 93 of 147 steps
    Copying VRTSvcsag.tar.gz to cluster2 ................................................................. Done 94 of 147 steps
    Installing VRTSvcsag 4.0 on cluster2 ................................................................. Done 95 of 147 steps
    Copying VRTSvcsmn.tar.gz to cluster2 ................................................................. Done 96 of 147 steps
    Installing VRTSvcsmn 4.0 on cluster2 ................................................................. Done 97 of 147 steps
    Copying VRTScspro.tar.gz to cluster2 ................................................................. Done 98 of 147 steps
    Installing VRTScspro 4.0 on cluster2 ................................................................. Done 99 of 147 steps
    Copying VRTSvcsdc.tar.gz to cluster2 ................................................................ Done 100 of 147 steps
    Installing VRTSvcsdc 4.0 on cluster2 ................................................................ Done 101 of 147 steps
    Copying VRTSjre.tar.gz to cluster2 .................................................................. Done 102 of 147 steps
    Installing VRTSjre 1.4 on cluster2 .................................................................. Done 103 of 147 steps
    Copying VRTScutil.tar.gz to cluster2 ................................................................ Done 104 of 147 steps
    Installing VRTScutil 4.0 on cluster2 ................................................................ Done 105 of 147 steps
    Copying VRTScssim.tar.gz to cluster2 ................................................................ Done 106 of 147 steps
    Installing VRTScssim 4.0 on cluster2 ................................................................ Done 107 of 147 steps
    Copying VRTScscw.tar.gz to cluster2 ................................................................. Done 108 of 147 steps
    Installing VRTScscw 4.0 on cluster2 ................................................................. Done 109 of 147 steps
    Copying VRTSweb.tar.gz to cluster2 .................................................................. Done 110 of 147 steps
    Installing VRTSweb 4.0 on cluster2 .................................................................. Done 111 of 147 steps
    Copying VRTSvcsw.tar.gz to cluster2 ................................................................. Done 112 of 147 steps
    Installing VRTSvcsw 4.0 on cluster2 ................................................................. Done 113 of 147 steps
    Copying VRTScscm.tar.gz to cluster2 ................................................................. Done 114 of 147 steps
    Installing VRTScscm 4.0 on cluster2 ................................................................. Done 115 of 147 steps
    Copying VRTScavf.tar.gz to cluster2 ................................................................. Done 116 of 147 steps
    Installing VRTScavf 4.0 on cluster2 ................................................................. Done 117 of 147 steps
    Copying VRTSglm.tar.gz to cluster2 .................................................................. Done 118 of 147 steps
    Installing VRTSglm 4.0 on cluster2 .................................................................. Done 119 of 147 steps
    Copying VRTSgms.tar.gz to cluster2 .................................................................. Done 120 of 147 steps
    Installing VRTSgms 4.0 on cluster2 .................................................................. Done 121 of 147 steps
    Copying VRTSodm.tar.gz to cluster2 .................................................................. Done 122 of 147 steps
    Installing VRTSodm 4.0 on cluster2 .................................................................. Done 123 of 147 steps
    Copying VRTSvail.tar.gz to cluster2 ................................................................. Done 124 of 147 steps
    Installing VRTSvail 4.0.0 on cluster2 ............................................................... Done 125 of 147 steps
    Copying VRTSdbac.tar.gz to cluster2 ................................................................. Done 126 of 147 steps
    Installing VRTSdbac 4.0 on cluster2 ................................................................. Done 127 of 147 steps
    Copying VRTSracdc.tar.gz to cluster2 ................................................................ Done 128 of 147 steps
    Installing VRTSracdc 4.0 on cluster2 ................................................................ Done 129 of 147 steps
    Copying VRTSvcsor.tar.gz to cluster2 ................................................................ Done 130 of 147 steps
    Installing VRTSvcsor 4.0 on cluster2 ................................................................ Done 131 of 147 steps
    Copying VRTScsocw.tar.gz to cluster2 ................................................................ Done 132 of 147 steps
    Installing VRTScsocw 4.0 on cluster2 ................................................................ Done 133 of 147 steps
    Copying VRTSvcsvr.tar.gz to cluster2 ................................................................ Done 134 of 147 steps
    Installing VRTSvcsvr 4.0 on cluster2 ................................................................ Done 135 of 147 steps
    Copying VRTSdbckp.tar.gz to cluster2 ................................................................ Done 136 of 147 steps
    Installing VRTSdbckp 4.0 on cluster2 ................................................................ Done 137 of 147 steps
    Copying VRTSvxmsa.tar.gz to cluster2 ................................................................ Done 138 of 147 steps
    Installing VRTSvxmsa 4.0 on cluster2 ................................................................ Done 139 of 147 steps
    Copying patch 115209-05 to cluster2 ................................................................. Done 140 of 147 steps
    Adding patch 115209-05 on cluster2 .................................................................. Done 141 of 147 steps
    Copying patch 115212-05 to cluster2 ................................................................. Done 142 of 147 steps
    Adding patch 115212-05 on cluster2 .................................................................. Done 143 of 147 steps
    Copying patch 115210-05 to cluster2 ................................................................. Done 144 of 147 steps
    Adding patch 115210-05 on cluster2 .................................................................. Done 145 of 147 steps
    Copying patch 115217-01 to cluster2 ................................................................. Done 146 of 147 steps
    Adding patch 115217-01 on cluster2 .................................................................. Done 147 of 147 steps

Storage Foundation for Oracle RAC installation completed successfully.

Press [Return] to continue:

The enclosure-based naming scheme is a feature of Volume Manager. It allows one to reference disks using a symbolic name that is
more meaningful than the operating system's normal device access name.  This symbolic name is typically derived from the array
name.

Evaluating which systems can be configured for the enclosure-based naming scheme...

System cluster1 is eligible -- can configure.
System cluster2 is eligible -- can configure.

Do you want to set up the enclosure-based naming scheme? [y,n,q,?] (n)

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Configuring Storage Foundation for Oracle RAC:

    Creating Cluster Server configuration files .......................................................................... Done
    Copying configuration files to cluster1 .............................................................................. Done
    Copying configuration files to cluster2 .............................................................................. Done

Storage Foundation for Oracle RAC configured successfully.

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Do you want to start Storage Foundation for Oracle RAC processes now? [y,n,q] (y)

Starting SFRAC:

    Starting LLT on cluster1 .......................................................................................... Started
    Starting LLT on cluster2 .......................................................................................... Started
    Starting GAB on cluster1 .......................................................................................... Started
    Starting GAB on cluster2 .......................................................................................... Started
    Starting Cluster Server on cluster1 ............................................................................... Started
    Checking SFRAC drivers on cluster1 ................................................................................ Checked
    Starting SFRAC drivers on cluster1 ................................................................................ Started
    Starting Cluster Server on cluster2 ............................................................................... Started
    Checking SFRAC drivers on cluster2 ................................................................................ Checked
    Starting SFRAC drivers on cluster2 ................................................................................ Started
    Confirming SFRAC startup ................................................................................ 2 systems RUNNING

Evaluating which systems can now be started...

System cluster1 is eligible -- can be started.
System cluster2 is eligible -- can be started.

Preparing to start VxVM on target systems...

Begin starting VxVM on system cluster1
    Disabling enclosure-based naming ..................................................................................... Done
    Starting vxconfigd for VxVM ..................................................................................... Succeeded
Done starting VxVM on system cluster1

Begin starting VxVM on system cluster2
    Disabling enclosure-based naming ..................................................................................... Done
    Starting vxconfigd for VxVM ..................................................................................... Succeeded
Done starting VxVM on system cluster2

Done with starting VxVM on target systems...

Press [Return] to continue:

Configuring CFS agents for SFRAC:

    Confirming VxVM configuration daemons startup ......................................................... All systems Enabled
    Starting CFS agents ............................................................................................... Started

Full activation of Cluster Manager, Cluster Volume Manager,
and Cluster File System requires a reboot on All Systems.

Execute /usr/sbin/shutdown -y -i6 -g0 to properly restart your systems
Many Volume Manager commands affect the contents or configuration of a disk group. Such commands require that the user specify a
disk group.  This is accomplished by using the -g option of a command or setting the VXVM_DEFAULTDG environment variable.  An
alternative to these two methods is to configure the default disk group of a system.

Evaluating which systems can now have their default disk group configured...

System cluster1 is eligible -- can set the default disk group.
System cluster2 is eligible -- can set the default disk group.

Do you want to set up the default disk group for each system? [y,n,q,?] (y)

Will you specify one disk group name for all eligible systems? [y,n,q,?] (y)

Specify a default disk group for all systems or type 'l' to display a listing of existing disk group(s). [?] l

No previous disk group(s) were detected.

Specify a default disk group for all systems or type 'l' to display a listing of existing disk group(s). [?] 9iRac

You have decided to specify the default disk groups as follows:

    Host: cluster1 .......................................................................................... Disk group: 9iRac
    Host: cluster2 .......................................................................................... Disk group: 9iRac

Note: If 'nodg' is displayed, then the host will be configured to have no default disk group.

Is this correct? [y,n,q] (y)

    Setting default diskgroup to 9iRac on cluster1 ....................................................................... Done
    Setting default diskgroup to 9iRac on cluster2 ....................................................................... Done

Preparing to start daemons on target systems...
    Starting vxcached on cluster1 ..................................................................................... Success
    Starting vxcached on cluster2 ..................................................................................... Success

Storage Foundation for Oracle RAC was started successfully.

Press [Return] to continue:

                                 VERITAS STORAGE FOUNDATION FOR ORACLE RAC 4.0 INSTALLATION PROGRAM

Installation of Storage Foundation for Oracle RAC 4.0 has completed successfully.

The installation summary is saved at:

        /opt/VRTS/install/logs/installer902153656.summary

The installer log is saved at:

        /opt/VRTS/install/logs/installer902153656.log

The installation response file is saved at:

        /opt/VRTS/install/logs/installer902153656.response

#

至此安装完成

下面是安装管理GUI的过程

# ./installer

                                                 VERITAS Cluster File Solutions 4.0

Copyright (c) 2004 VERITAS Software Corporation. All rights reserved.

VERITAS, the VERITAS Logo and all other VERITAS product names and slogans are trademarks or registered trademarks of VERITAS
Software Corporation. VERITAS and the VERITAS Logo Reg. U.S. Pat. & Tm. Off. Other product names and/or slogans mentioned herein
may be trademarks or registered trademarks of their respective companies.

                                                 VERITAS Cluster File Solutions 4.0

VERITAS Product                             Version Installed   Licensed
===========================================================================
Storage Foundation for Cluster File System        4.0             yes
Storage Foundation for Oracle RAC                 4.0             yes
Enterprise Administrator GUI                      3.2.514.0

Selection Menu:

    I) Install/Upgrade a Product    C) Configure an Installed Product
    L) License a Product            P) Perform a Preinstallation Check
    U) Uninstall a Product          D) View a Product Description
    Q) Quit                         ?) Help

Enter a Selection: [I,C,L,P,U,D,Q,?] I

                                                 VERITAS Cluster File Solutions 4.0

     1)  VERITAS Storage Foundation for Cluster File System
     2)  VERITAS Storage Foundation for Oracle RAC
     3)  VERITAS Enterprise Administrator GUI
     B)    Back to previous menu

Select a product to install: [1-3,b,q] 3

                                   VERITAS ENTERPRISE ADMINISTRATOR GUI 4.0 INSTALLATION PROGRAM

Copyright (c) 2004 VERITAS Software Corporation. All rights reserved.

VERITAS, the VERITAS Logo and all other VERITAS product names and slogans are trademarks or registered trademarks of VERITAS
Software Corporation. VERITAS and the VERITAS Logo Reg. U.S. Pat. & Tm. Off. Other product names and/or slogans mentioned herein
may be trademarks or registered trademarks of their respective companies.

Enter the system names separated by spaces on which to install VEA GUI: cluster1 cluster2

Checking system communication:

    Checking OS version on cluster1 ................................................................................. SunOS 5.9
    Checking VRTSobgui package .................................................................... version 3.2.514.0 installed
    Verifying communication with cluster2 ..................................................................... ping successful
    Attempting rsh with cluster2 ............................................................................... rsh successful
    Attempting rcp with cluster2 ............................................................................... rcp successful
    Checking OS version on cluster2 ................................................................................. SunOS 5.9
    Checking VRTSobgui package .................................................................... version 3.2.514.0 installed
    Creating log directory on cluster2 ................................................................................... Done

Logs for installer are being created in /var/tmp/installer902160337.

Using /usr/bin/rsh and /usr/bin/rcp to communicate with remote systems.

Initial system check completed successfully.

Press [Return] to continue:

                                   VERITAS ENTERPRISE ADMINISTRATOR GUI 4.0 INSTALLATION PROGRAM

Checking system installation requirements:

Checking VEA GUI installation requirements on cluster1:

    Checking VRTScpi package .......................................................................... version 4.0.5 installed
    Checking VRTSobgui package .................................................................... version 3.2.514.0 installed
    Checking VERITAS patch 115210 ......................................................................... 115210-05 installed
    Checking for any Solaris patch issues ................................................................................ None

Checking VEA GUI installation requirements on cluster2:

    Checking VRTScpi package .......................................................................... version 4.0.5 installed
    Checking VRTSobgui package .................................................................... version 3.2.514.0 installed
    Checking VERITAS patch 115210 ......................................................................... 115210-05 installed
    Checking for any Solaris patch issues ................................................................................ None

Installation requirement checks completed successfully.

Press [Return] to continue:

                                   VERITAS ENTERPRISE ADMINISTRATOR GUI 4.0 INSTALLATION PROGRAM

                                   VERITAS ENTERPRISE ADMINISTRATOR GUI 4.0 INSTALLATION PROGRAM

VEA GUI packages can be installed on systems consecutively or simultaneously. Installing packages on systems consecutively takes
more time but allows for better error handling.

Would you like to install Enterprise Administrator GUI packages on all systems simultaneously? [y,n,q,?] (y)

Installing Enterprise Administrator GUI 4.0 on all systems simultaneously:

All VEA GUI packages are already installed.
The installer log is saved at:

        /opt/VRTS/install/logs/installer902160337.log

#

# reboot
Sep  2 16:46:07 cluster1 reboot: rebooted by root
Sep  2 16:46:07 cluster1 gab: GAB INFO V-15-1-20032 Port h closed
Sep  2 16:46:07 /usr/lib/snmp/snmpdx: received signal 15
Sep  2 16:46:07 rpcbind: rpcbind terminating on signal.
Sep  2 16:46:07 EV_AGENT[285]: Signal TERM received
Sep  2 16:46:07 cluster1 syslogd: going down on signal 15
syncing file systems... done
rebooting...

SC Alert: Host System has Reset

Sun Fire V210, No Keyboard
Copyright 1998-2002 Sun Microsystems, Inc.  All rights reserved.
OpenBoot 4.8.2, 4096 MB memory installed, Serial #54274573.
Ethernet address 0:3:ba:3c:2a:d, Host ID: 833c2a0d.

Rebooting with command: boot
Boot device: disk  File and args:
SunOS Release 5.9 Version Generic_117171-07 64-bit
Copyright 1983-2003 Sun Microsystems, Inc.  All rights reserved.
Use is subject to license terms.
NOTICE:
Emulex LightPulse FC SCSI/IP 6.01c
NOTICE: lpfc0: Firmware Rev 3.90A7 (C2D3.90A7)
NOTICE: lpfc0: WWPN:10:00:00:00:c9:3d:cf:d3 WWNN:20:00:00:00:c9:3d:cf:d3 DID 0x10a00
WARNING: /pci@1d,700000/fibre-channel@1/sd@0,0 (sd30):
        Corrupt label; wrong magic number

Hardware watchdog enabled
Error: All paths to 6006016028A61000C2BDC4C591D4D811 are dead.
Error: 6006016028A61000C2BDC4C591D4D811 is dead.
Error: All paths to 6006016028A610009A75213E91D4D811 are dead.
Error: 6006016028A610009A75213E91D4D811 is dead.
Error: All paths to 6006016028A61000F42A89D591D4D811 are dead.
Error: 6006016028A61000F42A89D591D4D811 is dead.
Error: All paths to 6006016028A61000F075BD4E93D4D811 are dead.
Error: 6006016028A61000F075BD4E93D4D811 is dead.
Error: All paths to 60060160D2A91000AE22B826A6DED811 are dead.
Error: 60060160D2A91000AE22B826A6DED811 is dead.
Error: All paths to 6006016028A610005035CED392D4D811 are dead.
Error: 6006016028A610005035CED392D4D811 is dead.
Error: All paths to 6006016028A61000C65024C992D4D811 are dead.
Error: 6006016028A61000C65024C992D4D811 is dead.
VxVM sysboot INFO V-5-2-3244 Starting restore daemon...
VxVM sysboot INFO V-5-2-3445 starting in boot mode...
NOTICE: VxVM vxdmp V-5-0-34 added disk array DISKS, datype = Disk

configuring IPv4 interfaces: bge0ifconfig: setifflags: SIOCSLIFFLAGS: lpfc0: Cannot assign requested address
 lpfc0.
Setting netmask of lpfc0 to 255.255.255.0
ifconfig: setifflags: SIOCSLIFFLAGS: lpfc0: Cannot assign requested address
Hostname: cluster1
Configuring /dev and /devices
LLT INFO V-14-1-10009 LLT Protocol available
GAB INFO V-15-1-20021 GAB available
LMX Multiplexor available
Configuring the /dev directory (compatibility devices)
Setting up paths
VxVM vxvm-startup2 INFO V-5-2-503 VxVM general startup...
The system is coming up.  Please wait.
checking ufs filesystems
/dev/rdsk/c0t0d0s5: is logging.
/dev/rdsk/c0t0d0s7: is logging.
Starting LLT...
Starting LLT done.
Starting LMX
starting rpc services: rpcbind done.
Setting netmask of bge0 to 255.255.255.0
Setting default IPv4 interface for multicast: add net 224.0/4: gateway cluster1
syslog service starting.
Starting Navisphere Agent
Starting GAB...
Sep  2 16:48:45 cluster1 gab: GAB INFO V-15-1-20026 Port a registration waiting for seed port membership
Starting GAB done.
Starting ODM...
Sep  2 16:48:46 cluster1 llt: LLT INFO V-14-1-10024 link 1 (bge2) node 1 active
Sep  2 16:48:46 cluster1 llt: LLT INFO V-14-1-10024 link 0 (bge1) node 1 active
Sep  2 16:48:46 cluster1 gab: GAB INFO V-15-1-20026 Port d registration waiting for seed port membership
Starting vxfen..
Starting vxfen.. Done
Starting VCSMM
Sep  2 16:48:48 cluster1 gab: GAB INFO V-15-1-20026 Port o registration waiting for seed port membership
VCS FEN vxfenconfig NOTICE Driver will be disabled.
Sep  2 16:48:48 cluster1 gab: GAB INFO V-15-1-20026 Port b registration waiting for seed port membership
Sep  2 16:48:50 cluster1 gab: GAB INFO V-15-1-20036 Port d gen   2a9201 membership 01
Sep  2 16:48:50 cluster1 gab: GAB INFO V-15-1-20036 Port a gen   2a9202 membership 01
volume management starting.
The system is ready.

cluster1 console login: Sep  2 16:48:55 cluster1 gab: GAB INFO V-15-1-20036 Port o gen   2a9204 membership 01
Sep  2 16:48:55 cluster1 gab: GAB INFO V-15-1-20036 Port b gen   2a9205 membership 01
Sep  2 16:48:55 cluster1 vcsmm: VCS RAC INFO V-10-1-15047 plat_reconfig_ioctl: dev_ioctl failed, vxfen may not be configured
Sep  2 16:48:55 cluster1 vxfen: NOTICE: VCS FEN INFO V-11-1-35 Fencing driver going into RUNNING state
VCS NOTICE V-16-1-10619 'HAD' starting on: cluster1
VCS NOTICE V-16-1-10620 Waiting for local cluster configuration status
VCS NOTICE V-16-1-10625 Local cluster configuration valid
VCS NOTICE V-16-1-11034 Registering for cluster membership
VCS NOTICE V-16-1-11035 Waiting for cluster membership
Sep  2 16:49:03 cluster1 gab: GAB INFO V-15-1-20036 Port h gen   2a9205 membership 01
VCS INFO V-16-1-10077 Received new cluster membership
VCS NOTICE V-16-1-10082 System (cluster1) is in Regular Membership - Membership: 0x3
VCS NOTICE V-16-1-10082 System () is in Regular Membership - Membership: 0x3
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS ERROR V-16-1-50129 Operation 'hares -modify' rejected as the node is in CURRENT_DISCOVER_WAIT state
VCS NOTICE V-16-1-10075 Building from remote system
VCS NOTICE V-16-1-10066 Entering RUNNING state
Sep  2 16:49:07 cluster1 vxfen: NOTICE: VCS FEN INFO V-11-1-34 The ioctl VXFEN_IOC_CLUSTSTAT returned 0
Sep  2 16:49:11 cluster1 gab: GAB INFO V-15-1-20036 Port u gen   2a9207 membership 01
Sep  2 16:49:11 cluster1 gab: GAB INFO V-15-1-20032 Port u closed
Sep  2 16:49:11 cluster1 vxio: WARNING: VxVM vxio V-5-0-360 volcvm_vxnodeid_daemon:cluster join failed: error 11
Sep  2 16:49:17 cluster1 vxfen: NOTICE: VCS FEN INFO V-11-1-34 The ioctl VXFEN_IOC_CLUSTSTAT returned 0
Sep  2 16:49:25 cluster1 gab: GAB INFO V-15-1-20036 Port u gen   2a9209 membership 0
Sep  2 16:49:25 cluster1 gab: GAB INFO V-15-1-20038 Port u gen   2a9209 k_jeopardy ;1
Sep  2 16:49:25 cluster1 gab: GAB INFO V-15-1-20040 Port u gen   2a9209    visible ;1
Sep  2 16:49:30 cluster1 gab: GAB INFO V-15-1-20036 Port v gen   2a920a membership 01
Sep  2 16:49:35 cluster1 gab: GAB INFO V-15-1-20036 Port w gen   2a920c membership 01
Sep  2 16:49:36 cluster1 gab: GAB INFO V-15-1-20032 Port u closed
Sep  2 16:49:44 cluster1 gab: GAB INFO V-15-1-20036 Port q gen   2a920e membership 01
Sep  2 16:49:46 cluster1 gab: GAB INFO V-15-1-20036 Port f gen   2a9210 membership 01

cluster1 console login:


EMC Navisphere AGENT(NAVIAGENT) 安装日志 -www.eygle.com

EMC Navisphere AGENT(NAVIAGENT) 安装日志

Saturday, 2004-08-28 12:33 Eygle

在连接EMC阵列的主机上需要安装Agent，安装后重起，EMC阵列才能发现主机.

安装日志如下:

# pkgadd -d NAVIAGNT.pkg

The following packages are available:
1 NAVIAGENT Navisphere Disk Array Management Tool (AGENT)
(sparc) 6.6.0.3.8
2 NAVICLI Navisphere Disk Array Management Tool (CLI)
(sparc) 6.6.0.3.8

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]:

Processing package instance <NAVIAGENT> from </export/home/soft/NAVIAGNT.pkg>

Navisphere Disk Array Management Tool (AGENT)
(sparc) 6.6.0.3.8

Copyright (C) 2003, EMC Corporation.

Using </opt> as the package base directory.
## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.

The following files are already installed on the system and are being
used by another package:
/etc/init.d <attribute change only>
/etc/rc0.d <attribute change only>
/etc/rc2.d <attribute change only>

Do you want to install these conflicting files [y,n,?,q]
ERROR: Input is required.

Do you want to install these conflicting files [y,n,?,q] y
## Checking for setuid/setgid programs.

This package contains scripts which will be executed with super-user
permission during the process of installing this package.

Do you want to continue with the installation of <NAVIAGENT> [y,n,?] y

Installing Navisphere Disk Array Management Tool (AGENT) as <NAVIAGENT>

## Installing part 1 of 1.
/etc/Navisphere/agent.config <symbolic link>
/etc/init.d/agent
/etc/rc0.d/K40agent <symbolic link>
/etc/rc2.d/S80agent <symbolic link>
/opt/Navisphere/bin/agent.config
/opt/Navisphere/bin/clsendtrap
/opt/Navisphere/bin/naviagent
/opt/Navisphere/bin/naviagent.postinstall
[ verifying class <none> ]
## Executing postinstall script.

No saved config files exist for Navisphere Agent.

Installation of <NAVIAGENT> was successful.

Processing package instance <NAVICLI> from </export/home/soft/NAVIAGNT.pkg>

Navisphere Disk Array Management Tool (CLI)
(sparc) 6.6.0.3.8

Copyright (C) 2003, EMC Corporation.

Using </opt> as the package base directory.
## Processing package information.
## Processing system information.
2 package pathnames are already properly installed.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.

Installing Navisphere Disk Array Management Tool (CLI) as <NAVICLI>

## Installing part 1 of 1.
/opt/Navisphere/bin/archivedump.jar
/opt/Navisphere/bin/archiveretrieve.jar
/opt/Navisphere/bin/max_script.sh
/opt/Navisphere/bin/navicli
/opt/Navisphere/bin/navicli.jar
/opt/Navisphere/man/cat1/navicli.1
[ verifying class <none> ]

Installation of <NAVICLI> was successful.


Emulex LightPulse FC9002L光纤卡安装日志-www.eygle.com

Emulex LightPulse FC9002L光纤卡安装日志

Saturday, 2004-08-28 12:33 Eygle

光盘上的驱动程序在Solaris9上安装有问题,重新启动后系统不停重起,无法up

可以到官方网站下载新的驱动,安装即可.

# tar xvf solaris-6.01c-1a.tar
x EmlxApps300a8-Solaris.tar, 6850560 bytes, 13380 tape blocks
x lpfc-6.01c-sparc.tar, 1848832 bytes, 3611 tape blocks
x readme.first.txt, 953 bytes, 2 tape blocks
# ls
EmlxApps300a8-Solaris.tar  readme.first.txt           ssh-UdjGS369
lpfc-6.01c-sparc.tar       solaris-6.01c-1a.tar
# tar xvf lpfc-6.01c-sparc.tar
x lpfc.1, 0 bytes, 0 tape blocks
x lpfc.1/pkgmap, 1814 bytes, 4 tape blocks
x lpfc.1/pkginfo, 276 bytes, 1 tape blocks
x lpfc.1/install, 0 bytes, 0 tape blocks
x lpfc.1/install/copyright, 480 bytes, 1 tape blocks
x lpfc.1/install/postinstall, 9336 bytes, 19 tape blocks
x lpfc.1/install/postremove, 2848 bytes, 6 tape blocks
x lpfc.1/install/preremove, 1620 bytes, 4 tape blocks
x lpfc.1/install/request, 2378 bytes, 5 tape blocks
x lpfc.1/install/space, 23 bytes, 1 tape blocks
x lpfc.1/reloc, 0 bytes, 0 tape blocks
x lpfc.1/reloc/etc, 0 bytes, 0 tape blocks
x lpfc.1/reloc/etc/system, 0 bytes, 0 tape blocks
x lpfc.1/reloc/kernel, 0 bytes, 0 tape blocks
x lpfc.1/reloc/kernel/drv, 0 bytes, 0 tape blocks
x lpfc.1/reloc/kernel/drv/lpfc, 592692 bytes, 1158 tape blocks
x lpfc.1/reloc/kernel/drv/lpfc.conf, 10863 bytes, 22 tape blocks
x lpfc.1/reloc/kernel/drv/sd.conf, 1185 bytes, 3 tape blocks
x lpfc.1/reloc/kernel/drv/sparcv9, 0 bytes, 0 tape blocks
x lpfc.1/reloc/kernel/drv/sparcv9/lpfc, 719064 bytes, 1405 tape blocks
x lpfc.1/reloc/usr, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/include, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/include/fcdiag.h, 18051 bytes, 36 tape blocks
x lpfc.1/reloc/usr/lib, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/lib/libdfc.a, 43820 bytes, 86 tape blocks
x lpfc.1/reloc/usr/lib/libdfc.so, 42000 bytes, 83 tape blocks
x lpfc.1/reloc/usr/lib/sparcv9, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/lib/sparcv9/libdfc.a, 47936 bytes, 94 tape blocks
x lpfc.1/reloc/usr/lib/sparcv9/libdfc.so, 51248 bytes, 101 tape blocks
x lpfc.1/reloc/usr/sbin, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/sbin/lpfc, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/sbin/lpfc/convert_path_lpfc, 2257 bytes, 5 tape blocks
x lpfc.1/reloc/usr/sbin/lpfc/dfc, 1050 bytes, 3 tape blocks
x lpfc.1/reloc/usr/sbin/lpfc/dfc32, 118520 bytes, 232 tape blocks
x lpfc.1/reloc/usr/sbin/lpfc/dfc64, 120944 bytes, 237 tape blocks
x lpfc.1/reloc/usr/sbin/lpfc/resetqdepth, 1027 bytes, 3 tape blocks
x lpfc.1/reloc/usr/share, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/share/man, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/share/man/man7d, 0 bytes, 0 tape blocks
x lpfc.1/reloc/usr/share/man/man7d/lpfc.7d, 30587 bytes, 60 tape blocks
# ls
EmlxApps300a8-Solaris.tar  lpfc.1                     solaris-6.01c-1a.tar
lpfc-6.01c-sparc.tar       readme.first.txt           ssh-UdjGS369
# pkgadd -d /tmp

The following packages are available:
  1  lpfc.1     Emulex LightPulse FC SCSI/IP Host Bus Adapter driver
                (sun4u) Release 6.01c

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]:

Processing package instance  from

Emulex LightPulse FC SCSI/IP Host Bus Adapter driver
(sun4u) Release 6.01c

                    lpfc FC SCSI/IP driver

            Copyright (c) 2004, Emulex Corporation
            3333 Susan Street, Costa Mesa, CA  92626

All rights reserved.  This product and related documentation is
protected by copyright and distributed under licenses restricting
its use, copying, distribution and decompilation.  No part of this
product or related documentation may be reproduced in any form by
any means without prior written authorization of Emulex Corporation
and its licensors, if any.

CAUTION:  The lpfc driver will not work with any release of Solaris/SunOS
earlier than 2.6/5.6.  However, even for later releases, lpfc may
have to be compiled specifically for that release of Solaris.  This
version of lpfc has been built under Solaris/SunOS  for sun4u.

Rebuild manual pages database for section 7d [y,n,?] y

Use IP networking over Fibre Channel [y,n,?] y

Network hostname (for first adapter) [?,q] cluster2
Using  as the package base directory.
## Processing package information.
## Processing system information.
   11 package pathnames are already properly installed.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.

The following files are already installed on the system and are being
used by another package:
  /usr/share/man/man7d

Do you want to install these conflicting files [y,n,?,q] y
## Checking for setuid/setgid programs.

This package contains scripts which will be executed with super-user
permission during the process of installing this package.

Do you want to continue with the installation of  [y,n,?] y

Installing Emulex LightPulse FC SCSI/IP Host Bus Adapter driver as

## Installing part 1 of 1.
[ verifying class  ]
/usr/share/man/man7d/lpfc.7d
[ verifying class  ]
/kernel/drv/lpfc
/kernel/drv/lpfc.conf
/kernel/drv/sparcv9/lpfc
[ verifying class  ]
/usr/include/fcdiag.h
/usr/lib/libdfc.a
/usr/lib/libdfc.so
/usr/lib/sparcv9/libdfc.a
/usr/lib/sparcv9/libdfc.so
/usr/sbin/lpfc/convert_path_lpfc
/usr/sbin/lpfc/dfc
/usr/sbin/lpfc/dfc32
/usr/sbin/lpfc/dfc64
/usr/sbin/lpfc/resetqdepth
[ verifying class  ]
Modifying /etc/system
Modifying /kernel/drv/sd.conf
[ verifying class  ]
## Executing postinstall script.
Updating /kernel/drv/lpfc.conf
Updating /etc/system (moddir)

Configuring /etc/hostname.lpfc0 as cluster2
catman -M //usr/share/man -w 7d
This may take a while ...
Driver lpfc added to system.

************
IMPORTANT:  You must reboot the system to start this driver.
SCSI:       If you are using lpfc to access disks, be sure to
            check the configuration file of your SCSI target driver
            (presumably sd.conf) to ensure that the driver will
            probe for all of the targets/luns in your environment.
NETWORK:    The first adapter IP network interface
            /etc/hostname.lpfc0
            has been set up with the hostname cluster2.
            To configure additional Lightpulse adapters, simply
            create additional files
            /etc/hostname.lpfc[1-n]
            each containing the name of this host from the
            standpoint of that adapter's network.
ALL:        Examine the contents of /kernel/drv/lpfc.conf
            for driver-specific variables and behavior.
************

Installation of  was successful.

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: q

*** IMPORTANT NOTICE ***
        This machine must now be rebooted in order to ensure
        sane operation.  Execute
               shutdown -y -i6 -g0
        and wait for the "Console Login:" prompt.


Emulex光纤卡lpfc配置文件的修改 -www.eygle.com

Emulex光纤卡lpfc配置文件的修改

Saturday, 2004-08-28 12:40 Eygle

光纤卡安装以后,需要修改两个配置文件,分别为:

/kernel/drv/sd.conf

/kernel/drv/lpfc.conf

修改内容在以下过程中标注:

# cd /kernel/drv
# vi sd.conf
"sd.conf" 65 lines, 1611 characters
#
# Copyright (c) 1992, by Sun Microsystems, Inc.
#
#ident "@(#)sd.conf 1.9 98/01/11 SMI"

name="sd" class="scsi" class_prop="atapi"
target=0
lun=0;

name="sd" class="scsi" class_prop="atapi"
target=1
lun=0;

name="sd" class="scsi" class_prop="atapi"
target=2
lun=0;

name="sd" class="scsi" class_prop="atapi"
target=3
lun=0;

name="sd" class="scsi"
target=4 lun=0;

name="sd" class="scsi"
target=5 lun=0;

name="sd" class="scsi"
target=6 lun=0;

name="sd" class="scsi"
target=8 lun=0;

name="sd" class="scsi"
target=9 lun=0;

name="sd" class="scsi"
target=10 lun=0;

name="sd" class="scsi"
target=11 lun=0;

name="sd" class="scsi"
target=12 lun=0;

name="sd" class="scsi"
target=13 lun=0;

name="sd" class="scsi"
target=14 lun=0;

name="sd" class="scsi"
target=15 lun=0;

# Start lpfc auto-generated configuration -- do NOT alter or
              delete this line
# WARNING: anything you put within this
              auto-generated section will
# be DELETED if you execute pkgrm
              to remove the lpfc driver package.
# You may need to add
              additional lines to probe for additional LUNs
# or targets. You
              SHOULD delete any lines that represent lpfc targets
# or LUNs
              that are not used.
# You should add any new entries between
              this line
# and the End lpfc auto generated configuration
              line
# name="sd" parent="lpfc" target=16 lun=0;
# name="sd"
              parent="lpfc" target=17 lun=0;
# A small number of LUNs for a
              RAID array
# name="sd" parent="lpfc" target=17 lun=1;
#
              name="sd" parent="lpfc" target=17 lun=2;
# name="sd"
              parent="lpfc" target=17 lun=3;
name="sd"
              parent="lpfc" target=0 lun=0;
name="sd" parent="lpfc" target=0
              lun=1;
name="sd" parent="lpfc" target=0 lun=2;
name="sd"
              parent="lpfc" target=0 lun=3;
name="sd" parent="lpfc" target=0
              lun=4;
name="sd" parent="lpfc" target=0 lun=5;
name="sd"
              parent="lpfc" target=0 lun=6;
name="sd" parent="lpfc" target=0
              lun=7;
name="sd" parent="lpfc" target=1 lun=0;
name="sd"
              parent="lpfc" target=1 lun=1;
name="sd" parent="lpfc" target=1
              lun=2;
name="sd" parent="lpfc" target=1 lun=3;
name="sd"
              parent="lpfc" target=1 lun=4;
name="sd" parent="lpfc" target=1
              lun=5;
name="sd" parent="lpfc" target=1 lun=6;
name="sd"
              parent="lpfc" target=1 lun=7;
name="sd" parent="lpfc" target=2
              lun=0;
name="sd" parent="lpfc" target=3 lun=0;
name="sd"
              parent="lpfc" target=4 lun=0;
name="sd" parent="lpfc" target=5
              lun=0;
name="sd" parent="lpfc" target=6 lun=0;
name="sd"
              parent="lpfc" target=7 lun=0;
name="sd" parent="lpfc" target=8
              lun=0;
name="sd" parent="lpfc" target=9 lun=0;
name="sd"
              parent="lpfc" target=10 lun=0;
name="sd" parent="lpfc"
              target=11 lun=0;
name="sd" parent="lpfc" target=12
              lun=0;
name="sd" parent="lpfc" target=13 lun=0;
name="sd"
              parent="lpfc" target=14 lun=0;
name="sd" parent="lpfc"
              target=15 lun=0;
name="sd" parent="lpfc" target=16
              lun=0;
name="sd" parent="lpfc" target=17 lun=0;
name="sd"
              parent="lpfc" target=17 lun=1;
name="sd" parent="lpfc"
              target=17 lun=2;
name="sd" parent="lpfc" target=17
              lun=3;

--增加部分
"sd.conf" 100 lines, 3022 characters
# vi lpfc.conf
"lpfc.conf" 276 lines, 10863 characters
#
# COPYRIGHT 2004, EMULEX CORPORATION
# 3333 Susan Street, Costa Mesa, CA 92626
#
# All rights reserved. This computer program and related documentation
# is protected by copyright and distributed under licenses restricting
# its use, copying, distribution and decompilation. This computer
# program and its documentation are CONFIDENTIAL and a TRADE SECRET
# of EMULEX CORPORATION. The receipt or possession of this program
# or its documentation does not convey rights to reproduce or disclose
# its contents, or to manufacture, use, or sell anything that it may
# describe, in whole or in part, without the specific written consent
# of EMULEX CORPORATION. Any reproduction of this program without
# the express written consent of EMULEX CORPORATION is a violation
# of the copyright laws and may subject you to criminal prosecution.
#
#
# Solaris LightPulse lpfc (SCSI) / lpfn (IP) driver: global initialized data.
#
# lpfc.conf 1.26 2004/03/15 11:41:22PST

# Verbosity: only turn this flag on if you are willing to risk being
# deluged with LOTS of information.
# You can set a bit mask to record specific types of verbose messages:
#
# 0x1 ELS events
# 0x2 Device Discovery events
# 0x4 Mailbox Command events
# 0x8 Initialization events
# 0x10 Link Attention events
# 0x20 IP events
# 0x40 FCP events
# 0x80 Node table events
# 0x400 Miscellaneous events
# 0x800 SLI events
# 0x2000 IOCtl events
# 0xffff Log All Events
log-verbose=0x0;

# Setting log-only to 0 causes log messages to be printed on the
# console and to be logged to syslog (which may send them to the
# console again if it's configured to do so).
# Setting log-only to 1 causes log messages to go to syslog only.
log-only=1;

#
# +++ Variables relating to FCP (SCSI) support. +++
#
/top
# If set, nodev-holdio will hold all I/O errors on devices that disappear
# until they come back. Default is 0, return errors with no-device-delay.
nodev-holdio=0;

# If set, nodev-tmo will hold all I/O errors on devices that disappear
# until the timer [0 to 255 secs] expires. Default is 30, return errors
# with no-device-delay.
nodev-tmo=30;

# Use no-device-delay to delay FCP RSP errors and certain check conditions.
delay-rsp-err=0;

# Treat certain check conditions as an FCP error.
check-cond-err=0;

# num-iocbs [128 to 10240] - number of iocb buffers to allocate
num-iocbs=256;

# num-bufs [64 to 4096] - number of buffers to allocate
# Buffers are needed to support Fibre channel Extended Link Services.
# Also used for SLI-2 FCP buffers, one per FCP command, and Mailbox commands.
num-bufs=128;

# topology: link topology for initializing the Fibre Channel connection.
# 0 = attempt loop mode, if it fails attempt point-to-point mode
# 2 = attempt point-to-point mode only
# 4 = attempt loop mode only
# 6 = attempt point-to-point mode, if it fails attempt loop mode
# Set point-to-point mode if you want to run as an N_Port.
# Set loop mode if you want to run as an NL_Port.
topology=2;

--由0更改为2

# Set a preferred ALPA for the adapter, only valid if topology is loop.
# lpfc0-assign-alpa=2; Request ALPA 2 for lpfc0

# ip-class: FC class (2 or 3) to use for the IP protocol.
ip-class=3;

# fcp-class: FC class (2 or 3) to use for the FCP protocol.
fcp-class=3;

# Use ADISC for FCP rediscovery instead of PLOGI.
use-adisc=0;

# Extra IO timeout [0 to 255 secs] for fabrics
extra-io-tmo=0;

# Number of 4k STREAMS buffers [64 to 1024] to post to IP ring.
"lpfc.conf" 276 lines, 10863 characters
# reboot

修改配置文件后,重起主机生效

#reboot -- -r

注意这里需要使用-r选项,使更改生效.


分配磁盘组(EMC阵列)-www.eygle.com

分配磁盘组(EMC阵列)

Saturday, 2004-08-28 12:41 Eygle

当前系统状态,可以看到lpfc启用IP功能的地址:

# ifconfig -a
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
bge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 172.16.33.70 netmask ffffff00 broadcast 172.16.33.255
ether 0:3:ba:3c:2a:d
lpfc0: flags=1000842<BROADCAST,RUNNING,MULTICAST,IPv4> mtu 65280 index 3
inet 172.16.33.70 netmask ffffff00 broadcast 172.16.33.255
ether 0:0:c9:3d:cf:d3

在EMC中给主机分配磁盘组,此时可以看到共享磁盘,如果安装PowerPath,可以看到双路通道(本例未安装PowerPath Client):

# format
Searching for disks...done

AVAILABLE DISK SELECTIONS:
0. c0t0d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107>
/pci@1c,600000/scsi@2/sd@0,0
1. c0t1d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107>
/pci@1c,600000/scsi@2/sd@1,0
2. c2t0d0 <DGC-RAID5-0206 cyl 61438 alt 2 hd 256 sec 20>
/pci@1d,700000/fibre-channel@1/sd@0,0
3. c2t1d0 <drive type unknown>
/pci@1d,700000/fibre-channel@1/sd@1,0
Specify disk (enter its number): 2
selecting c2t0d0
[disk formatted]

FORMAT MENU:
disk - select a disk
type - select (define) a disk type
partition - select (define) a partition table
current - describe the current disk
format - format and analyze the disk
repair - repair a defective sector
label - write label to the disk
analyze - surface analysis
defect - defect list management
backup - search for backup labels
verify - read and display labels
save - save new disk/partition definitions
inquiry - show vendor, product and revision
volname - set 8-character volume name
!<cmd> - execute <cmd>, then return
quit
format> q
#


Statspack之一-Statspack简介-www.eygle.com

Statspack之一-Statspack简介

Monday, 2004-10-04 15:48 Eygle

Oracle Statspack 从Oracle8.1.6开始被引入Oracle,并马上成为DBA和Oracle专家用来诊断数据库性能的强有力的工具。

通过Statspack我们可以很容易的确定Oracle数据库的瓶颈所在，记录数据库性能状态，也可以使远程技术支持人员迅速了解你的数据库运行状况。
因此了解和使用Statspack对于DBA来说至关重要。

在数据库中Statspack的脚本位于$ORACLE_HOME/RDBMS/ADMIN目录下，对于ORACLE8.1.6,是一组以stat开头的文件；
对于ORACLE8.1.7,是一组以sp开头的文件。

在Oracle8.1.6中，Statspack第一次发布，但是你也可以在以下链接找到可用于Oracle80~Oracle8.1.5的版本。

http://www.oracle.com/oramag/oracle/00-Mar/index.html?o20tun.html
http://www.oracle.com/oramag/oracle/00-Mar/index.html?statspack-other.html
http://www.oracle.com/oramag/oracle/00-Mar/index.html?statspack.tar

如果以上链接失效,你可以在本地下载支持80~815版本.

在816以前的版本使用Statspack，你需要使用statscbps.sql脚本建立一个v$buffer_pool_statistics视图，该脚本包含在以上链接下载的tar文件中。
访问该链接，你可能需要一个OTN帐号，申请该帐号是免费的。

在Statspack发布之前，我们通常能够使用诊断数据库的工具是两个脚本UTLBSTAT.SQL和UTLESTAT.SQL，BSTAT/ESTAT是一个非常简单的性能诊断工具。
UTLBSTAT获得开始时很多V$视图的快照，UTLESTAT通过先前的快照和当前视图生成一个报表。 该报表实际上相当于statspack中的两个采样点。

Statspack通过连续的采样，能够给我们提供至关重要的趋势分析数据。这是一个巨大的进步。
能够使用Statspack的环境我们就尽量不要使用BSTAT/ESTAT的方式来诊断数据库问题。

下面我们来讲一讲Statspack的安装，配置，使用和解读，通过这篇文章，

我们希望至少可以使每个使用Oracle数据库的人，都可以学会怎样生成Statspack Report.


Statspack之二-系统参数-eygle.com

Statspack之二-需要更改的系统参数

为了能够顺利安装和运行Statspack你可能需要设置以下系统参数：

    • job_queue_processes

为了能够建立自动任务，执行数据收集，该参数需要大于0。你可以在初试化参数文件中修改该参数(使该参数在重起后以然有效)。

该参数可以在系统级动态修改(重起后失效)。

SQL> alter system set job_queue_processes = 6;

System altered

在Oracle9i当中，可以指定范围，如 both,这样该修改在当前及之后保持有效(仅当你使用spfile时，如果在9i中仍然使用pfile，
那么更改方法同8i相同):

SQL> alter system set job_queue_processes = 6 scope=both;

系统已更改。

    • timed_statistics

收集操作系统的计时信息，这些信息可被用来显示时间等统计信息、优化数据库和 SQL 语句。要防止因从操作系统请求时间而引
起的开销，请将该值设置为False。

使用statspack收集统计信息时建议将该值设置为 TRUE，否则收集的统计信息大约只能起到10%的作用，将timed_statistics
设置为True所带来的性能影响与好处相比是微不足道的。

该参数使收集的时间信息存储在在V$SESSTATS和V$SYSSTATS等动态性能视图中。

Timed_statistics参数可以在实例级进行更改

SQL> alter system set timed_statistics = true;

System altered

SQL>

如果你担心一致启用timed_statistics 对于性能的影响，你可以在使用statspack之前在system更改，采样过后把该参数动
态修改成false。

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之三-安装statspack-eygle.com

Statspack之三-安装statspack

安装Statspack需要用internal身份登陆，或者拥有SYSDBA(connect / as sysdba)权限的用户登陆。
需要在本地安装或者通过telnet登陆到服务器。

在Oracle8.1.6版本中运行statscre.sql;在Oracle8.1.7版本中运行spcreate.sql。

首先登陆到数据库，最好转到$ORACLE_HOME/RDBMS/ADMIN目录，这样我们执行脚本就可以方便些。

D:\oracle\ora81\RDBMS\ADMIN>sqlplus internal

SQL*Plus: Release 8.1.7.0.0 - Production on 星期二 12月 3 16:54:53 2002

(c) Copyright 2000 Oracle Corporation.All rights reserved.

请输入口令:

连接到:

Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production

With the Partitioning option

JServer Release 8.1.7.0.0 - Production

SQL> select instance_name,host_name,version,startup_time from v$instance;

INSTANCE_NAMEHOST_NAME VERSIONSTARTUP_TIME

----------------------------------------------------------------

eygleAM-SERVER 8.1.7.0.022-11月-02

SQL>

注:在Oracle9i中，不存在internal用户，可以使用sys用户以sysdba身份连接:

D:\oracle\ora92\rdbms\admin>sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on 星期四 7月 10 19:18:54 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

连接到: Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production

With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options

JServer Release 9.2.0.3.0 - Production

SQL>

检查数据文件路径及磁盘空间，以决定创建数据文件的位置：

SQL> select file_name from dba_data_files;

FILE_NAME

--------------------------------------------------------------------------------

D:\ORACLE\ORADATA\EYGLE\SYSTEM01.DBF

D:\ORACLE\ORADATA\EYGLE\TEMP01.DBF

……

D:\ORACLE\ORADATA\EYGLE\HH_AM01.ORA

已选择24行。

SQL>

创建存储数据的表空间，如果采样间隔较短，周期较长，打算长期使用，那么你可能需要一个大一点的表空间，
如果每个半个小时采样一次，连续采样一周，数据量是很大的。本例创建一个500M的测试表空间。

注意:这里创建的表空间不能太小，如果太小创建对象会失败，至少需要建立100M表空间,如果打算
长期使用,可以建立稍大的表空间，本例创建500M LMT表空间。

SQL> create tablespace perfstat

2datafile 'd:\oracle\oradata\eygle\perfstat.dbf'

3size 500M

4extent management local;

表空间已创建。

SQL>

检查是否存在安装所需要的脚本文件(对于不同的版本，脚本有所不同)

E:\Oracle\ora92\rdbms\admin>dir /w sp*

驱动器 E 中的卷没有标签。

卷的序列号是 ACC3-4340

E:\Oracle\ora92\rdbms\admin 的目录

spauto.sqlspcpkg.sqlspcreate.sqlspctab.sqlspcusr.sqlspdoc.txt

spdrop.sqlspdtab.sqlspdusr.sqlsppurge.sqlsprepins.sqlspreport.sql

sprepsql.sqlsptrunc.sqlspuexp.parspup816.sqlspup817.sqlspup90.sql

18 个文件510,296 字节

0 个目录4,146,565,120 可用字节

接下来我们就可以开始安装Statspack了。这期间会提示你输入缺省表空间和临时表空间的位置,输入我们为
perfstat用户创建的表空间和你的临时表空间。

SQL> @spcreate

.

.

Specify PERFSTAT user's defaulttablespace

输入 default_tablespace 的值:perfstat

Using perfstat for the default tablespace

用户已更改。

用户已更改。

Specify PERFSTAT user's temporary tablespace

输入 temporary_tablespace 的值:temp

注意:在statspack创建过程中,当提示输入口令时，你可以输入一个明文口令，但是如果输入口令不符
合规范(如123或以数字开头的口令)，创建会失败。

输入口令时可以暂时输入:perfstat ,稍后可以更改。

... Creating PERFSTAT user ...

Choose the PERFSTAT user's password.

Not specifying a password will result in the installation FAILING

Specify PERFSTAT password

输入 perfstat_password 的值: 123

123

PL/SQL 过程已成功完成。

create user perfstat identified by 123

*

ERROR 位于第 1 行:

ORA-00988: 缺少或无效口令

如果安装成功，你可以看到如下的输出信息：

….

Creating Package STATSPACK...

程序包已创建。

没有错误。

Creating Package Body STATSPACK...

程序包主体已创建。

没有错误。

NOTE:

SPCPKG complete. Please check spcpkg.lis for any errors.

你可以查看.lis文件查看安装时的错误信息。

SQL> host dir *.lis

驱动器 D 中的卷没有标签。

卷的序列号是 5070-5982

D:\oracle\ora81\RDBMS\ADMIN 的目录

2002-12-0317:25204 spcpkg.lis

2002-12-0317:252,276 spctab.lis

2002-12-0317:253,965 spcusr.lis

2002-12-0317:231,187 spdtab.lis

2002-12-0317:24351 spdusr.lis

5 个文件7,983 字节

0 个目录3,965,304,832 可用字节

SQL> host find “ORA-“ *.lis

SQL> host find "err" *.lis

---------- SPAUTO.LIS

---------- SPCPKG.LIS

SPCPKG complete. Please check spcpkg.lis for any errors.

---------- SPCTAB.LIS

SPCTAB complete. Please check spctab.lis for any errors.

---------- SPCUSR.LIS

SPCUSR complete. Please check spcusr.lis for any errors.

---------- SPDTAB.LIS

在UNIX上，你可以通过以下命令查看相应的错误信息

$ ls *.lis

spauto.lisspcpkg.lisspctab.lisspcusr.lisspdtab.lisspdusr.lis

$ grep ORA- *.lis

$ grep err *.lis

spcpkg.lis:SPCPKG complete. Please check spcpkg.lis for any errors.

spctab.lis:SPCTAB complete. Please check spctab.lis for any errors.

spcusr.lis:SPCUSR complete. Please check spcusr.lis for any errors.

spdtab.lis:SPDTAB complete. Please check spdtab.lis for any errors.

spdusr.lis:SPDUSR complete. Please check spdusr.lis for any errors.

在这一步，如果出现错误，那么你可以运行spdrop.sql脚本来删除这些对象。然后重新运行spcreate.sql来创
建这些对象。运行 SQL*Plus, 以具有SYSDBA 权限的用户登陆：

SQL> @spdrop.sql

.

.

.

同义词已丢弃。off;

视图已丢掉。

同义词已丢弃。

视图已丢掉。

同义词已丢弃。

用户已丢弃

NOTE:

SPDUSR complete. Please check spdusr.lis for any errors.

SQL>

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之四-测试安装好的Statspack-eygle.com

Statspack之四-测试安装好的Statspack

运行statspack.snap可以产生系统快照，运行两次，然后执行spreport.sql就可以生成一个基于两个时间点的报告。

如果一切正常，说明安装成功。

SQL>execute statspack.snap

PL/SQL procedure successfully completed.

SQL>execute statspack.snap

PL/SQL procedure successfully completed.

SQL>@spreport.sql

…

可是有可能你会得到以下错误：

SQL> exec statspack.snap;

BEGIN statspack.snap; END;

*

ERROR at line 1:

ORA-01401: inserted value too large for column

ORA-06512: at "PERFSTAT.STATSPACK", line 978

ORA-06512: at "PERFSTAT.STATSPACK", line 1612

ORA-06512: at "PERFSTAT.STATSPACK", line 71

ORA-06512: at line 1

这是Oracle的一个Bug，Bug号1940915。

该Bug自8.1.7.3后修正。

这个问题只会出现在多位的字符集,需要修改spcpkg.sql脚本，$ORACLE_HOME/rdbms/admin/spcpkg.sql，
将"substr" 修改为 "substrb"，然后重新运行该脚本。

该脚本错误部分：

select l_snap_id

, p_dbid

, p_instance_number

, substr(sql_text,1,31)

．．．．．．．．．．．

substr 会将多位的字符, 当作一个byte.substrb 则会当作多个byte。在收集数据时， statpack 会将 top 10
的 sql 前 31 个字节存入数据表中,若在SQL的前31 个字有中文，就会出现此错误。

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之五-规划自动任务-eygle.com

Statspack之五-规划自动任务

Statspack正确安装以后，我们就可以设置定时任务，开始收集数据了。可以使用spatuo.sql来定义自动任务。

先来看看spauto.sql的关键内容：

dbms_job.submit(:jobno, 'statspack.snap;',

trunc(sysdate+1/24,'HH'), 'trunc(SYSDATE+1/24,''HH'')', TRUE, :instno);

这个job任务定义了收集数据的时间间隔：

一天有24个小时，1440分钟，那么：

1/24 | HH每小时一次
1/48 | MI每半小时一次
1/144 | MI每十分钟一次
1/288 | MI每五分钟一次

我们可以修改spauto.sql来更改执行间隔，如：

dbms_job.submit(:jobno, 'statspack.snap;',

trunc(sysdate+1/48,'MI'), 'trunc(SYSDATE+1/48,''MI'')', TRUE, :instno);

然后我们执行spauto，这样我们就建立了一个每30分钟执行一次的数据收集计划。你可以查看spauto.lis来获得输出信息：

SQL> @spauto

PL/SQL procedure successfully completed.

Job number for automated statistics collection for this instance

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that this job number is needed when modifying or removing

the job:

JOBNO

----------

28

Job queue process

~~~~~~~~~~~~~~~~~

Below is the current setting of the job_queue_processes init.ora

parameter - the value for this parameter must be greater

than 0 to use automatic statistics gathering:

NAMETYPEVALUE

------------------------------------ ----------- ------------------------------

job_queue_processesinteger 5

Next scheduled run

~~~~~~~~~~~~~~~~~~

The next scheduled run for this job is:

JOB NEXT_DATE NEXT_SEC

---------- --------- ----------------

28 15-AUG-0316:00:00

关于采样间隔，我们通常建议以1小时为时间间隔，对于有特殊需要的环境，可以设置更短的，如半小时作为采样间隔，
但是不推荐更短。因为statspack的执行本身需要消耗资源，对于繁忙的生产系统，太短的采样对系统的性能会产生较
大的影响（甚至会使statspack的执行出现在采样数据中）。

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之六-生成分析报告-eygle.com

Statspack之六-生成分析报告

调用spreport.sql可以生成分析报告：

SQL> @spreport

DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
1277924236 EYGLE 1 eygle

Completed Snapshots

Snap Snap
Instance DB Name Id Snap Started Level Comment
------------ ------------ ----- ----------------- ----- ----------------------
eygle EYGLE 1 04 12月 2002 14:30 5
eygle EYGLE 2 04 12月 2002 15:00 5

………………

eygle EYGLE 98 05 12月 2002 04:10 5
eygle EYGLE 99 05 12月 2002 04:20 5
eygle EYGLE 100 05 12月 2002 04:30 5

....

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入 begin_snap 的值: 1
Begin Snapshot Id specified: 1

输入 end_snap 的值: 100
End Snapshot Id specified: 100

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sp_1_100. To use this name,
press <return> to continue, otherwise enter an alternative.
输入 report_name 的值: rep1205.txt

Using the report name rep1205.txt

这样就生成了一个报告，可是如果中间停过机，那么你可能收到以下错误信息：

ERROR: Snapshots chosen span an instance shutdown: RESULTS ARE INVALID

STATSPACK report for

DB NameDB IdInstanceInst Num ReleaseOPS Host

------------ ----------- ------------ -------- ----------- --- ------------

EYGLE1277924236 eygle1 8.1.7.0.0NOAM-SERVER

:ela:=;

*

ERROR 位于第 4 行:

ORA-06550: 第 4 行, 第 17 列:

PLS-00103: 出现符号 ";"在需要下列之一时：

(-+modnotnull<an identifier>

<a double-quoted delimited-identifier><a bind variable>avg

countcurrentexistsmaxminpriorsqlstddevsumvarianceexecute

foralltimetimestampintervaldate

<a string literal with character set specification>

<a number><a single-quoted SQL string>

符号 "null" 被替换为 ";" 后继续。

ORA-06550: 第 6 行, 第 16 列:

PLS-00103: 出现符号 ";"在需要下列之一时：

(-+modnotnull<an identifier>

<a double-quoted delimited-identifier><a bind variable>avg

countcurrentexistsmaxminpriorsqlstddevsumvarianceexecute

foralltimetimestampintervaldate

<a stri

一个statspack的报告不能跨越一次停机，但是之前或之后的连续区间，收集的信息依然有效。你可以选择之前或之后的采样声称report。

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之七-移除定时任务-eygle.com

Statspack之七-移除定时任务

移除一个定时任务，可以如下操作:

SQL> select job,log_user,priv_user,last_date,next_date,interval from user_jobs;

JOB LOG_USERLAST_DATENEXT_DATEINTERVAL

---------- ----------------------------------- ------------------------------ -----------

22 PERFSTAT 2002-12-5:14:33:26 2002-12-5 14:43:00 trunc(SYSDATE+1/144,'MI')

SQL> execute dbms_job.remove('22')

PL/SQL procedure successfully completed

当你完成了一个采样报告，你应该及时移除这个job任务，在生产环境中，遗漏一个无人照顾的job是非常危险的，
如果statspack运行一个星期，采样的数据量是非常惊人的。有的生产企业因疏忽而当机！

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之八-删除历史数据-eygle.com

Statspack之八-删除历史数据

删除stats$snapshot数据表中的相应数据，其他表中的数据会相应的级连删除：

SQL> select max(snap_id) from stats$snapshot;

MAX(SNAP_ID)

------------

166

SQL> delete from stats$snapshot where snap_id < = 166;

143 rows deleted

你可以更改snap_id的范围以保留你需要的数据。

在以上删除过程中，你可以看到所有相关的表都被锁定。

SQL> select a.object_id,a.oracle_username ,b.object_name
from v$locked_object a,dba_objects b
where a.object_id = b.object_id
/

OBJECT_ID ORACLE_USERNAMEOBJECT_NAME

------------------------------------- ---------------------------------------------------------

156 PERFSTATSNAP$

39700 PERFSTATSTATS$LIBRARYCACHE

39706 PERFSTATSTATS$ROLLSTAT

39712 PERFSTATSTATS$SGA

39754 PERFSTATSTATS$PARAMETER

39745 PERFSTATSTATS$SQL_STATISTICS

39739 PERFSTATSTATS$SQL_SUMMARY

39736 PERFSTATSTATS$ENQUEUESTAT

39733 PERFSTATSTATS$WAITSTAT

39730 PERFSTATSTATS$BG_EVENT_SUMMARY

39724 PERFSTATSTATS$SYSTEM_EVENT

39718 PERFSTATSTATS$SYSSTAT

39715 PERFSTATSTATS$SGASTAT

39709 PERFSTATSTATS$ROWCACHE_SUMMARY

39703 PERFSTATSTATS$BUFFER_POOL_STATISTICS

39697 PERFSTATSTATS$LATCH_MISSES_SUMMARY

39679 PERFSTATSTATS$SNAPSHOT

39682 PERFSTATSTATS$FILESTATXS

39688 PERFSTATSTATS$LATCH

174 PERFSTATJOB$

20 rows selected

Oracle还提供了系统脚本用于Truncate这些统计信息表，这个脚本名字是: sptrunc.sql (8i、9i都相同)

该脚本主要内容如下，里面看到的就是statspack相关的所有系统表：

truncate table STATS$FILESTATXS;

truncate table STATS$LATCH;

truncate table STATS$LATCH_CHILDREN;

truncate table STATS$LATCH_MISSES_SUMMARY;

truncate table STATS$LATCH_PARENT;

truncate table STATS$LIBRARYCACHE;

truncate table STATS$BUFFER_POOL_STATISTICS;

truncate table STATS$ROLLSTAT;

truncate table STATS$ROWCACHE_SUMMARY;

truncate table STATS$SGA;

truncate table STATS$SGASTAT;

truncate table STATS$SYSSTAT;

truncate table STATS$SESSTAT;

truncate table STATS$SYSTEM_EVENT;

truncate table STATS$SESSION_EVENT;

truncate table STATS$BG_EVENT_SUMMARY;

truncate table STATS$WAITSTAT;

truncate table STATS$ENQUEUESTAT;

truncate table STATS$SQL_SUMMARY;

truncate table STATS$SQL_STATISTICS;

truncate table STATS$SQLTEXT;

truncate table STATS$PARAMETER;

delete from STATS$SNAPSHOT;

delete from STATS$DATABASE_INSTANCE;

commit;

如果采样了大量的数据，直接Delete是非常缓慢的，可以考虑使用上述SQL截断所有表。

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之九-其它重要脚本-eygle.com

Statspack之九-其它重要脚本

1．通过导出保存及共享数据

在诊断系统问题时，可能需要向专业人士提供原始数据，这时我们可以导出Statspack表数据，其中我们可能用到：spuexp.par

其内容主要为：

file=spuexp.dmp log=spuexp.log compress=y grants=y indexes=y rows=y constraints=y owner=PERFSTAT consistent=y

我们可以导出如下：

exp userid=perfstat/my_perfstat_password parfile=spuexp.par

2．删除数据

spdrop.sql在执行时主要调用两个脚本: spdtab.sql 、spdusr.sql

前者删除表及同义词等数据，后者删除用户

3．Oracle92中新增加的脚本

1．用于升级statspack对象的脚本,这些脚本需要以具有SYSDBA权限的用户运行, 升级前请先备份存在的Schema数据:

SPUP90.SQL: 用于升级9.0版本的模式至9.2版本。
SPUP817.SQL: 如果从Statspack 8.1.7升级,需要运行这个脚本
SPUP816.SQL: 从Statspack 8.1.6升级,需要运行这个脚本，然后运行SPUP817.SQL.

2．sprepsql.sql 用于根据给定的SQL Hash值生成SQL报告

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之十-调整STATSPACK的收集门限-eygle.com

Statspack之十-调整STATSPACK的收集门限

Statspack有两种类型的收集选项：

级别（level）：控制收集数据的类型

门限（threshold）：设置收集的数据的阈值。

1．级别（level）

Statspack共有三种快照级别，默认值是5

a.level 0: 一般性能统计。包括等待事件、系统事件、系统统计、回滚段统计、行缓存、SGA、会话、锁、缓冲池统计等等。

b.level 5: 增加SQL语句。除了包括level0的所有内容，还包括SQL语句的收集，收集结果记录在stats$sql_summary中。

c.level 10: 增加子锁存统计。包括level5的所有内容。并且还会将附加的子锁存存入stats$lathc_children中。在使用这个级别时需要慎重，建议在Oracle support的指导下进行。

可以通过statspack包修改缺省的级别设置

SQL>execute statspack.snap(i_snap_level=>0,i_modify_parameter=>’true’);

通过这样的设置，以后的收集级别都将是0级。

如果你只是想本次改变收集级别，可以忽略i_modify_parameter参数。

SQL>execute statspack.snap(i_snap_level=>10);

2．快照门限

快照门限只应用于stats$sql_summary表中获取的SQL语句。

因为每一个快照都会收集很多数据，每一行都代表获取快照时数据库中的一个SQL语句，所以stats$sql_summary很快就会成为Statspack中最大的表。

门限存储在stats$statspack_parameter表中。让我们了结一下各种门限：

a. executions_th这是SQL语句执行的数量(默认值是100)

b. disk_reads_tn这是SQL语句执行的磁盘读入数量（默认值是1000）

c. parse_calls_th这是SQL语句执行的解析调用的数量（默认值是1000）

d. buffer_gets_th这是SQL语句执行的缓冲区获取的数量（默认值是10000）

任何一个门限值超过以上参数就会产生一条记录。

通过调用statspack.modify_statspack_parameter函数我们可以改变门限的默认值。

例如：

SQL>execute statspack.modify_statspack_parameter(i_buffer_gets_th=>100000,i_disk_reads_th=>100000;

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .


Statspack之十一-Statspack报告各部分简要说明-eygle.com

Statspack之十一-Statspack报告各部分简要说明

    • 第一部分

数据库概要信息

DB Name         DB Id    Instance     Inst Num Release     Cluster Host
---------- ----------- ------------ --------   -----------  ------------
GLOB         188430914   glob              1  9.2.0.4.0   NO    b02

    • 第二部分

数据库采样时段，这一部分记录了数据库采样的时间，以及采样点数，这部分信息对于report来说是十分重要。

任何统计数据都需要通过时间纬度来衡量，离开了时间，任何数据都失去了意义。

我们在论坛上经常看到有人贴出Top 5等待事件寻求分析，我们的回答是:

无法分析，如果没有时间纬度!

            Snap Id     Snap Time      Sessions Curs/Sess Comment
            ------- ------------------ -------- --------- -------------------
Begin Snap:   508    10-Nov-03 15:27:29       76      39.4
End Snap:     511    10-Nov-03 15:57:42       66      35.4
   Elapsed:                               30.22 (mins)

    • 第三部分

主要性能指标说明:

  • Execute to Parse %执行分析比率

Instance Efficiency Percentages (Target 100%)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            Buffer Nowait %:  100.00       Redo NoWait %: 100.00
            Buffer  Hit   %:   99.81    In-memory Sort %: 100.00
            Library Hit   %:   98.75        Soft Parse %:  97.05
         Execute to Parse %:   44.21         Latch Hit %:  94.79
Parse CPU to Parse Elapsd %:   11.74     % Non-Parse CPU:  96.08

执行分析比率计算公式如下:

100 * (1 - Parses/Executions) = Execute to Parse

所以如果系统Parses > Executions,就可能出现该比率小于0的情况.

该参数计算来自以下部分:

Instance Activity Stats for DB: ORA9  Instance: ora91  Snaps: 30 -32

Statistic                              Total     per Second    per Trans
--------------------------------- ------------------ -------------- ------------
exchange deadlocks                       481            0.2          0.0
execute count                      4,873,158        1,968.2         94.4

……………

parse count (failures)                   542            0.2          0.0
parse count (hard)                    80,281           32.4          1.6
parse count (total)                2,718,643        1,098.0         52.6
parse time cpu                        44,009           17.8          0.9
parse time elapsed                   374,902          151.4          7.3

…………………….

通过公式及以上两个数值：

100 * (1 - Parses/Executions) = Execute to Parse

100 * (1 - 2,718,643/4,873,158) = 0.44211884777797067117462 * 100 = 44.21

该值<0通常说明shared pool设置或效率存在问题

造成反复解析，reparse可能较严重,或者可是同snapshot有关

如果该值为负值或者极低,通常说明数据库性能存在问题

  • Parse CPU to Parse Elapsd %

来自parse time cpu和parse time elapsed

100*（parse time cpu / parse time elapsed）= Parse CPU to Parse Elapsd %

100*（44,009 / 374,902）= 11.7388010733471680599196590% = 11.74%

  • Rollback per transaction 平均事务回滚率

  % Blocks changed per Read:    0.37    Recursive Call %:    1.14
   Rollback per transaction %:   38.22       Rows per Sort:   11.83

如果回滚率过高，可能说明你的数据库经历了太多的无效操作
过多的回滚可能还会带来Undo Block的竞争

该参数计算公式如下:

     Round(User rollbacks / (user commits + user rollbacks) ,4)* 100%

…………….
user commits                             31,910           12.9          0.6
user rollbacks                           19,740            8.0          0.4
…………….

对于本例:

     Round(19740 / (31910 + 19740),4) = .3822

这一部分的内容还没有写完,在继续进行中...

:)

2004年6月25日 星期五

If you have any question,please mail to eygle@itpub.net .


Statspack之十二-db file scattered read-DB文件分散读取-www.eygle.com

Statspack之十二-db file scattered read-DB文件分散读取

Last Updated: Thursday, 2004-10-14 19:51 Eygle

这种情况通常显示与全表扫描相关的等待。
当数据库进行全表扫时，基于性能的考虑，数据会分散(scattered)读入Buffer Cache。如果这个等待事件比较显著，
可能说明对于某些全表扫描的表，没有创建索引或者没有创建合适的索引，我们可能需要检查这些数据表已确定是否进
行了正确的设置。

然而这个等待事件不一定意味着性能低下，在某些条件下Oracle会主动使用全表扫描来替换索引扫描以提高性能，这
和访问的数据量有关，在CBO下Oracle会进行更为智能的选择，在RBO下Oracle更倾向于使用索引。

因为全表扫描被置于LRU（Least Recently Used，最近最少适用）列表的冷端（cold end），对于频繁访问的较
小的数据表，可以选择把他们Cache到内存中，以避免反复读取。

当这个等待事件比较显著时，可以结合v$session_longops动态性能视图来进行诊断，该视图中记录了长时间（运
行时间超过6秒的）运行的事物，可能很多是全表扫描操作（不管怎样，这部分信息都是值得我们注意的）。

我们通过通过一个案例分析来熟悉一下这个等待事件:

DB Name        DB Id     Instance    Inst Num  Release     OPS   Host
----------  -----------  ----------  --------  ----------  ----  ----------
K2        1999167370      k2              1  8.1.5.0.0   NO      k2

这是一个8.1.5的数据库系统，通过脚本增强，我们可以在8.1.5的数据库上使用statspack来进行数据库诊断。

                                                             Snap Length
Start Id    End Id       Start Time             End Time         (Minutes)
--------  --------  --------------------  --------------------  -----------
     170       176  25-Feb-03 10:00:11    25-Feb-03 15:00:05         299.90

Cache Sizes
~~~~~~~~~~~
           db_block_buffers:       64000
              db_block_size:        8192
                 log_buffer:     8388608
           shared_pool_size:   157286400

………………

Top 5 Wait Events
~~~~~~~~~~~~~~~~~                                              		     Wait  % Total
Event                                          Waits  			Time (cs)  Wt Time
-------------------------------------------- ------------ ----------------------- -------
db file scattered read                         16,842,920    	        3,490,719   43.32
latch free                                     844,272    		3,270,073   40.58
buffer busy waits                               114,421      		  933,136   11.58
db file sequential read                          2,067,910      	  117,750    1.46
enqueue                                          464      		  110,840    1.38
         -------------------------------------------------------------

这是一个典型的性能低下的系统，几个重要的等待事件都在Top 5中出现，其中，前3个等待极为显著，需要进行
相应的调整。
在5小时的采样间隔内，其中db file scattered read累计等待时间约10小时，已经成为影响系统性能的主要原因。
了解了这些以后我们就可以进一步察看相关SQL看是否存在可以的SQL语句。

SQL ordered by Gets for DB: K2  Instance: k2  Snaps:     170 -    176

                                Gets       % of
   Buffer Gets     Executes   per Exec    Total   Hash Value
-------------- ------------ ------------ ------ ------------
SQL statement
------------------------------------------------------------------------------
     6,480,163           12    540,013.6    2.4   3791855498
  SELECT "PROCESS_REQ"."WORK_ID", "PROCESS_REQ"."STOCK_NO",    "PROCESS_R

     3,784,566           16    236,535.4    1.4   2932917818
SELECT * FROM FIND_LATER_WO ORDER BY NOTE,ORDER_NO

     1,200,976            3    400,325.3     .4   4122791109
  SELECT "ITEM_STOCK"."ITEM_NO",              "ITEM"."NOTE",            "ITEM"

       923,944            9    102,660.4     .3   2200071737
  SELECT  "ITEM_STOCK"."ITEM_NO" ,           "ITEM_STOCK"."STOCK_NO" ,

       921,301            3    307,100.3     .3   2218843294
  SELECT "ITEM_STOCK"."ITEM_NO",              "ITEM"."NOTE",            "ITEM"

       911,285            3    303,761.7     .3   1769130587
  SELECT  "LISTS"."ITEM_NO" ,           "LISTS"."SUB_ITEM" ,           "LISTS"

       831,439            2    415,719.5     .3   1349577999
  SELECT  "GROUP_OPER"."ITEM_NO" ,           "GROUP_OPER"."PROCESS_ID" ,

       802,918            1    802,918.0     .3   3613809507
  SELECT  "LISTS"."ITEM_NO" ,           "LISTS"."SUB_ITEM" ,           "ITEM".

       800,548            2    400,274.0     .3   2643788247
  SELECT "ITEM_STOCK"."ITEM_NO",              "ITEM"."NOTE",            "ITEM"

       666,085            2    333,042.5     .2   3391363608
  SELECT "ITEM_STOCK"."ITEM_NO",              "ITEM_STOCK"."STOCK_NO",
          ………..

注意到以上很多查询导致的Buffer Gets都非常庞大，我们非常有理由怀疑索引存在问题，甚至缺少必要的索引。
以上记录的是SQL的片段，通过Hash Value值结合v$sql_text我们可以获得完整的SQL语句。

在这次诊断中，我紧接着去查询的是v$session_longops数据表，一个分组查询的结果如下:

TARGET                                  COUNT(*)
---------------------------------------------------------------- ----------
SA.PPBT_GRAPHOBJTABLE                  418
SA.PPBT_PPBTOBJRELATTABLE              53

我们发现这些问题SQL的全表扫描(结合v$session_longops视图中的OPNAME)主要集中在PPBT_GRAPHOBJTABLE和
PPBT_PPBTOBJRELATTABLE两张数据表上。
进一步研究发现这两个数据表上没有任何索引，并且有相当的数据量:

SQL> select count(*) from SA.PPBT_PPBTOBJRELATTABLE;

  COUNT(*)
----------
   1209017
  SQL> select count(*) from SA.PPBT_GRAPHOBJTABLE;

   COUNT(*)
----------
      2445

在创建了合适的索引后，系统性能得到了大幅提高!

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过mailto:eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

原文出处:

http://www.eygle.com/statspack/statspack12.htm


Statspack之十四-"log file sync" 等待事件-www.eygle.com

Statspack之十四-"log file sync" 等待事件

Thursday, 2004-10-14 17:49 Eygle

当一个用户提交(commits)或者回滚(rollback),session的redo信息需要写出到redo logfile中.
用户进程将通知LGWR执行写出操作,LGWR完成任务以后会通知用户进程.
这个等待事件就是指用户进程等待LGWR的写完成通知.

对于回滚操作，该事件记录从用户发出rollback命令到回滚完成的时间.

如果该等待过多，可能说明LGWR的写出效率低下，或者系统提交过于频繁.
针对该问题，可以关注:
log file parallel write等待事件
user commits,user rollback等统计信息可以用于观察提交或回滚次数

解决方案:
1.提高LGWR性能
尽量使用快速磁盘，不要把redo log file存放在raid 5的磁盘上
2.使用批量提交
3.适当使用NOLOGGING/UNRECOVERABLE等选项

可以通过如下公式计算平均redo写大小：

avg.redo write size = (Redo block written/redo writes)*512 bytes

如果系统产生redo很多，而每次写的较少，一般说明LGWR被过于频繁的激活了.
可能导致过多的redo相关latch的竞争,而且Oracle可能无法有效的使用piggyback的功能.

我们从一个statspack中提取一些数据来研究一下这个问题.

1.主要信息

DB Name         DB Id    Instance     Inst Num Release     OPS Host
------------ ----------- ------------ -------- ----------- --- ------------
DB           1222010599  oracle              1 8.1.7.4.5   NO  sun
                Snap Id     Snap Time      Sessions
                ------- ------------------ --------
 Begin Snap:       3473 13-Oct-04 13:43:00      540
   End Snap:       3475 13-Oct-04 14:07:28      540
    Elapsed:                  24.47 (mins)

Cache Sizes
~~~~~~~~~~~
           db_block_buffers:     102400          log_buffer:   20971520
              db_block_size:       8192    shared_pool_size:       600M

Load Profile
~~~~~~~~~~~~                            Per Second       Per Transaction
                                   ---------------       ---------------
                  Redo size:             28,458.11              2,852.03
                  ......

2.等待事件

Event                               Waits   Timeouts  Time (cs)    (ms)   /txn
---------------------------- ------------ ---------- ----------- ------ ------
log file sync                      14,466          2       4,150      3    1.0
db file sequential read            17,202          0       2,869      2    1.2
latch free                         24,841     13,489       2,072      1    1.7
direct path write                     121          0       1,455    120    0.0
db file parallel write              1,314          0       1,383     11    0.1
log file sequential read            1,540          0          63      0    0.1
....
log file switch completion              1          0           3     30    0.0
refresh controlfile command            23          0           1      0    0.0
LGWR wait for redo copy                46          0           0      0    0.0
....
log file single write                   4          0           0      0    0.0

我们看到，这里log file sync和db file parallel write等待同时出现了.
显然log file sync在等待db file parallel write的完成.

这里磁盘IO肯定存在了瓶颈，实际用户的redo和数据文件同时存放在Raid的磁盘上，存在性能问题.
需要调整.

3.统计信息

Statistic                                    Total   per Second    per Trans
--------------------------------- ---------------- ------------ ------------
....
redo blocks written                         93,853         63.9          6.4
redo buffer allocation retries                   1          0.0          0.0
redo entries                               135,837         92.5          9.3
redo log space requests                          1          0.0          0.0
redo log space wait time                         3          0.0          0.0
redo ordering marks                              0          0.0          0.0
redo size                               41,776,508     28,458.1      2,852.0
redo synch time                              4,174          2.8          0.3
redo synch writes                           14,198          9.7          1.0
redo wastage                             4,769,200      3,248.8        325.6
redo write time                              3,698          2.5          0.3
redo writer latching time                        0          0.0          0.0
redo writes                                 14,572          9.9          1.0
....
sorts (disk)                                     4          0.0          0.0
sorts (memory)                             179,856        122.5         12.3
sorts (rows)                             2,750,980      1,874.0        187.8
....
transaction rollbacks                           36          0.0          0.0
transaction tables consistent rea                0          0.0          0.0
transaction tables consistent rea                0          0.0          0.0
user calls                               1,390,718        947.4         94.9
user commits                                14,136          9.6          1.0
user rollbacks                                 512          0.4          0.0
write clones created in backgroun                0          0.0          0.0
write clones created in foregroun               11          0.0          0.0
          -------------------------------------------------------------

avg.redo write size = (Redo block written/redo writes)*512 bytes
            = ( 93,853 / 14,572 )*512
            = 3K

这个平均过小了，说明系统的提交过于频繁.

Latch Sleep breakdown for DB: DPSHDB  Instance: dpshdb  Snaps: 3473 -3475
-> ordered by misses desc

                                Get                                  Spin &
Latch Name                    Requests         Misses      Sleeps Sleeps 1->4
-------------------------- -------------- ----------- ----------- ------------
row cache objects              12,257,850     113,299          64 113235/64/0/
                                                                  0/0
shared pool                     3,690,715      60,279      15,857 52484/588/65
                                                                  46/661/0
library cache                   4,912,465      29,454       8,876 23823/2682/2
                                                                  733/216/0
cache buffers chains           10,314,526       2,856          33 2823/33/0/0/
                                                                  0
redo writing                       76,550         937           1 936/1/0/0/0
session idle bit                2,871,949         225           1 224/1/0/0/0
messages                          107,950         159           2 157/2/0/0/0
session allocation                184,386          44           6 38/6/0/0/0
checkpoint queue latch             96,583           1           1 0/1/0/0/0
          -------------------------------------------------------------

由于过渡频繁的提交，LGWR过度频繁的激活，我们看到这里出现了redo writing的latch竞争.

关于redo writing竞争你可以在steve的站点找到详细的介绍:
http://www.ixora.com.au/notes/lgwr_latching.htm

转引如下:

When LGWR wakes up, it first takes the redo writing latch to update the SGA variable that shows whether it is active. This prevents other Oracle processes from posting LGWR needlessly. LGWR then takes the redo allocation latch to determine how much redo might be available to write (subject to the release of the redo copy latches). If none, it takes the redo writing latch again to record that it is no longer active, before starting another rdbms ipc message wait.
If there is redo to write, LGWR then inspects the latch recovery areas for the redo copy latches (without taking the latches) to determine whether there are any incomplete copies into the log buffer. For incomplete copies above the sync RBA, LGWR just defers the writing of that block and subsequent log buffer blocks. For incomplete copies below the sync RBA, LGWR sleeps on a LGWR wait for redo copy wait event, and is posted when the required copy latches have been released. The time taken by LGWR to take the redo writing and redo allocation latches and to wait for the redo copy latches is accumulated in the redo writer latching time statistic.

(Prior to release 8i, foreground processes held the redo copy latches more briefly because they did not retain them for the application of the change vectors. Therefore, LGWR would instead attempt to assure itself that there were no ongoing copies into the log buffer by taking all the redo copy latches.)

After each redo write has completed, LGWR takes the redo allocation latch again in order to update the SGA variable containing the base disk block for the log buffer. This effectively frees the log buffer blocks that have just been written, so that they may be reused.

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过mailto:eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

原文出处:

http://www.eygle.com/statspack/statspack14-LogFileSync.htm


Statspack之十三-Enqueue-www.eygle.com

Statspack 之十三-Enqueue

Last Updated: Thursday, 2004-10-14 19:59 Eygle

enqueue是一种保护共享资源的锁定机制。该锁定机制保护共享资源，如记录中的数据，以避免两个人在同一时间更新 同一数据。enqueue
包括一个排队机制，即FIFO（先进先出）排队机制。

Enqueue等待常见的有ST、HW 、TX 、TM等

ST enqueue，用于空间管理和字典管理的表空间(DMT)的区间分配，在DMT中典型的是对于uet$和fet$数据字典表的 争用。对于支持LMT的
版本，应该尽量使用本地管理表空间. 或者考虑手工预分配一定数量的区(Extent)，减少动态扩展
时发生的严重队列竞争。

我们通过一个实例来看一下:

DB Name         DB Id    Instance     Inst Num Release     OPS Host
------------ ----------- ------------ -------- ----------- --- ------------------
DB       40757346      aaa                 1 8.1.7.4.0   NO    server

                Snap Id     Snap Time      Sessions
                ------- ------------------ --------
 Begin Snap:       2845 31-10月-03 02:10:16      46
   End Snap:       2848 31-10月-03 03:40:05      46
    Elapsed:                  89.82 (mins)

对于一个Statspack的report,采样时间是非常重要的维度，离开时间做参考，任何等待都不足以说明问题。

Cache Sizes
~~~~~~~~~~~
           db_block_buffers:      51200          log_buffer:    2097152
              db_block_size:      16384    shared_pool_size:  209715200
………..
Top 5 Wait Events
~~~~~~~~~~~~~~~~~                                   Wait     % Total
Event                                               Waits  Time (cs)   Wt Time
-------------------------------------------- ------------ ------------ -------
enqueue                                            53,793   16,192,686   67.86
rdbms ipc message                                  19,999    5,927,350   24.84
pmon timer                                          1,754      538,797    2.26
smon timer                                             17      522,281    2.19
SQL*Net message from client              		   94,525      520,104   2.18
          -------------------------------------------------------------

在Statspack分析中，Top 5等待事件是我们最为关注的部分。
这个系统中，除了enqueue 等待事件以外，其他4个都属于空闲等待事件，无须关注。我们来关注一下enqueue等
待事件，在89.82 (mins)的采样间隔内，累计enqueue等待长达16,192,686cs,即45小时左右。这个等待已经太过
显著，实际上这个系统也正因此遭遇了巨大的困难，观察到队列等待以后，我们就应该关注队列等待在等待什么
资源。快速跳转的Statspack的其他部分，我们看到以下详细内容:

Enqueue activity for DB: DB  Instance: aaa  Snaps: 2716 -2718
-> ordered by waits desc, gets desc

Enqueue            Gets      Waits
---------- ------------ ----------
ST                1,554      1,554
          -------------------------------------------------------------

我们看到主要队列等待在等待ST锁定，对于DMT，我们说这个等待跟FET$,UET$的争用紧密相关。我们在回过头来
研究捕获的SQL语句:

-> End Buffer Gets Threshold:   10000
-> Note that resources reported for PL/SQL includes the resources used by
   all SQL statements called within the PL/SQL code.  As individual SQL
   statements are also reported, it is possible and valid for the summed
   total % to exceed 100

  Buffer Gets    Executions  Gets per Exec  % Total  Hash Value
--------------- ------------ -------------- ------- ------------
      4,800,073       10,268          467.5    51.0   2913840444
select length from fet$ where file#=:1 and block#=:2 and ts#=:3

        803,187       10,223           78.6     8.5    528349613
delete from uet$ where ts#=:1 and segfile#=:2 and segblock#=:3 a
nd ext#=:4

        454,444       10,300           44.1     4.8   1839874543
select file#,block#,length from uet$ where ts#=:1 and segfile#=:
2 and segblock#=:3 and ext#=:4

         23,110       10,230            2.3     0.2   3230982141
insert into fet$ (file#,block#,ts#,length) values (:1,:2,:3,:4)

         21,201          347           61.1     0.2   1705880752
select file# from file$ where ts#=:1
….
          9,505           12          792.1     0.1   1714733582
select f.file#, f.block#, f.ts#, f.length from fet$ f, ts$ t whe
re t.ts#=f.ts# and t.dflextpct!=0 and t.bitmapped=0

          6,426          235           27.3     0.1   1877781575
delete from fet$ where file#=:1 and block#=:2 and ts#=:3

我们看到数据库频繁操作UET$,FET$系统表已经成为了系统的主要瓶颈。
至此，我们已经可以准确的为该系统定位问题，相应的解决方案也很容易确定，在8.1.7中，使用LMT代替DMT，
这是解决问题的根本办法，当然实施起来还要进行综合考虑，实际情况还要复杂得多。

HW enqueue指和段的高水位标记相关等待；手动分配适当区可以避免这一等待。

TX是最常见的enqueue等待。TX enqueue等待通常是以下三个问题之一产生的结果。
第一个问题是唯一索引中的重复索引，你需要执行提交（commit）/回滚（rollback）操作来释放enqueue。
第二个问题是对同一位图索引段的多次更新。因为单个位图段可能包含多个行地址（rowid），所以当多个用户试图更新同一段时，可能一个
用户会锁定其他用户请求的记录，这时等待出现。直到获得锁定的用户提交或回滚， enqueue释放。
第三个问题，也是最可能发生的问题是多个用户同时更新同一个块。如果没有足够的ITL槽，就会发生块级锁定。通过增大initrans和/或
maxtrans以允许使用多个ITL槽（对于频繁并发进行DML操作的数据表，在建表之初就应该考虑为相应参数设置合理的数值，避免系统运行
以后在线的更改，在8i之前，freelists等参数不能在线更改，设计时的考虑就尤为重要），或者增大表上的pctfree值，就可以很容易的避免
这种情况。

TM enqueue队列锁在进行DML操作前获得，以阻止对正在操作的数据表进行任何DDL操作(在DML操作一个数据表时，其结构不能被更改)。

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过mailto:eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

原文出处:

http://www.eygle.com/statspack/statspack13.htm


关于Oracle9i的Peeking of User-Defined Bind Variables -www.eygle.com

关于Oracle9i的Peeking of User-Defined Bind Variables

Thursday, 2004-09-16 12:02 Eygle

我们知道,由于使用绑定变量,在Oracle9i之前会导致柱状图信息无法被用到
从Oracle9i开始Oracle提供了Peeking的方式,在使用绑定变量的SQL第一次执行时,使用参数传递成文本sql，此时可以有效的利用
存在的柱状图信息进行执行计划的评估,从而在某些数据分布不均和的情况下，可能可以产生更为精确的执行计划.这显然是一个有
益的提高,然而这个Peeking有时候也会存在问题,本文通过实例说明这个特性及其不足.

以下是完整的测试验证过程:

[oracle@jumper oracle]$ sqlplus eqsp/eqsp

SQL*Plus: Release 9.2.0.3.0 - Production on Thu Nov 20 23:13:20 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

准备试验数据

SQL>
SQL>
SQL> drop table t;

Table dropped.

SQL> create table t as select 1 id,a.* from dba_objects a;

Table created.

SQL> insert into t select * from t;

10168 rows created.

SQL> /

20336 rows created.

SQL> commit;

Commit complete.

SQL> select count(*) from t;

COUNT(*)
----------
40672

SQL> update t set id = 99 where rownum <2; --构造试验数据,id=99的纪录只有一条.其余id=1

1 row updated.

SQL> commit;

Commit complete.

SQL> create index t_ind1 on t(id);

Index created.

SQL> analyze table t compute statistics for table for all indexed columns;

Table analyzed.

SQL> exit

测试脚本

[oracle@jumper oracle]$ vi eygle.sql

set term off
set head off
alter session set sql_trace = true;
select * from t where id = :v;
alter session set sql_trace = false;

~
~
~
"eygle.sql" [ò?×a??] 6L, 131C ò?D′è?

[oracle@jumper oracle]$ more eygle2.sql
set term off
set head off
alter session set sql_trace = true;
select * from t n_1 where id = :v;
alter session set sql_trace = false;

第一步测试:

SQL> var v number
SQL> exec :v :=1 ---传入参数为1 ,此时Oracle应该放弃索引,使用全表扫描

PL/SQL procedure successfully completed.

SQL> @$ORACLE_BASE/eygle.sql

[oracle@jumper udump]$ tkprof *.trc e1.log

TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:49:28 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

[oracle@jumper udump]$ vi e1.log

TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:49:28 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Trace file: hsjf_ora_16137.trc
Sort options: default

********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************

alter session set sql_trace = true

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0
Optimizer goal: CHOOSE
Parsing user id: 96
********************************************************************************

select *
from
t where id = :v

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2713 0.50 0.47 0 3239 0 40671
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2715 0.51 0.48 0 3239 0 40671

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 96

Rows Row Source Operation
------- ---------------------------------------------------
40671 TABLE ACCESS FULL T (cr=3239 r=0 w=0 time=246446 us)

-----------由于柱状图信息生效,此处使用了全表扫描

********************************************************************************

Peek here

select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#,
sample_size, minimum, maximum, distcnt, lowval, hival, density, col#,
spare1, spare2, avgcln
from
hist_head$ where obj#=:1 and intcol#=:2

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 13 0.00 0.00 0 0 0 0
Fetch 13 0.00 0.00 0 26 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 27 0.00 0.00 0 26 0 0

Misses in library cache during parse: 0
Optimizer goal: RULE
Parsing user id: SYS (recursive depth: 1)
********************************************************************************

alter session set sql_trace = false

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 0 0

SQL> exec :v :=99 ---id=99的记录只有一条,此处应该使用索引

PL/SQL procedure successfully completed.

SQL> @$ORACLE_BASE/eygle.sql

[oracle@jumper udump]$ tkprof hsjf_ora_16137.trc e2.log

TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:50:44 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

[oracle@jumper udump]$ vi e2.log

cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************

alter session set sql_trace = true

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0
Optimizer goal: CHOOSE
Parsing user id: 96
********************************************************************************

execute twice

select *
from
t where id = :v

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2715 0.55 0.52 12 3802 0 40672
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2719 0.56 0.52 12 3802 0 40672

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 96

Rows Row Source Operation
------- ---------------------------------------------------
40671 TABLE ACCESS FULL T (cr=3239 r=0 w=0 time=246446 us)

---------由于不再进行Peeking,所以这里仍然使用了全表扫描,这是错误的选择

********************************************************************************

peek once

select /*+ rule */ bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp#,
sample_size, minimum, maximum, distcnt, lowval, hival, density, col#,
spare1, spare2, avgcln
from
hist_head$ where obj#=:1 and intcol#=:2

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 13 0.00 0.00 0 0 0 0
Fetch 13 0.00 0.00 0 26 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 27 0.00 0.00 0 26 0 0

第二步测试

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> var v number
SQL> exec :v :=99

PL/SQL procedure successfully completed.

SQL> @eygle2.sql
SQL> !

[oracle@jumper udump]$ tkprof hsjf_ora_15042.trc 3.log

TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:55:53 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

[oracle@jumper udump]$ vi 3.log

Optimizer goal: CHOOSE

TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:55:53 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Trace file: hsjf_ora_15042.trc
Sort options: default

********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************

alter session set sql_trace = true

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 1 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0
Optimizer goal: CHOOSE
Parsing user id: 96
********************************************************************************

select *
from
t n_1 where id = :v

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 8 0.00 0.00 1 18 0 99
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 10 0.00 0.00 1 18 0 99

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 96

index scan is right here.

Rows Row Source Operation
------- ---------------------------------------------------
99 TABLE ACCESS BY INDEX ROWID T (cr=18 r=1 w=0 time=1963 us)
99 INDEX RANGE SCAN T_IND1 (cr=9 r=1 w=0 time=1264 us)(object id 13674)

********************************************************************************

SQL> exec :v :=1

PL/SQL procedure successfully completed.

SQL> @eygle2.sql
SQL> !

[oracle@jumper udump]$ tkprof hsjf_ora_15042.trc 4.log

TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:59:07 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

[oracle@jumper udump]$ vi 4.log

TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:59:07 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Trace file: hsjf_ora_15042.trc
Sort options: default

********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************

alter session set sql_trace = true

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0
Optimizer goal: CHOOSE
Parsing user id: 96
********************************************************************************

execute twice here,use index scan

select *
from
t n_1 where id = :v

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2714 0.77 0.74 80 5988 0 40672
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2718 0.77 0.74 80 5988 0 40672

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 96

Rows Row Source Operation
------- ---------------------------------------------------
99 TABLE ACCESS BY INDEX ROWID T (cr=18 r=1 w=0 time=1963 us)
99 INDEX RANGE SCAN T_IND1 (cr=9 r=1 w=0 time=1264 us)(object id 13674)

********************************************************************************


使用or展开进行sql调整-eygle.com

使用or展开进行sql调整

作者: Eygle

itpub link:

http://www.itpub.net/showthread.php?threadid=239335

问题:

这样一条sql应该怎么优化?

select * from sys_user
where user_code = 'zhangyong'
or user_code in
(select grp_code
from sys_grp
where sys_grp.user_code = 'zhangyong')

Execution Plan
----------------------------------------------------------
0  SELECT STATEMENT Optimizer=RULE
1  0   FILTER
2  1     TABLE ACCESS (FULL) OF 'SYS_USER'
3  1     INDEX (UNIQUE SCAN) OF 'PK_SYS_GRP' (UNIQUE)

Statistics
----------------------------------------------------------
14 	recursive calls
4 	db block gets
30590 consistent gets
0 	physical reads
0 	redo size
1723 	bytes sent via SQL*Net to client
425 	bytes received via SQL*Net from client
2 	SQL*Net roundtrips to/from client
0 	sorts (memory)
0 	sorts (disk)
3 	rows processed

里面的查询返回的记录数一般只有一两条，但sys_user表的数据很多，怎么样才能让这条sql以sys_grp为驱动表？
表中记录情况如下:

SQL> select count(*) from sys_grp;

COUNT(*)
----------
25130

SQL> select count(*) from sys_user;

COUNT(*)
----------
15190

优化:

降低逻辑读是优化SQL的基本原则之一

我们尝试通过降低逻辑读来加快SQL的执行.

这里我们使用or展开来改写SQL查询:

select * from sys_user where user_code = 'zhangyong'
union all
select * from sys_user where user_code <> 'zhangyong'
and user_code in (select grp_code from sys_grp where sys_grp.user_code = 'zhangyong')

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         130 consistent gets
          0  physical reads
          0  redo size
       1723  bytes sent via SQL*Net to client
        425  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
          3  rows processed

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=RULE
   1    0   UNION-ALL
   2    1     TABLE ACCESS (BY INDEX ROWID) OF 'SYS_USER'
   3    2       INDEX (UNIQUE SCAN) OF 'PK_SYS_USER' (UNIQUE)
   4    1     NESTED LOOPS
   5    4       VIEW OF 'VW_NSO_1'
   6    5         SORT (UNIQUE)
   7    6           TABLE ACCESS (BY INDEX ROWID) OF 'SYS_GRP'
   8    7             INDEX (RANGE SCAN) OF 'FK_SYS_USER_CODE' (NON-UNIQUE)
   9    4       TABLE ACCESS (BY INDEX ROWID) OF 'SYS_USER'
  10    9         INDEX (UNIQUE SCAN) OF 'PK_SYS_USER' (UNIQUE)

我们注意到,通过改写,逻辑读减少到130，从30590到130这是一个巨大的提高,减少逻辑读最终会减少资源消耗,提高SQL的执行效率.

这个改写把Filter改为了Nest LOOP,索引得以充分利用.从而大大提高了性能.

我们同时注意到，这里引入了一个排序

排序来自于这一步:

-----------------------------------------------------------------------------------------

6  5  SORT (UNIQUE)
7  6    TABLE ACCESS (BY INDEX ROWID) OF 'SYS_GRP'
8  7       INDEX (RANGE SCAN) OF 'FK_SYS_USER_CODE' (NON-UNIQUE)

------------------------------------------------------------------------------------------

在'SYS_GRP'表中，user_code 是非唯一键值
在in值判断里，要做sort unique排序，去除重复值

这里的union all是不需要排序的

2004年7月9日 星期五 15:42

If you have any question,please mail to eygle@itpub.net .


关于PUSH_SUBQ提示的说明-www.eygle.com

关于PUSH_SUBQ提示的说明

PUSH_SUBQ 可以用来控制子查询的执行 这个是PUSH_SUBQ 的本意

我那个例子的意思是说:
PUSH_SUBQ 本质上是个CBO的hints(当然RBO也提不上hints)
由于PUSH_SUBQ 的引入就是为了来解决unnesting的某些不足
所以在不同的版本上,这个hints发挥的作用也有所不同了.

8i上这个提示的作用更接近本原:

$ sqlplus "/ as sysdba"

SQL*Plus: Release 8.1.5.0.0 - Production on Sun Sep 12 20:51:21 2004

(c) Copyright 1999 Oracle Corporation.  All rights reserved.

Connected to:
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production

SQL> connect scott/tiger
Connected.
SQL> create table dept1 as select * from dept;

Table created.

SQL> set linesize 120
SQL> select a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

14 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   FILTER ---------------'最初push_subq的使命是为了消除/提高这个filter的效率的'
   2    1     NESTED LOOPS
   3    2       TABLE ACCESS (FULL) OF 'EMP'
   4    2       TABLE ACCESS (BY INDEX ROWID) OF 'DEPT'
   5    4         INDEX (UNIQUE SCAN) OF 'PK_DEPT' (UNIQUE)
   6    1     TABLE ACCESS (FULL) OF 'DEPT1'

Statistics
----------------------------------------------------------
          0  recursive calls
         52  db block gets
         21  consistent gets
          0  physical reads
          0  redo size
       2715  bytes sent via SQL*Net to client
        751  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         14  rows processed

用于push_subq是个CBO hints，这里我们可以看到COST的出现:

SQL> select /*+ push_subq */ a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30

14 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1 Bytes=122)
   1    0   NESTED LOOPS (Cost=3 Card=1 Bytes=122)
   2    1     TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=2 Bytes=44)
   3    2       TABLE ACCESS (FULL) OF 'DEPT1' (Cost=1 Card=1 Bytes=9)--------'这里消除了之前的filter'
   4    1     TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=21 Bytes=2100)

Statistics
----------------------------------------------------------
        204  recursive calls
         85  db block gets
         38  consistent gets
          0  physical reads
          0  redo size
       2706  bytes sent via SQL*Net to client
        768  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          5  sorts (memory)
          0  sorts (disk)
         14  rows processed

再看CBO下:

正常情况下,没什么好说的:

SQL> set autotrace traceonly
SQL> exec dbms_stats.gather_schema_stats('SCOTT')

PL/SQL procedure successfully completed.

SQL> select a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

14 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=5 Bytes=275)
   1    0   FILTER
   2    1     NESTED LOOPS (Cost=2 Card=5 Bytes=275)
   3    2       TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=1 Bytes=18)
   4    2       TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=518)
   5    1     TABLE ACCESS (FULL) OF 'DEPT1' (Cost=1 Card=1 Bytes=9)

Statistics
----------------------------------------------------------
         39  recursive calls
         68  db block gets
         21  consistent gets
          0  physical reads
          0  redo size
       2708  bytes sent via SQL*Net to client
        751  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         14  rows processed

在CBO下push_subq发挥了同样的作用:

SQL> select /*+ push_subq */ a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

14 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=5 Bytes=275)
   1    0   NESTED LOOPS (Cost=2 Card=5 Bytes=275)
   2    1     TABLE ACCESS (FULL) OF 'DEPT' (Cost=1 Card=1 Bytes=18)
   3    2       TABLE ACCESS (FULL) OF 'DEPT1' (Cost=1 Card=1 Bytes=9)---'注意这里'
   4    1     TABLE ACCESS (FULL) OF 'EMP' (Cost=1 Card=14 Bytes=518)

Statistics
----------------------------------------------------------
          0  recursive calls
         84  db block gets
         11  consistent gets
          0  physical reads
          0  redo size
       2709  bytes sent via SQL*Net to client
        768  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         14  rows processed

而在Oracle9i之中:

[oracle@jumper oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Sun Sep 12 21:42:57 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> connect scott/tiger
Connected.
SQL> set linesize 120
SQL> set autotrace traceonly
SQL> select a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE
   1    0   FILTER
   2    1     NESTED LOOPS
   3    2       TABLE ACCESS (FULL) OF 'EMP'
   4    2       TABLE ACCESS (BY INDEX ROWID) OF 'DEPT'
   5    4         INDEX (UNIQUE SCAN) OF 'PK_DEPT' (UNIQUE)
   6    1     TABLE ACCESS (FULL) OF 'DEPT1'

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         26  consistent gets
          0  physical reads
          0  redo size
       1164  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         11  rows processed

SQL> select /*+ push_subq */ a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=82 Bytes=9676)
   1    0   HASH JOIN (SEMI) (Cost=8 Card=82 Bytes=9676)
   2    1     HASH JOIN (Cost=5 Card=82 Bytes=8938)
   3    2       TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=82 Bytes=7134)
   4    2       TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=82 Bytes=1804)
   5    1     TABLE ACCESS (FULL) OF 'DEPT1' (Cost=2 Card=82 Bytes=738)

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         10  consistent gets
          0  physical reads
          0  redo size
       1195  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         11  rows processed

SQL> exec dbms_stats.gather_schema_stats('scott')

PL/SQL procedure successfully completed.

SQL> select a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=11 Bytes=682)
   1    0   HASH JOIN (SEMI) (Cost=8 Card=11 Bytes=682)
   2    1     HASH JOIN (Cost=5 Card=11 Bytes=572)
   3    2       TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=4 Bytes=52)
   4    2       TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=11 Bytes=429)
   5    1     TABLE ACCESS (FULL) OF 'DEPT1' (Cost=2 Card=4 Bytes=40)

Statistics
----------------------------------------------------------
        172  recursive calls
          0  db block gets
         60  consistent gets
          0  physical reads
          0  redo size
       1196  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          6  sorts (memory)
          0  sorts (disk)
         11  rows processed

SQL> select /*+ push_subq */ a.*
  2  from emp a,dept b where a.deptno = b.deptno and exists (select 1 from dept1 where dept1.dname = b.dname);

11 rows selected.

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=11 Bytes=682)
   1    0   HASH JOIN (SEMI) (Cost=8 Card=11 Bytes=682)
   2    1     HASH JOIN (Cost=5 Card=11 Bytes=572)
   3    2       TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=4 Bytes=52)
   4    2       TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=11 Bytes=429)
   5    1     TABLE ACCESS (FULL) OF 'DEPT1' (Cost=2 Card=4 Bytes=40)

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         10  consistent gets
          0  physical reads
          0  redo size
       1196  bytes sent via SQL*Net to client
        503  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         11  rows processed

SQL>

可以肯定的是push_subq从8i到9i的作用发生了变化
这个变化可能来自于CBO的更加优化


OPTIMIZER_INDEX_COST_ADJ与成本计算-eygle.com

OPTIMIZER_INDEX_COST_ADJ与成本计算

OPTIMIZER_INDEX_COST_ADJ
这个初始化参数代表一个百分比,取值范围在1到10000之间.
该参数表示索引扫描和全表扫描成本的比较。缺省值100表示索引扫描成本等价转换与全表扫描成本。

这些参数对于CBO的执行具有重大影响，其缺省值对于数据库来说通常需要调整。
一般来说对于OPTIMIZER_INDEX_CACHING可以设置为90左右
对于大多数OLTP系统，OPTIMIZER_INDEX_COST_ADJ可以设置在10到50之间。对于数据仓库和DSS系统，
可能不能简单的把OPTIMIZER_INDEX_COST_ADJ设置为50，通常我们需要反复调整取得一个合理值.
更为具体的可以根据统计信息,db file scattered reads/db file sequential reads来计算.

本文通过实验对该参数的使用作出探讨和说明.

我们看到optimizer_index_cost_adj的缺省值为100.

[oracle@jumper udump]$ sqlplus eygle/eygle

SQL*Plus: Release 9.2.0.3.0 - Production on Mon Jun 28 17:11:15 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> show parameter optimizer_index_cost_adj

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_index_cost_adj integer 100
SQL>

创建测试表:

SQL> create table t as select * from dba_objects;

Table created.

SQL> create index ind_owner on t(owner);

Index created.

SQL> analyze table t compute statistics;

Table analyzed.

我们分别观察一下全表扫描和索引访问的成本:

SQL> set autotrace traceonly

SQL> select * from t where owner='EYGLE';

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=14 Card=476 Bytes=36652)
1 0 TABLE ACCESS (FULL) OF 'T' (Cost=14 Card=476 Bytes=36652)

SQL> select /*+ index(t ind_owner) */ * from t where owner='EYGLE';

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=16 Card=476 Bytes=36652)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T' (Cost=16 Card=476 Bytes=36652)
2 1 INDEX (RANGE SCAN) OF 'IND_OWNER' (NON-UNIQUE) (Cost=2 Card=476)

Oracle在选择不同的访问路径时，会对全表扫描和索引扫描进行比较评估.

在比较的时候，Oracle会把索引扫描的成本转换为全表扫描的成本，和全表扫描的COST进行比较.这个转换需要一个转换因子.
就是optimizer_index_cost_adj:

optimizer_index_cost_adj * (Index Scan Cost) = 等价的 Full Scan Cost

这个 等价的 Full Scan Cost 就是来和全表扫描成本进行比较的.

而这个转换因子的临界值实际上就是Full Scan Cost 和 Index Scan Cost的比值.

即:

optimizer_index_cost_adj = Full Scan Cost / Index Scan Cost

SQL> set autotrace off
SQL> select (14/16)*100 from dual;

(14/16)*100
-----------
87.5

1 row selected.

我们通过调整optimizer_index_cost_adj来看一下执行计划的变化:

SQL> set autotrace traceonly

SQL> alter session set optimizer_index_cost_adj = 87;

Session altered.

SQL> select * from t where owner='EYGLE';

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=14 Card=476 Bytes=36652)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T' (Cost=14 Card=476 Bytes=36652)
2 1 INDEX (RANGE SCAN) OF 'IND_OWNER' (NON-UNIQUE) (Cost=2 Card=476)

此时使用索引成本较低.等价全表扫描成本为:

87% * (Index Scan Cost) < Full Scan Cost

此时Oracle选择了索引.

SQL> alter session set optimizer_index_cost_adj = 88;

Session altered.

SQL> select * from t where owner='EYGLE';

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=14 Card=476 Bytes=36652)
1 0 TABLE ACCESS (FULL) OF 'T' (Cost=14 Card=476 Bytes=36652)

此时使用索引成本较高.等价全表扫描成本为:

88% * (Index Scan Cost) > Full Scan Cost

所以Oracle选择了全表扫描.

参考文档:

http://www.evdbt.com/SearchIntelligenceCBO.doc

2004年6月28日 星期一 17:03

If you have any question,please mail to eygle@itpub.net .


Oracle的优化器-RBO、CBO及其变迁(之一)-www.eygle.com

Oracle的优化器-RBO、CBO及其变迁(之一)

Thursday, 2004-09-09 18:52 eygle


Oracle的优化器-RBO、CBO及其变迁(之二)-www.eygle.com

Oracle的优化器-RBO、CBO及其变迁(之二)

Thursday, 2004-09-09 18:53 eygle


Oracle的数据访问(之一)-数据、索引等-www.eygle.com

Oracle的数据访问(之一)

Thursday, 2004-10-07 2:49 eygle


Oracle的数据访问(之二)-B树及位图索引等-www.eygle.com

Oracle的数据访问(之二)

Thursday, 2004-10-07 2:50 eygle


Oracle的数据访问(之三)-表连接-www.eygle.com

Oracle的数据访问(之三)

Thursday, 2004-10-07 2:55 eygle


Oracle的优化器-RBO、CBO及其变迁(之三)-www.eygle.com

Oracle的优化器-RBO、CBO及其变迁(之三)

Thursday, 2004-09-09 18:54 eygle


Oracle的优化器-RBO、CBO及其变迁(之四)-www.eygle.com

Oracle的优化器-RBO、CBO及其变迁(之四)

Thursday, 2004-09-09 18:54 eygle


Oracle的数据访问(之四)-表连接及临时表等-www.eygle.com

Oracle的数据访问(之四)

Thursday, 2004-10-07 2:51 eygle


10g新特性之-expdp与传统exp的速度比较-eygle.com

10g新特性之-expdp与传统exp的速度比较

测试环境:

System Configuration: Sun Microsystems sun4u Sun Enterprise 450 (4 X UltraSPARC-II 296MHz)
System clock frequency: 99 MHz
Memory size: 2048 Megabytes

数据量:
单表测试,1363292行记录，116.6 MB左右数据

1.使用并行 expdp

花费时间:
Tue Apr 27 10:21:54 CST 2004 - Tue Apr 27 10:21:10 CST 2004 = 43秒

$ cat bak.sh
date
expdp eygle/eygle dumpfile=big_big_table.dmp directory=dpdata tables=big_big_table job_name=exptab parallel=4
date
$ ./bak.sh
Tue Apr 27 10:21:10 CST 2004

Export: Release 10.1.0.2.0 - 64bit Production on Tuesday, 27 April, 2004 10:21

Copyright (c) 2003, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "EYGLE"."EXPTAB": eygle/******** dumpfile=big_big_table.dmp directory=dpdata tables=big_big_table job_name=exptab parallel=4
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TBL_TABLE_DATA/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 248 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "EYGLE"."BIG_BIG_TABLE" 116.6 MB 1363292 rows
Master table "EYGLE"."EXPTAB" successfully loaded/unloaded
******************************************************************************
Dump file set for EYGLE.EXPTAB is:
/opt/oracle/dpdata/big_big_table.dmp
Job "EYGLE"."EXPTAB" successfully completed at 10:21

Tue Apr 27 10:21:54 CST 2004

2.使用正常 expdp

花费时间:
Tue Apr 27 10:23:36 CST 2004 - Tue Apr 27 10:23:02 CST 2004 = 34 秒

看来并行的差异需要更大的数据量的测试

$ cat bak2.sh
date
expdp eygle/eygle dumpfile=big_big_table2.dmp directory=dpdata tables=big_big_table job_name=exptab
date

$ ./bak2.sh
Tue Apr 27 10:23:02 CST 2004

Export: Release 10.1.0.2.0 - 64bit Production on Tuesday, 27 April, 2004 10:23

Copyright (c) 2003, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "EYGLE"."EXPTAB": eygle/******** dumpfile=big_big_table2.dmp directory=dpdata tables=big_big_table job_name=exptab
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TBL_TABLE_DATA/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 248 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "EYGLE"."BIG_BIG_TABLE" 116.6 MB 1363292 rows
Master table "EYGLE"."EXPTAB" successfully loaded/unloaded
******************************************************************************
Dump file set for EYGLE.EXPTAB is:
/opt/oracle/dpdata/big_big_table2.dmp
Job "EYGLE"."EXPTAB" successfully completed at 10:23

Tue Apr 27 10:23:36 CST 2004

3.常规路径exp

花费时间:Tue Apr 27 10:27:00 CST 2004 - Tue Apr 27 10:24:54 CST 2004 = 2:06

这是花费时间最长的.
是 126/34 = 370.58823529411764705882352941176%

expdp明显快于exp

$ cat bak3.sh
date
exp eygle/eygle file=big_big_table3.dmp tables=big_big_table
date

$ ./bak3.sh
Tue Apr 27 10:24:54 CST 2004

Export: Release 10.1.0.2.0 - Production on Tue Apr 27 10:24:54 2004

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

About to export specified tables via Conventional Path ...
. . exporting table BIG_BIG_TABLE 1363292 rows exported
Export terminated successfully without warnings.
Tue Apr 27 10:27:00 CST 2004

4.直接路径exp

花费时间:
Tue Apr 27 10:52:09 CST 2004 - Tue Apr 27 10:50:58 CST 2004 = 1.11
是 71/34 = 208.82352941176470588235294117647%

直接路径导出快于常规路径导出，但是仍然不敌expdp

$ cat bak4.sh
date
exp eygle/eygle file=big_big_table3.dmp tables=big_big_table direct=y
date

$ ./bak4.sh
Tue Apr 27 10:50:58 CST 2004

Export: Release 10.1.0.2.0 - Production on Tue Apr 27 10:50:58 2004

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

About to export specified tables via Direct Path ...
. . exporting table BIG_BIG_TABLE 1363292 rows exported
Export terminated successfully without warnings.
Tue Apr 27 10:52:09 CST 2004

5.文件大小

传统方式exp文件要大于expdp的文件大小
大约大出10M左右.

$ ls -al
total 741566
drwxr-xr-x 2 oracle dba 512 Apr 27 10:50 .
drwxr-xr-x 23 oracle dba 1024 Apr 26 22:53 ..
-rwxr-xr-x 1 oracle dba 120 Apr 27 10:21 bak.sh
-rwxr-xr-x 1 oracle dba 111 Apr 27 10:22 bak2.sh
-rwxr-xr-x 1 oracle dba 71 Apr 27 10:24 bak3.sh
-rwxr-xr-x 1 oracle dba 80 Apr 27 10:50 bak4.sh
-rw-r----- 1 oracle dba 122413056 Apr 27 10:21 big_big_table.dmp
-rw-r----- 1 oracle dba 122417152 Apr 27 10:23 big_big_table2.dmp
-rw-r--r-- 1 oracle dba 134604800 Apr 27 10:52 big_big_table3.dmp
-rw-r--r-- 1 oracle dba 965 Apr 27 10:23 export.log

以下是导入测试:

6. imp测试

花费时间: Tue Apr 27 11:15:11 CST 2004 - Tue Apr 27 11:08:24 CST 2004 = 6:47s

$ cat rev2.sh
date
imp eygle/eygle file=big_big_table3.dmp tables=big_big_table
date

$ ./rev2.sh
Tue Apr 27 11:08:24 CST 2004

Import: Release 10.1.0.2.0 - Production on Tue Apr 27 11:08:24 2004

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

Export file created by EXPORT:V10.01.00 via direct path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing EYGLE's objects into EYGLE
. . importing table "BIG_BIG_TABLE" 1363292 rows imported
Import terminated successfully without warnings.
Tue Apr 27 11:15:11 CST 2004
$

7. impdp

花费时间: Tue Apr 27 11:07:06 CST 2004 - Tue Apr 27 11:06:40 CST 2004 = 26s
与imp相比这个速度实在是惊人.
407/26 = 1565.3846153846153846153846153846%
无怪乎Oracle说impdp才是data pump真正杰出的地方(really stands out)

$ ./rev.sh
Tue Apr 27 11:06:40 CST 2004

Import: Release 10.1.0.2.0 - 64bit Production on Tuesday, 27 April, 2004 11:06

Copyright (c) 2003, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "EYGLE"."IMPTAB" successfully loaded/unloaded
Starting "EYGLE"."IMPTAB": eygle/******** dumpfile=big_big_table.dmp tables=big_big_table directory=dpdata job_name=imptab
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TBL_TABLE_DATA/TABLE/TABLE_DATA
. . imported "EYGLE"."BIG_BIG_TABLE" 116.6 MB 1363292 rows
Job "EYGLE"."IMPTAB" successfully completed at 11:07

Tue Apr 27 11:07:06 CST 2004

2004年6月26日 星期六

If you have any question,please mail to eygle@itpub.net .


10g新特性之-跨平台传输表空间-eygle.com

10g新特性之-跨平台传输表空间

1.准备工作:
查询源数据库平台信息

SQL> col platform_name for a40
SQL> SELECT d.PLATFORM_NAME, ENDIAN_FORMAT
2 FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
3 WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;

PLATFORM_NAME ENDIAN_FORMAT
---------------------------------------- --------------
Solaris[tm] OE (64-bit) Big

查询目标数据库平台信息

SQL> col platform_name for a40
SQL> SELECT d.PLATFORM_NAME, ENDIAN_FORMAT
2 FROM V$TRANSPORTABLE_PLATFORM tp, V$DATABASE d
3 WHERE tp.PLATFORM_NAME = d.PLATFORM_NAME;

PLATFORM_NAME ENDIAN_FORMAT
---------------------------------------- --------------
Microsoft Windows IA (32-bit) Little

查询Oracle10g支持的平台转换

SQL> select * from v$transportable_platform;

PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- ---------------------------------------- --------------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
10 Linux IA (32-bit) Little
6 AIX-Based Systems (64-bit) Big
3 HP-UX (64-bit) Big
5 HP Tru64 UNIX Little
4 HP-UX IA (64-bit) Big
11 Linux IA (64-bit) Little
15 HP Open VMS Little
8 Microsoft Windows IA (64-bit) Little

PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT
----------- ---------------------------------------- --------------
9 IBM zSeries Based Linux Big
13 Linux 64-bit for AMD Little
16 Apple Mac OS Big
12 Microsoft Windows 64-bit for AMD Little

2.创建一个独立的自包含表空间

用于测试

$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.1.0.2.0 - Production on Tue Apr 27 14:04:08 2004

Copyright (c) 1982, 2004, Oracle.?All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/eygle/system01.dbf
/opt/oracle/oradata/eygle/undotbs01.dbf
/opt/oracle/oradata/eygle/sysaux01.dbf
/opt/oracle/oradata/eygle/users01.dbf
/data1/oradata/systemfile/eygle01.dbf
/opt/oracle/oradata/eygle/EYGLE/datafile/o1_mf_test_03xv34ny_.dbf
/opt/oracle/oradata/eygle/EYGLE/datafile/o1_mf_itpub_03xv5g66_.dbf

7 rows selected.

SQL> create tablespace trans
2?datafile '/data1/oradata/systemfile/trans01.dbf'
3?size 10M;

Tablespace created.

SQL> create user trans identified by trans
2?default tablespace trans;

User created.

SQL> grant connect,resource to trans;

Grant succeeded.

SQL> connect trans/trans
Connected.

SQL> create table test as select * from user_objects;

Table created.

SQL> select?count(*) from test;

COUNT(*)
----------
1

SQL> select * from test;

OBJECT_NAME
--------------------------------------------------------------------------------
SUBOBJECT_NAME?OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE
------------------------------ ---------- -------------- -------------------
CREATED?LAST_DDL_TIM TIMESTAMP?STATUS?T G S
------------ ------------ ------------------- ------- - - -
TEST
15604?15604 TABLE
27-APR-04?27-APR-04?2004-04-27:14:05:42 VALID?N N N

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data

3.导出要传输的表空间

$ pwd
/opt/oracle
$ cd dpdata
$ ls
$ expdp eygle/eygle dumpfile=trans.dmp directory=dpdata transport_tablespace=trans
LRM-00101: unknown parameter name 'transport_tablespace'

$ expdp eygle/eygle dumpfile=trans.dmp directory=dpdata TRANSPORT_TABLESPACES=trans

Export: Release 10.1.0.2.0 - 64bit Production on Tuesday, 27 April, 2004 14:07

Copyright (c) 2003, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "EYGLE"."SYS_EXPORT_TRANSPORTABLE_01": eygle/******** dumpfile=trans.dmp directory=dpdata TRANSPORT_TABLESPACES=trans
ORA-39123: Data Pump transportable tablespace job aborted
ORA-29335: tablespace 'TRANS' is not read only

Job "EYGLE"."SYS_EXPORT_TRANSPORTABLE_01" stopped due to fatal error at 14:08

注意:传输表空间必须置为只读状态

$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.1.0.2.0 - Production on Tue Apr 27 14:08:13 2004

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> alter tablespace trans read only;

Tablespace altered.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

$ expdp eygle/eygle dumpfile=trans.dmp directory=dpdata TRANSPORT_TABLESPACES=trans

Export: Release 10.1.0.2.0 - 64bit Production on Tuesday, 27 April, 2004 14:08

Copyright (c) 2003, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "EYGLE"."SYS_EXPORT_TRANSPORTABLE_01": eygle/******** dumpfile=trans.dmp directory=dpdata TRANSPORT_TABLESPACES=trans
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/TTE_POSTINST/PLUGTS_BLK
Master table "EYGLE"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for EYGLE.SYS_EXPORT_TRANSPORTABLE_01 is:
/opt/oracle/dpdata/trans.dmp
Job "EYGLE"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 14:09

4.使用rman转换文件格式

$ rman target /

Recovery Manager: Release 10.1.0.2.0 - 64bit Production

Copyright (c) 1995, 2004, Oracle. All rights reserved.

connected to target database: EYGLE (DBID=1337390772)

RMAN> convert tablespace trans
2> to platform 'Microsoft Windows IA (32-bit)'
3> Format '/tmp/%U';

Starting backup at 27-APR-04
using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 devtype=DISK
channel ORA_DISK_1: starting datafile conversion
input datafile fno=00008 name=/data1/oradata/systemfile/trans01.dbf
converted datafile=/tmp/data_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01fk92hg
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Finished backup at 27-APR-04

RMAN> exit

Recovery Manager complete.

5.确认导出文件已生成

$ ls /tmp/data*
/tmp/data_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01fk92hg
$ ls -l /tmp/data*
-rw-r----- 1 oracle dba 10493952 Apr 27 14:12 /tmp/data_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01fk92hg
$ chmod 777 /tmp/data*
$ chmod 777 /opt/oracle/dpdata/*

6.通过ftp传输文件至目标主机

220 billing-center.hurray.com.cn FTP server (SunOS 5.8) ready.
User (172.16.33.32none)): gqgai
331 Password required for gqgai.
Password:
230 User gqgai logged in.
ftp> bin
200 Type set to I.
ftp> cd /tmp
250 CWD command successful.
ftp> mget data*
200 Type set to I.
mget data_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01fk92hg? y
200 PORT command successful.
150 Binary data connection for data_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01fk92hg (172.16.32.65,2885) (10493952 bytes).
226 Binary Transfer complete.
ftp: 10493952 bytes received in 15.90Seconds 659.87Kbytes/sec.
ftp> cd /opt/oracle/dpdata
250 CWD command successful.
ftp> ls
200 PORT command successful.
150 ASCII data connection for /bin/ls (172.16.32.65,2889) (0 bytes).
export.log
trans.dmp
226 ASCII Transfer complete.
ftp: 23 bytes received in 0.01Seconds 2.30Kbytes/sec.
ftp> bin
200 Type set to I.
ftp> mget trans.dmp
200 Type set to I.
mget trans.dmp? y
200 PORT command successful.
150 Binary data connection for trans.dmp (172.16.32.65,2893) (73728 bytes).
226 Binary Transfer complete.
ftp: 73728 bytes received in 0.03Seconds 2457.60Kbytes/sec.
ftp> bye
221 Goodbye.

7.使用rman在目标数据库转换文件

E:\Oracle\oradata\vilen\dpdata>rman target /

恢复管理器: 版本10.1.0.2.0 - Production

Copyright (c) 1995, 2004, Oracle. All rights reserved.

连接到目标数据库: VILEN (DBID=1587222708)

RMAN> CONVERT DATAFILE 'E:\Oracle\oradata\vilen\dpdata\data_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01fk92hg'
2> DB_FILE_NAME_CONVERT
3> 'E:\Oracle\oradata\vilen\dpdata\data_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01fk92hg','E:\Oracle\oradata\vilen\VILEN\DATAFILE\trans01.dbf';

启动 backup 于 27-4月 -04
使用通道 ORA_DISK_1
通道 ORA_DISK_1: 启动数据文件转换
输出文件名=E:\ORACLE\ORADATA\VILEN\DPDATA\DATA_D-EYGLE_I-1337390772_TS-TRANS_FNO-8_01FK92HG
已转换的数据文件 = E:\ORACLE\ORADATA\VILEN\VILEN\DATAFILE\TRANS01.DBF
通道 ORA_DISK_1: 数据文件转换完毕, 经过时间: 00:00:04
完成 backup 于 27-4月 -04

RMAN>

8.在目标数据库plugin数据文件

注意目标数据库中的目标用户必须存在
否则会报错.

E:\Oracle\oradata\vilen\dpdata>impdp eygle/eygle dumpfile=trans.dmp directory=dpdata transport_datafiles='E:\Oracle\orad
ata\vilen\VILEN\DATAFILE\TRANS01.DBF'

Import: Release 10.1.0.2.0 - Production on 星期二, 27 4月, 2004 15:02

Copyright (c) 2003, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
已成功加载/卸载了主表 "EYGLE"."SYS_IMPORT_TRANSPORTABLE_01"
启动 "EYGLE"."SYS_IMPORT_TRANSPORTABLE_01": eygle/******** dumpfile=trans.dmp directory=dpdata transport_datafiles='E:\
Oracle\oradata\vilen\VILEN\DATAFILE\TRANS01.DBF'
处理对象类型 TRANSPORTABLE_EXPORT/PLUGTS_BLK
ORA-39123: 数据泵可传输的表空间作业中止
ORA-29342: 数据库中不存在用户 TRANS

作业 "EYGLE"."SYS_IMPORT_TRANSPORTABLE_01" 因致命错误于 15:02 停止

E:\Oracle\oradata\vilen\dpdata>sqlplus "/ as sysdba"

SQL*Plus: Release 10.1.0.2.0 - Production on 星期二 4月 27 15:03:03 2004

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

连接到:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> create user trans identified by trans;

用户已创建。

SQL> grant connect,resource to trans;

授权成功。

SQL> exit
从 Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options 断开

E:\Oracle\oradata\vilen\dpdata>impdp eygle/eygle dumpfile=trans.dmp directory=dpdata transport_datafiles='E:\Oracle\orad
ata\vilen\VILEN\DATAFILE\TRANS01.DBF'

Import: Release 10.1.0.2.0 - Production on 星期二, 27 4月, 2004 15:03

Copyright (c) 2003, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
已成功加载/卸载了主表 "EYGLE"."SYS_IMPORT_TRANSPORTABLE_01"
启动 "EYGLE"."SYS_IMPORT_TRANSPORTABLE_01": eygle/******** dumpfile=trans.dmp directory=dpdata transport_datafiles='E:\
Oracle\oradata\vilen\VILEN\DATAFILE\TRANS01.DBF'
处理对象类型 TRANSPORTABLE_EXPORT/PLUGTS_BLK
处理对象类型 TRANSPORTABLE_EXPORT/TABLE
处理对象类型 TRANSPORTABLE_EXPORT/TTE_POSTINST/PLUGTS_BLK
作业 "EYGLE"."SYS_IMPORT_TRANSPORTABLE_01" 已于 15:03 成功完成

9.检查数据

E:\Oracle\oradata\vilen\dpdata>sqlplus trans/trans

SQL*Plus: Release 10.1.0.2.0 - Production on 星期二 4月 27 15:03:50 2004

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

连接到:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select count(*) from test;

COUNT(*)
----------
1

SQL> exit
从 Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options 断开

E:\Oracle\oradata\vilen\dpdata>

可以选择把表空间更改为读写

SQL> alter tablespace trans read write;

表空间已更改。

10.总结

10g的表空间跨平台迁移，较9i就是增加了一个使用Rman进行的文件格式转换的过程.
实际上也就是转换了数据文件头的格式信息而已.

然而这一简单改进带来的方便之处是显而易见的.

2004年6月26日 星期六

If you have any question,please mail to eygle@itpub.net .


10g新特性之-SYSAUX表空间-eygle.com

10g新特性之-SYSAUX表空间

Oracle10g新特性-SYSAUX表空间-SYS Auxiliary

SYSAUX表空间在Oracle Database 10g中引入,作为SYSTEM表空间的辅助表空间.

以前一些使用独立表空间或系统表空间的数据库组件现在在SYSAUX表空间中创建.
通过分离这些组件和功能，SYSTEM表空间的负荷得以减轻.反复创建一些相关对象及组件引起SYSTEM表空间的碎片问题得以避免。

如果SYSAUX表空间不可用,数据库核心功能将保持有效;使用SYSAUX表空间的特点将会失败或功能受限.

我们看一下数据库创建脚本：

CREATE DATABASE "eygle"
MAXINSTANCES 8
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
DATAFILE '/opt/oracle/oradata/eygle/system01.dbf'
SIZE 300M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/opt/oracle/oradata/eygle/sysaux01.dbf'
SIZE 120M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED--SYSAUX表空间的创建
DEFAULT TEMPORARY TABLESPACE TEMP
TEMPFILE '/opt/oracle/oradata/eygle/temp01.dbf' SIZE 20M REUSE
AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE "UNDOTBS1" DATAFILE '/opt/oracle/oradata/eygle/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
LOGFILE GROUP 1 ('/opt/oracle/oradata/eygle/redo01.log') SIZE 10240K,
GROUP 2 ('/opt/oracle/oradata/eygle/redo02.log') SIZE 10240K,
GROUP 3 ('/opt/oracle/oradata/eygle/redo03.log') SIZE 10240K
USER SYS IDENTIFIED BY "&&sysPassword" USER SYSTEM IDENTIFIED BY "&&systemPassword";

以下是使用SYSAUX表空间的数据库组件:

使用SYSAUX表空间的组件				以前版本所在表空间
Analytical Workspace Object Table	           SYSTEM
Enterprise Manager Repository	               OEM_REPOSITORY
LogMiner			                           SYSTEM
Logical Standby		               	       SYSTEM
OLAP API History Tables		               CWMLITE
Oracle Data Mining		                   ODM
Oracle Spatial		                       SYSTEM
Oracle Streams		               	       SYSTEM
Oracle Text			                       DRSYS
Oracle Ultra Search		                   DRSYS
Oracle interMedia ORDPLUGINS Components      SYSTEM
Oracle interMedia ORDSYS Components          SYSTEM
Oracle interMedia SI_INFORMTN_SCHEMA Components	SYSTEM
Server Manageability Components	           New in Oracle Database 10g
Statspack Repository		                   User-defined
Unified Job Scheduler		                   New in Oracle Database 10g
Workspace Manager	                           SYSTEM

新增的V$SYSAUX_OCCUPANTS视图可以用来查看这些信息

SQL> select OCCUPANT_NAME,OCCUPANT_DESC,SCHEMA_NAME
  2  from V$SYSAUX_OCCUPANTS;

OCCUPANT_NAME OCCUPANT_DESC                                                    SCHEMA_NAME
------------- ---------------------------------------------------------------- ------------------
LOGMNR        LogMiner                                                         SYSTEM
LOGSTDBY      Logical Standby                                                  SYSTEM
STREAMS       Oracle Streams                                                   SYS
AO            Analytical Workspace Object Table                                SYS
XSOQHIST      OLAP API History Tables                                          SYS
SM/AWR        Server Manageability - Automatic Workload Repository             SYS
SM/ADVISOR    Server Manageability - Advisor Framework                         SYS
SM/OPTSTAT    Server Manageability - Optimizer Statistics History              SYS
SM/OTHER      Server Manageability - Other Components                          SYS
STATSPACK     Statspack Repository                                             PERFSTAT
ODM           Oracle Data Mining                                               DMSYS

OCCUPANT_NAME OCCUPANT_DESC                                                    SCHEMA_NAME
------------- ---------------------------------------------------------------- ------------------
SDO           Oracle Spatial                                                   MDSYS
WM            Workspace Manager                                                WMSYS
ORDIM         Oracle interMedia ORDSYS Components                              ORDSYS
ORDIM/PLUGINS Oracle interMedia ORDPLUGINS Components                          ORDPLUGINS
ORDIM/SQLMM   Oracle interMedia SI_INFORMTN_SCHEMA Components                  SI_INFORMTN_SCHEMA
EM            Enterprise Manager Repository                                    SYSMAN
TEXT          Oracle Text                                                      CTXSYS
ULTRASEARCH   Oracle Ultra Search                                              WKSYS
JOB_SCHEDULER Unified Job Scheduler                                            SYS

20 rows selected.

SYAAUX表空间具有如下限制:

1. 不能删除
SQL> drop tablespace SYSAUX including contents and datafiles;
drop tablespace SYSAUX including contents and datafiles
*
ERROR at line 1:
ORA-13501: Cannot drop SYSAUX tablespace

2. 不能重命名
SQL> alter tablespace SYSAUX rename to OPT_TBS;
alter tablespace SYSAUX rename to OPT_TBS
*
ERROR at line 1:
ORA-13502: Cannot rename SYSAUX tablespace

3. 不能置为read only
SQL> alter tablesapce SYSAUX read only;
alter tablesapce SYSAUX read only
*
ERROR at line 1:
ORA-00940: invalid ALTER command

如果希望转移这些系统对象的表空间，可以使用相应得系统包实现:

SQL> set linesize 120
SQL> col schema_name for a18
SQL> col occupant_name for a13
SQL> col move_procedure for a32
SQL> SELECT    occupant_name, schema_name, move_procedure,space_usage_kbytes
  2  FROM      v$sysaux_occupants
  3  ORDER BY  1
  4  /

OCCUPANT_NAME SCHEMA_NAME        MOVE_PROCEDURE                   SPACE_USAGE_KBYTES
------------- ------------------ -------------------------------- ------------------
AO            SYS                DBMS_AW.MOVE_AWMETA                             768
EM            SYSMAN             emd_maintenance.move_em_tblspc                    0
JOB_SCHEDULER SYS                                                                256
LOGMNR        SYSTEM             SYS.DBMS_LOGMNR_D.SET_TABLESPACE               7488------------注意这里
LOGSTDBY      SYSTEM             SYS.DBMS_LOGSTDBY.SET_TABLESPACE                  0
ODM           DMSYS              MOVE_ODM                                          0
ORDIM         ORDSYS                                                               0
ORDIM/PLUGINS ORDPLUGINS                                                           0
ORDIM/SQLMM   SI_INFORMTN_SCHEMA                                                   0
SDO           MDSYS              MDSYS.MOVE_SDO                                    0
SM/ADVISOR    SYS                                                               5760

OCCUPANT_NAME SCHEMA_NAME        MOVE_PROCEDURE                   SPACE_USAGE_KBYTES
------------- ------------------ -------------------------------- ------------------
SM/AWR        SYS                                                              62848
SM/OPTSTAT    SYS                                                               9344
SM/OTHER      SYS                                                               2816
STATSPACK     PERFSTAT                                                             0
STREAMS       SYS                                                                192
TEXT          CTXSYS             DRI_MOVE_CTXSYS                                   0
ULTRASEARCH   WKSYS              MOVE_WK                                           0
WM            WMSYS              DBMS_WM.move_proc                              6656
XSOQHIST      SYS                DBMS_XSOQ.OlapiMoveProc                         768

20 rows selected.

SQL> exec SYS.DBMS_LOGMNR_D.SET_TABLESPACE('USERS');

PL/SQL procedure successfully completed.

SQL> set linesize 120
SQL> col schema_name for a18
SQL> col occupant_name for a13
SQL> col move_procedure for a32
SQL> SELECT    occupant_name, schema_name, move_procedure,space_usage_kbytes
  2  FROM      v$sysaux_occupants
  3  ORDER BY  1
  4  /

OCCUPANT_NAME SCHEMA_NAME        MOVE_PROCEDURE                   SPACE_USAGE_KBYTES
------------- ------------------ -------------------------------- ------------------
AO            SYS                DBMS_AW.MOVE_AWMETA                             768
EM            SYSMAN             emd_maintenance.move_em_tblspc                    0
JOB_SCHEDULER SYS                                                                256
LOGMNR        SYSTEM             SYS.DBMS_LOGMNR_D.SET_TABLESPACE                  0------------注意这里
LOGSTDBY      SYSTEM             SYS.DBMS_LOGSTDBY.SET_TABLESPACE                  0
ODM           DMSYS              MOVE_ODM                                          0
ORDIM         ORDSYS                                                               0
ORDIM/PLUGINS ORDPLUGINS                                                           0
ORDIM/SQLMM   SI_INFORMTN_SCHEMA                                                   0
SDO           MDSYS              MDSYS.MOVE_SDO                                    0
SM/ADVISOR    SYS                                                               5760

OCCUPANT_NAME SCHEMA_NAME        MOVE_PROCEDURE                   SPACE_USAGE_KBYTES
------------- ------------------ -------------------------------- ------------------
SM/AWR        SYS                                                              62848
SM/OPTSTAT    SYS                                                               9344
SM/OTHER      SYS                                                               2816
STATSPACK     PERFSTAT                                                             0
STREAMS       SYS                                                                192
TEXT          CTXSYS             DRI_MOVE_CTXSYS                                   0
ULTRASEARCH   WKSYS              MOVE_WK                                           0
WM            WMSYS              DBMS_WM.move_proc                              6656
XSOQHIST      SYS                DBMS_XSOQ.OlapiMoveProc                         768

20 rows selected.

复位:

SQL> exec SYS.DBMS_LOGMNR_D.SET_TABLESPACE('SYSAUX');

PL/SQL procedure successfully completed.

SQL> set linesize 120
SQL> col schema_name for a18
SQL> col occupant_name for a13
SQL> col move_procedure for a32
SQL> SELECT    occupant_name, schema_name, move_procedure,space_usage_kbytes
  2  FROM      v$sysaux_occupants
  3  ORDER BY  1
  4  /

OCCUPANT_NAME SCHEMA_NAME        MOVE_PROCEDURE                   SPACE_USAGE_KBYTES
------------- ------------------ -------------------------------- ------------------
AO            SYS                DBMS_AW.MOVE_AWMETA                             768
EM            SYSMAN             emd_maintenance.move_em_tblspc                    0
JOB_SCHEDULER SYS                                                                256
LOGMNR        SYSTEM             SYS.DBMS_LOGMNR_D.SET_TABLESPACE               7488
LOGSTDBY      SYSTEM             SYS.DBMS_LOGSTDBY.SET_TABLESPACE                  0
ODM           DMSYS              MOVE_ODM                                          0
ORDIM         ORDSYS                                                               0
ORDIM/PLUGINS ORDPLUGINS                                                           0
ORDIM/SQLMM   SI_INFORMTN_SCHEMA                                                   0
SDO           MDSYS              MDSYS.MOVE_SDO                                    0
SM/ADVISOR    SYS                                                               5760

OCCUPANT_NAME SCHEMA_NAME        MOVE_PROCEDURE                   SPACE_USAGE_KBYTES
------------- ------------------ -------------------------------- ------------------
SM/AWR        SYS                                                              62848
SM/OPTSTAT    SYS                                                               9344
SM/OTHER      SYS                                                               2816
STATSPACK     PERFSTAT                                                             0
STREAMS       SYS                                                                192
TEXT          CTXSYS             DRI_MOVE_CTXSYS                                   0
ULTRASEARCH   WKSYS              MOVE_WK                                           0
WM            WMSYS              DBMS_WM.move_proc                              6656
XSOQHIST      SYS                DBMS_XSOQ.OlapiMoveProc                         768

20 rows selected.

结论:

这是一个管理及规划上的改进,进一步独立SYSTEM表空间,保证其存储及性能.

我们在做数据库规划时大可借鉴Oracle这个改进,分离重要数据及次要数据，分离稳定结构及频繁变化结构，尽量减少对重要数据及结构的影响。

2004年6月26日 星期六

If you have any question,please mail to eygle@itpub.net .


Oracle10g安装与升级之一-www.eygle.com

Oracle10g安装与升级之一

Thursday, 2004-09-09 15:58 eygle


Oracle10g安装与升级之二-www.eygle.com

Oracle10g安装与升级之二

Thursday, 2004-09-09 16:03 eygle


Oracle10g安装与升级之三-www.eygle.com

Oracle10g安装与升级之三

Thursday, 2004-09-09 16:05 eygle


Oracle10g安装与升级之四-www.eygle.com

Oracle10g安装与升级之四

Thursday, 2004-09-09 16:06 eygle


如何获得跟踪文件名称-www.eygle.com

如何获得跟踪文件名称

Friday, 2004-10-08 16:41 Eygle

当我们使用sql_trace/10046等事件进行进程跟踪时，会生成跟踪文件.跟踪文件名称由以下几部分组成:

<sid>_ora_<pid>.trc

以下脚本用户获得跟踪文件名称:

For Unix:

$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Oct 8 12:08:09 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> set echo on
SQL> @gettrcnameunix
SQL> SELECT       d.VALUE
  2         || '/'
  3         || LOWER (RTRIM (i.INSTANCE, CHR (0)))
  4         || '_ora_'
  5         || p.spid
  6         || '.trc' trace_file_name
  7    FROM (SELECT p.spid
  8            FROM v$mystat m, v$session s, v$process p
  9           WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
 10         (SELECT t.INSTANCE
 11            FROM v$thread t, v$parameter v
 12           WHERE v.NAME = 'thread'
 13             AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
 14         (SELECT VALUE
 15            FROM v$parameter
 16           WHERE NAME = 'user_dump_dest') d
 17  /

TRACE_FILE_NAME
--------------------------------------------------------------------------------
/opt/oracle/admin/hsbill/udump/hsbill_ora_29630.trc

For Nt:

SQL> SELECT    d.VALUE
  2         || '\'
  3         || LOWER (RTRIM (i.INSTANCE, CHR (0)))
  4         || '_ora_'
  5         || p.spid
  6         || '.trc' trace_file_name
  7    FROM (SELECT p.spid
  8            FROM v$mystat m, v$session s, v$process p
  9           WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
 10         (SELECT t.INSTANCE
 11            FROM v$thread t, v$parameter v
 12           WHERE v.NAME = 'thread'
 13             AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
 14         (SELECT VALUE
 15            FROM v$parameter
 16           WHERE NAME = 'user_dump_dest') d
 17  /

TRACE_FILE_NAME
--------------------------------------------------------------------------------
e:\oracle\admin\eygle\udump\eygle_ora_3084.trc

你可以在这里下载以上脚本:ForUnix ForNt

本文作者:
eygle,Oracle技术关注者,来自中国最大的Oracle技术论坛itpub.
http://www.eygle.com/是作者的个人站点.你可通过mailto:eygle.com@gmail.com来联系作者.欢迎技术探讨交流以及链接交换.

原文出处:

http://www.eygle.com/faq/How.To.Get.Tracefile.Name.htm


Use.Nt.Tools.2.Manage.Oracle-www.eygle.com

使用Windows工具管理Nt上的Oracle数据库

Tuesday, 2004-10-05 14:38 Eygle

1.TOP

Top 工具可以监视最消耗系统资源的进程

Pid 即process id，Windows是多线程服务器,每个进程包含一系列线程，这个与UNIX不同，Unix每个Oralce进程独立存在，在Nt上所有线程由Oralce进程衍生。

所以只用TOP工具我们还无法找出每个连接的用户进程。

71% 00000000?1?16384?0?8:52:53.936 No Name Found
0% 00000008?4116?282624?24576?0:00:45.164 System
1% 000000B8?27023?991232 2207744?0:03:10.313 CSRSS.EXE
0% 00000524?1844 2035712 3137536?0:00:11.726 rundll32.exe
0% 0000032C?1002 1765376 1380352?0:00:08.432 AOM.exe
0% 000004E8?773695 7610368 8146944?0:04:26.533 XDICT.EXE
0% 00000720?583880 5079040 33280000?0:08:29.122 NetCaptor.exe
23% 000006F4?11882 37056512 79757312?0:00:07.661 oracle.exe
0% 00000420?1622 1478656 2420736?0:00:00.170 SQLPLUS.EXE

如果windows上由于某个进程的sql或其他问题导致资源过度占用或消耗,比如如下这样一条语句,那么我们怎样来找到这条问题sql呢?

2.QSLICE

找到最消耗资源的线程号，本例中为（6ec），为16进制，需要转换，v$process视图中的进程ID为十进制

使用getsql.sql脚本即可获得当前正在执行的SQL语句：

REM getsql.sql
REM author eygle
REM 在windows上,已知进程ID,得到当前正在执行的语句
REM 在windows上,进程ID为16进制,需要转换,在UNIX直接为10进制
SELECT   /*+ ORDERED */
         sql_text
    FROM v$sqltext a
   WHERE (a.hash_value, a.address) IN (
            SELECT DECODE (sql_hash_value,
                           0, prev_hash_value,
                           sql_hash_value
                          ),
                   DECODE (sql_hash_value, 0, prev_sql_addr, sql_address)
              FROM v$session b
             WHERE b.paddr = (SELECT addr
                                FROM v$process c
                               WHERE c.spid = TO_NUMBER ('&pid', 'xxxx')))
ORDER BY piece ASC
/

运行以上脚本:

ok,找到这最消耗资源的问题SQL接下来就可以进行针对性调整了.

相关工具下载地址：

http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/qslice-o.asp


Use.Nid.to.Change.your.dbname-www.eygle.com

Use Nid to Change dbname

Tuesday, 2004-10-05 13:40 Eygle

Nid是Oracle从9iR2开始提供的工具，可以用来更改数据库名称，而无需通过之前重建控制文件等繁琐方式.
需要说明的是，虽然这个工具来自9iR2，但是仍然可以被用于Oracle8i.

先看一下帮助:

C:\>nid -help
DBNEWID: Release 10.1.0.2.0 - Production
Copyright (c) 2001, 2004, Oracle.  All rights reserved.

关键字      说明                    (默认值)
----------------------------------------------------
TARGET      用户名/口令              (无)
DBNAME      新的数据库名             (无)
LOGFILE     输出日志                     (无)
REVERT      还原失败的更改            否
SETNAME     仅设置新的数据库名        否
APPEND      附加至输出日志            否
HELP        显示这些消息              否

我们通过范例来看一下用法:

1．数据库当前设置

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE    9.2.0.1.0       Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      eyglev
global_names                         boolean     FALSE
instance_name                        string      eyglev
lock_name_space                      string
log_file_name_convert                string
oracle_trace_collection_name         string
oracle_trace_facility_name           string      oracled
plsql_native_make_file_name          string
service_names                        string      eyglev

2．Shutdown数据库

SQL> connect sys/orasys as sysdba
Connected.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

3．Startup mount

SQL> startup mount
ORACLE instance started.

Total System Global Area 135338868 bytes
Fixed Size 453492 bytes
Variable Size 109051904 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.

4. 使用NID更改

SQL> host
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版权所有 1985-2000 Microsoft Corp.

C:\>nid target=sys/orasys dbname=eyglen
DBNEWID: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

Connected to database EYGLEV (DBID=677189177)

Control Files in database:
    E:\ORACLE\ORADATA\EYGLEN\CONTROL01.CTL
    E:\ORACLE\ORADATA\EYGLEN\CONTROL02.CTL
    E:\ORACLE\ORADATA\EYGLEN\CONTROL03.CTL

Change database ID and database name EYGLEV to EYGLEN? (Y/[N]) => Y

Proceeding with operation
Changing database ID from 677189177 to 3955758099
Changing database name from EYGLEV to EYGLEN
    Control File E:\ORACLE\ORADATA\EYGLEN\CONTROL01.CTL - modified
    Control File E:\ORACLE\ORADATA\EYGLEN\CONTROL02.CTL - modified
    Control File E:\ORACLE\ORADATA\EYGLEN\CONTROL03.CTL - modified
    Datafile E:\ORACLE\ORADATA\EYGLEN\SYSTEM01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\UNDOTBS01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\CWMLITE01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\DRSYS01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\INDX01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\ODM01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\TOOLS01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\USERS01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\XDB01.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\EYGLE.DBF - dbid changed, wrote new name
    Datafile E:\ORACLE\ORADATA\EYGLEN\TEMP01.DBF - dbid changed, wrote new name
    Control File E:\ORACLE\ORADATA\EYGLEN\CONTROL01.CTL - dbid changed, wrote new name
    Control File E:\ORACLE\ORADATA\EYGLEN\CONTROL02.CTL - dbid changed, wrote new name
    Control File E:\ORACLE\ORADATA\EYGLEN\CONTROL03.CTL - dbid changed, wrote new name

Database name changed to EYGLEN.
Modify parameter file and generate a new password file before restarting.
Database ID for database EYGLEN changed to 3955758099.
All previous backups and archived redo logs for this database are unusable.
Shut down database and open with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

5．Shutdown database

SQL> shutdown immediate
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.

6．修改初始化参数文件、spfile文件（init.ora/spfile）

###########################################
instance_name=eyglen
#instance_name=eyglev

###########################################
db_domain=""
db_name=eyglen
# db_name=eyglev
###########################################

7．重建spfile文件
如果你没有使用spfile，当然无需重建，跳至8

SQL> startup pfile=E:\Oracle\admin\eyglen\pfile\init.ora
ORACLE instance started.

Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
ORA-01991: invalid password file 'e:\oracle\Ora9iR2\DATABASE\PWDeyglen.ORA'

SQL> CREATE SPFILE='E:\Oracle\Ora9iR2\database\SPFILEEYGLEN.ORA' FROM
  2  PFILE='E:\Oracle\admin\eyglen\pfile\init.ora';

File created.

8．重建口令文件

SQL> host
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版权所有 1985-2000 Microsoft Corp.

C:\>orapwd file=E:\Oracle\Ora9iR2\database\PWDeyglen.ORA password=oracle entries=5

9.shutdown数据库
如果不使用spfile,则可以跳至10

SQL> shutdown immediate
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.

10．Startup mount,resetlogs打开

SQL> startup mount
ORACLE instance started.

Total System Global Area  135338868 bytes
Fixed Size                   453492 bytes
Variable Size             109051904 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes
Database mounted.
SQL> alter database open resetlogs
  2  /

Database altered.

SQL>

11．修改后的参数

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      eyglen
global_names                         boolean     FALSE
instance_name                        string      eyglen
lock_name_space                      string
log_file_name_convert                string
oracle_trace_collection_name         string
oracle_trace_facility_name           string      oracled
plsql_native_make_file_name          string
service_names                        string      eyglen

12．对数据库做个全备份

附：使用nid更改817的数据库

1． 更改前

SVRMGR> startup mount
已启动 ORACLE 实例。
系统全局区域合计有                         61970460个字节
Fixed Size                                          75804个字节
Variable Size                                    17645568个字节
Database Buffers                                 44171264个字节
Redo Buffers                                        77824个字节
已装入数据库。
SVRMGR> show parameter name
NAME                                TYPE    VALUE
----------------------------------- ------- ------------------------------
db_file_name_convert                字符串
db_name                             字符串  vilen
global_names                        布尔值  TRUE
instance_name                       字符串  vilen
lock_name_space                     字符串
log_file_name_convert               字符串
oracle_trace_collection_name        字符串
oracle_trace_facility_name          字符串  oracled
service_names                       字符串  vilen
SVRMGR>

2． 修改

C:\>nid target=sys/orasys@vilen dbname=vilene
DBNEWID: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.

Connected to database VILEN (DBID=1535443189)

Control Files in database:
    C:\ORACLE\ORADATA\VILEN\CONTROL01.CTL
    C:\ORACLE\ORADATA\VILEN\CONTROL02.CTL
    C:\ORACLE\ORADATA\VILEN\CONTROL03.CTL

Change database ID and database name VILEN to VILENE? (Y/[N]) => Y

Proceeding with operation
Changing database ID from 1535443189 to 681857412
Changing database name from VILEN to VILENE
    Control File C:\ORACLE\ORADATA\VILEN\CONTROL01.CTL - modified
    Control File C:\ORACLE\ORADATA\VILEN\CONTROL02.CTL - modified
    Control File C:\ORACLE\ORADATA\VILEN\CONTROL03.CTL - modified
    Datafile C:\ORACLE\ORADATA\VILEN\SYSTEM01.DBF - dbid changed, wrote new name
    Datafile C:\ORACLE\ORADATA\VILEN\RBS01.DBF - dbid changed, wrote new name
    Datafile C:\ORACLE\ORADATA\VILEN\USERS01.DBF - dbid changed, wrote new name
    Datafile C:\ORACLE\ORADATA\VILEN\TEMP01.DBF - dbid changed, wrote new name
    Datafile C:\ORACLE\ORADATA\VILEN\TOOLS01.DBF - dbid changed, wrote new name
    Datafile C:\ORACLE\ORADATA\VILEN\INDX01.DBF - dbid changed, wrote new name
    Datafile C:\ORACLE\ORADATA\VILEN\EQSP01.DBF - dbid changed, wrote new name
    Datafile C:\ORACLE\ORADATA\VILEN\PERFSTAT.DBF - dbid changed, wrote new name
    Control File C:\ORACLE\ORADATA\VILEN\CONTROL01.CTL - dbid changed, wrote new name
    Control File C:\ORACLE\ORADATA\VILEN\CONTROL02.CTL - dbid changed, wrote new name
    Control File C:\ORACLE\ORADATA\VILEN\CONTROL03.CTL - dbid changed, wrote new name

Database name changed to VILENE.
Modify parameter file and generate a new password file before restarting.
Database ID for database VILENE changed to 681857412.
All previous backups and archived redo logs for this database are unusable.
Shut down database and open with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.

3． 关闭数据库

SVRMGR> shutdown immediate
ORA-01109: 数据库未打开
已卸下数据库。
已关闭 ORACLE 实例。

4． 修改参数文件

db_name = "vilene"
#db_name = "vilen"

instance_name = vilene
#instance_name = vilen

5． 重建口令文件

C:\oracle\database>orapwd file=PWDvilen.ORA password=oracle entries=5

C:\oracle\database>

6． mount数据库

SVRMGR> startup mount
ORACLE instance started.
Total System Global Area                         61970460 bytes
Fixed Size                                          75804 bytes
Variable Size                                    17645568 bytes
Database Buffers                                 44171264 bytes
Redo Buffers                                        77824 bytes
Database mounted.

7． 打开数据库

SVRMGR> alter database open resetlogs
2> /
Statement processed.

8． 修改后的参数

SVRMGR> show parameter name
NAME                                TYPE    VALUE
----------------------------------- ------- ------------------------------
db_file_name_convert                string
db_name                             string  vilene
global_names                        boolean TRUE
instance_name                       string  vilene
lock_name_space                     string
log_file_name_convert               string
oracle_trace_collection_name        string
oracle_trace_facility_name          string  oracled
service_names                       string  vilen


在RAC环境中如何管理日志(redolog file)组-www.eygle.com

在RAC环境中如何管理日志(redolog file)组

Tuesday, 2004-09-14 11:52 Eygle

本文简单介绍在RAC裸设备环境下如何管理日志文件(redolog file)

本文环境:Oracle9i Rac + VCS4.0 + VxVM4.0 + Solaris9.0 + SunFire210

1.首先可以查看当前裸设备情况

# vxprint
Disk group: oradg

TY NAME         ASSOC        KSTATE   LENGTH   PLOFFS   STATE    TUTIL0  PUTIL0
dg oradg        oradg        -        -        -        -        -       -

dm oradg01      c2t0d2s2     -        244143872 -       -        -       -

v  ctlfile1     gen          ENABLED  204800   -        ACTIVE   -       -
pl ctlfile1-01  ctlfile1     ENABLED  204800   -        ACTIVE   -       -
sd oradg01-13   ctlfile1-01  ENABLED  204800   0        -        -       -

v  ctlfile2     gen          ENABLED  204800   -        ACTIVE   -       -
pl ctlfile2-01  ctlfile2     ENABLED  204800   -        ACTIVE   -       -
sd oradg01-14   ctlfile2-01  ENABLED  204800   0        -        -       -

v  redo101      gen          ENABLED  204800   -        ACTIVE   -       -
pl redo101-01   redo101      ENABLED  204800   -        ACTIVE   -       -
sd oradg01-04   redo101-01   ENABLED  204800   0        -        -       -

v  redo102      gen          ENABLED  204800   -        ACTIVE   -       -
pl redo102-01   redo102      ENABLED  204800   -        ACTIVE   -       -
sd oradg01-05   redo102-01   ENABLED  204800   0        -        -       -

v  redo103      gen          ENABLED  204800   -        ACTIVE   -       -
pl redo103-01   redo103      ENABLED  204800   -        ACTIVE   -       -
sd oradg01-06   redo103-01   ENABLED  204800   0        -        -       -

v  redo201      gen          ENABLED  204800   -        ACTIVE   -       -
pl redo201-01   redo201      ENABLED  204800   -        ACTIVE   -       -
sd oradg01-07   redo201-01   ENABLED  204800   0        -        -       -

v  redo202      gen          ENABLED  204800   -        ACTIVE   -       -
pl redo202-01   redo202      ENABLED  204800   -        ACTIVE   -       -
sd oradg01-08   redo202-01   ENABLED  204800   0        -        -       -

v  redo203      gen          ENABLED  204800   -        ACTIVE   -       -
pl redo203-01   redo203      ENABLED  204800   -        ACTIVE   -       -
sd oradg01-09   redo203-01   ENABLED  204800   0        -        -       -

v  spfile       gen          ENABLED  204800   -        ACTIVE   -       -
pl spfile-01    spfile       ENABLED  204800   -        ACTIVE   -       -
sd oradg01-12   spfile-01    ENABLED  204800   0        -        -       -

v  srvcfg       gen          ENABLED  1024000  -        ACTIVE   -       -
pl srvcfg-01    srvcfg       ENABLED  1024000  -        ACTIVE   -       -
sd oradg01-15   srvcfg-01    ENABLED  1024000  0        -        -       -

v  system       gen          ENABLED  1638400  -        ACTIVE   -       -
pl system-01    system       ENABLED  1638400  -        ACTIVE   -       -
sd oradg01-01   system-01    ENABLED  1638400  0        -        -       -

v  temp         gen          ENABLED  2048000  -        ACTIVE   -       -
pl temp-01      temp         ENABLED  2048000  -        ACTIVE   -       -
sd oradg01-02   temp-01      ENABLED  2048000  0        -        -       -

v  undo11       gen          ENABLED  16777216 -        ACTIVE   -       -
pl undo11-01    undo11       ENABLED  16777216 -        ACTIVE   -       -
sd oradg01-10   undo11-01    ENABLED  2048000  0        -        -       -
sd oradg01-17   undo11-01    ENABLED  14729216 2048000  -        -       -

v  undo21       gen          ENABLED  2048000  -        ACTIVE   -       -
pl undo21-01    undo21       ENABLED  2048000  -        ACTIVE   -       -
sd oradg01-11   undo21-01    ENABLED  2048000  0        -        -       -

v  users        gen          ENABLED  16777216 -        ACTIVE   -       -
pl users-01     users        ENABLED  16777216 -        ACTIVE   -       -
sd oradg01-03   users-01     ENABLED  2048000  0        -        -       -
sd oradg01-16   users-01     ENABLED  14729216 2048000  -        -       -

2.分配新的裸设备并设置相应的权限

这一步需要以root身份执行

# vxassist -g oradg -U gen make redo104 100m
# vxassist -g oradg -U gen make redo105 100m
# vxedit -g oradg set user=oracle mode=644 redo104
# vxedit -g oradg set user=oracle mode=644 redo105

3.重新规划redolog file组

$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Tue Sep 14 10:02:47 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Real Application Clusters option
JServer Release 9.2.0.4.0 - Production

SQL> set linesize 120
SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1       6313   52428800          1 NO  ACTIVE                 3193855 14-SEP-04
         2          1       6312   52428800          1 NO  INACTIVE               3191691 14-SEP-04
         5          1       6314   52428800          1 NO  CURRENT                3196041 14-SEP-04
         3          2         17   10485760          1 NO  CURRENT                3016310 14-SEP-04
         4          2         16   10485760          1 NO  INACTIVE               1619198 13-SEP-04

SQL> alter database add logfile thread 1 group 6 ('/dev/vx/rdsk/oradg/redo104') size 90M;

Database altered.

SQL> alter database add logfile thread 1 group 7 ('/dev/vx/rdsk/oradg/redo105') size 90M;

Database altered.

SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1       6316   52428800          1 NO  INACTIVE               3200415 14-SEP-04
         2          1       6315   52428800          1 NO  INACTIVE               3198233 14-SEP-04
         5          1       6317   52428800          1 NO  ACTIVE                 3202621 14-SEP-04
         6          1       6318   94371840          1 NO  CURRENT                3204811 14-SEP-04
         7          1          0   94371840          1 YES UNUSED                       0
         3          2         17   10485760          1 NO  CURRENT                3016310 14-SEP-04
         4          2         16   10485760          1 NO  INACTIVE               1619198 13-SEP-04

7 rows selected.

SQL> alter database drop logfile group 5;

Database altered.

SQL> alter database add logfile thread 1 group 5 ('/dev/vx/rdsk/oradg/redo103') size 90M;

Database altered.

....

SQL> select *from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1       6327   94371840          1 NO  INACTIVE               3238534 14-SEP-04
         2          1       6329   94371840          1 NO  CURRENT                3246417 14-SEP-04
         5          1          0   94371840          1 YES UNUSED                       0
         6          1       6328   94371840          1 NO  ACTIVE                 3242482 14-SEP-04
         7          1       6326   94371840          1 NO  INACTIVE               3234597 14-SEP-04
         3          2         17   10485760          1 NO  CURRENT                3016310 14-SEP-04
         4          2         16   10485760          1 NO  INACTIVE               1619198 13-SEP-04

7 rows selected.


使用 db_file_multiblock_read_count测试Oracle在不同系统中的IO能力-eygle.com

使用 db_file_multiblock_read_count测试Oracle在不同系统中的IO能力

作者: Eygle

初始化参数db_file_multiblock_read_count 影响Oracle在执行全表扫描时一次读取的block的数量.

db_file_multiblock_read_count的设置要受OS最大IO能力影响，也就是说，如果 你系统的硬件IO能力有限，
即使设置再大的db_file_multiblock_read_count也是没有用 的。

理论上，最大db_file_multiblock_read_count和系统IO能力应该有如下关系:

Max(db_file_multiblock_read_count) = MaxOsIOsize/db_block_size

当然这个Max(db_file_multiblock_read_count)还要受Oracle的限制，
目前Oracle所支持的最大db_file_multiblock_read_count 值为128.

我们可以通过db_file_multiblock_read_count来测试Oracle在不同系统下，单次IO最大所能读取得数据量：

$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.1.0.2.0 - Production on Wed Aug 11 23:43:52 2004

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SYS AS SYSDBA on 11-AUG-04 >show parameter read_count

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_multiblock_read_count        integer     16

SYS AS SYSDBA on 11-AUG-04 >create tablespace dfmbrc
  2  datafile '/opt/oracle/oradata/eygle/dfmbrc.dbf'
  3  size 20M extent management local uniform size 2M;

Tablespace created.

SYS AS SYSDBA on 11-AUG-04 >create table t tablespace dfmbrc as select * from dba_objects;

Table created.

SYS AS SYSDBA on 11-AUG-04 >insert into t select * from t;

9149 rows created.

SYS AS SYSDBA on 11-AUG-04 >/

18298 rows created.

SYS AS SYSDBA on 11-AUG-04 >/

36596 rows created.

SYS AS SYSDBA on 11-AUG-04 >commit;

Commit complete.

SYS AS SYSDBA on 11-AUG-04 >alter session set db_file_multiblock_read_count=1000;

Session altered.

SYS AS SYSDBA on 12-AUG-04 >show parameter read_count

NAME                           TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_multiblock_read_count        integer        128

SYS AS SYSDBA on 11-AUG-04 >alter session set events '10046 trace name context forever,level 12';

Session altered.

SYS AS SYSDBA on 11-AUG-04 >alter system flush buffer_cache;

System altered.

SYS AS SYSDBA on 11-AUG-04 >select count(*) from t;

  COUNT(*)
----------
     73192

SYS AS SYSDBA on 12-AUG-04 >@gettrace

TRACE_FILE_NAME
--------------------------------------------------------------------------------
/opt/oracle/soft/eygle_ora_24432.trc

$ cat /opt/oracle/soft/eygle_ora_24432.trc|grep sca
WAIT #26: nam='db file scattered read' ela= 18267 p1=10 p2=10 p3=128
WAIT #26: nam='db file scattered read' ela= 8836 p1=10 p2=138 p3=127
WAIT #26: nam='db file scattered read' ela= 8923 p1=10 p2=265 p3=128
WAIT #26: nam='db file scattered read' ela= 8853 p1=10 p2=393 p3=128
WAIT #26: nam='db file scattered read' ela= 8985 p1=10 p2=521 p3=128
WAIT #26: nam='db file scattered read' ela= 8997 p1=10 p2=649 p3=128
WAIT #26: nam='db file scattered read' ela= 9096 p1=10 p2=777 p3=128
WAIT #26: nam='db file scattered read' ela= 583 p1=10 p2=905 p3=12
$

我们可以看到，在以上测试平台中，Oracle最多每次IO能够读取128个Block，由于block_size为8k,也就是每次最多读取了1M数据.
系统平台为:

$ uname -a
SunOS billing 5.8 Generic_108528-23 sun4u sparc SUNW,Ultra-4

当然具体的，Oracle一次IO能读取多少block还和很多因素有关，比如存储是否连续，磁盘是否经过条带等方式划分，并且Oracle的
单次IO读取不能跨越Extent边界等.某些平台还和操作系统的参数设置有关.

大家可以测试一下不同的平台，Oracle的单次IO最多可以读取的Block数量.

2004年8月13日 星期五 12:09

If you have any question,please mail to eygle@itpub.net .


如何查询redo logfile的使用率-eygle.com

如何查询redo logfile的使用率

作者: Eygle

redo logfile的使用,不能通过v$视图查询，但是我们可以通过底层视图得到.

首先介绍一下引用到的视图及字段.

x$kccle---- [K]ernel [C]ache [C]ontrolfile management [L]ogfil[E] record

这个视图记录了logfile的使用情况

其中,

LESIZ ------logfile大小(以逻辑块表示)
LESEQ------log sequence #
LEBSZ------logfile逻辑块大小

顺便说一下，redo logfile是以操作系统块为单位的.所以，这里的LEBSZ就是OS的块大小.

如果我们需要获取OS块大小，就可以从这里查询得到:

SQL> select max(lebsz) lbsize from x$kccle;

LBSIZE
----------
512

x$kcccp----[K]ernel [C]ache [C]ontrolfile management [c]heckpoint [p]rogress

检查点增进(progress)

CPODR_SEQ------日志文件的seq #
CPODR_BNO------日志文件中使用块的数量

获取日志文件使用率:

SELECT
    le.leseq 			CURRENT_LOG_SEQUENCE#,
    100*cp.cpodr_bno/LE.lesiz	PERCENTAGE_FULL
from
    x$kcccp cp,x$kccle le
WHERE
    LE.leseq =CP.cpodr_seq
;

参考:

http://www.eygle.com/faq/redo_logfile_usage.htm#

2004年7月24日 星期六 0:13

If you have any question,please mail to eygle@itpub.net .


Oracle9i新特性：iSQLPLUS-eygle.com

Oracle9i新特性：iSQLPLUS

作者: Eygle

iSqlPlus是Oracle9i提供的新功能，是Sqlplus的Web形式发布。是基于三层结构涉及的。
其client、middle、server可以位于同一台机器上也可以位于不同的机器。iSqlPlus不需要单独安装，访问iSqlPlus
你只需要知道中间层服务器的地址和端口，可以以标准用户或者sysdba、sysoper的身份登陆。
iSQL*Plus 提供快速的、基于浏览器的界面，它通过一个三层模型来使用 SQL*Plus 处理引擎，这个模型包括：

  • 客户机层 (iSQL*Plus 用户界面，通常是 Web 浏览器)。
  • 中间层 (iSQL*Plus Server、Oracle Net 和 Oracle HTTP Server)。
  • 数据库层 (Oracle9i)。

这三层可位于同一台计算机上，也可位于不同的计算机上。iSQL*Plus Server 必须与 Oracle HTTP Server 位于同一台计算机上。

中间层负责协调客户机层和数据库层之间的交互和资源。数据库层是 Oracle9i，可以通过 Oracle Net 访问。

以下作一个详细的介绍

1. 启动服务器上的Http server

Start HTTP Server powered by Apache

2. 通过浏览器访问http服务器

一般缺省设置我们的端口及协议是：

http 7778 端口 / https 4443端口

注意:不同版本可能使用不同端口，具体你可以通过查看$ORACLE_HOME/Apache/Apache下的ports.ini文件来看缺省的端口设置.

如果需要更该端口，你可以通过调整$ORACLE_HOME/Apache/conf/httpd.conf文件来更该端口设置.

如本例设置：

http://ggqiang:7778/

https://ggqiang:4443/

浏览器输入以后显示如下：

或者：

3. 启动iSqlPlus

通过在浏览器输入

http://machine_name.domain:port/isqlplus

就可以启动iSqlPlus：

输入用户名口令等信息就可以登陆到数据库，并执行SQL语句及脚本文件。

也可以加载叫本来执行：

4.以Sysdba的身份登陆

以Sysdba的身份登陆，需要运行：

         http://machine_name.domain:7778/isqlplusdba
这需要你先输入http server的口令，这个不同于数据库认证。

创建认证口令文件：

D:\oracle\ora92\Apache\Apache\bin>htpasswd D:/oracle/ora92/sqlplus/admin/iplusdba.pw admin
Automatically using MD5 format on Windows.
New password: *****
Re-type new password: *****
Adding password for user admin

然后可以用这个用户以SYSDBA身份登陆数据库：

以sysdba身份登陆:

以sysdba身份起停数据库：

4.     启动服务参考

Microsoft Windows 2000 [Version 5.00.2195]

(C) 版权所有 1985-2000 Microsoft Corp.

C:\>ps -ef|grep oracle

SYSTEM 816 240 0 19:23:12 CONIN$ 0:00

d:\oracle\ora92\bin\omtsreco.exe "OracleMTSRecoveryService"

SYSTEM 1132 240 0 19:23:32 CONIN$ 0:00 D:\oracle\ora81\bin\dbsnmp.exe

SYSTEM 296 240 0 19:23:48 CONIN$ 0:01 "d:\oracle\ora92\Apache\Apache\apache.exe" --ntservice

SYSTEM 1192 240 0 19:23:50 CONIN$ 0:00 d:\oracle\ora92\BIN\TNSLSNR

SYSTEM 1212 240 0 19:23:52 CONIN$ 0:01 d:\oracle\ora92\bin\ORACLE.EXE VILEN

SYSTEM 1432 296 0 19:24:14 CONIN$ 0:00

"d:\oracle\ora92\Apache\Apache\apache.exe" -z ap296_C1 -f

"d:/oracle/ora92/apache/apache/conf/httpd.conf" "-d"

"d:/oracle/ora92/apache/apache" "-f" "d:/oracle/ora92/apache/apache/conf/httpd.conf"

SYSTEM 1696 1432 0 19:24:16 CONIN$ 0:01

d:\oracle\ora92\jdk\bin\java.exe -DORACLE_HOME=d:\oracle\ora92 org.apache.jserv.JServ -opmpropfile

d:\oracle\ora92\Apache\Jserv\conf\jserv.properties -opmhost eygle -opmport 3339 -opmgrp group1 -opmindex 0 -opmprocid 1

SYSTEM 1704 1432 0 19:24:16 CONIN$ 0:00

d:\oracle\ora92\jdk\bin\java.exe org.apache.jserv.JServ

-opmpropfile d:\oracle\ora92\Apache\Jserv\conf\jservSoap.properties –opmhost

eygle -opmport 3339 -opmgrp group2 -opmindex 0 -opmprocid 2

SYSTEM 1712 1432 0 19:24:16 CONIN$ 0:00 "d:/oracle/ora92/bin/isqlplus"

C:\>

其他请参考：

SQL*Plus Quick Reference Release 9.2 Part No. A90843-01

IsqlPlus联机帮助手册

2004年7月16日 星期五 15:02

If you have any question,please mail to eygle@itpub.net .


整理数据的小技巧-eygle.com

整理数据的小技巧

------使用Excel 、SQLPLUS和PL/SQL developer

作者: Eygle

在管理数据库和开发软件的过程中，我们常常需要整理庞杂的数据，整理，导入，不厌其烦。

下面介绍几个我们在数据整理中发现的小技巧。

以下是我操作个一个示范，旨在说明这些小技巧，你可能有更好的实现方法。如果你需要转换的是Excel表，请从步骤3看起

1.这是我们需要整理的新旧编码对照

2．我先通过SQL*PLUS把这些数据做成EXCEL表，所以使用SQL*PLUS是因为它可以让我们自上而下选取一列。

复制这些数据

粘贴在Excel表中

反复几次，复制所有的数据列。在很多时候我们需要整理的数据来自Excel表而不是文本文件，那么从下面开始，

我们开始整理数据

3．我们创建一个用于导入数据的表，字段属性可以根据需要设置

选择编辑数据

5．打开编辑界面

6．首先多插入几个空行

7．复制Excel表数据

8．粘贴数据

9．Ok,我们可以提交这些数据了

10．查看结果

以上方法对于number,date等类型数据都有效，我的例子只涉及varchar2型，是我实际做过的一次工作。

一点经验，和大家共享。

2004年7月16日 星期五 14:27

If you have any question,please mail to eygle@itpub.net .


Nologging到底何时才能生效-eygle.com

Nologging到底何时才能生效?

作者: Eygle

最初的问题是这个帖子:

http://www.itpub.net/showthread.php?threadid=239905

请大家仔细看那些测试的例子.

看了Tom的解释,始终觉得牵强.
开始以为可能是bug
经过观察和测试,终于发现了Nologging的秘密

我们知道,Nologging只在很少情况下生效
通常,DML操作总是要生成redo的

这个我们不多说.

关于Nologging和append,一直存在很多误解.
经过一系列研究,终于发现了Nologging的真相.

我们来看一下测试:

1.Nologging的设置跟数据库的运行模式有关

a.数据库运行在非归档模式下:

SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Enabled
Archive destination            /opt/oracle/oradata/hsjf/archive
Oldest online log sequence     155
Current log sequence           157

SQL> @redo
SQL> create table test as select * from dba_objects where 1=0;

Table created.

SQL> select * from redo_size;

     VALUE
----------
     63392

SQL>
SQL> insert into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   1150988

SQL>
SQL> insert /*+ append */ into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   1152368

SQL> select (1152368 -1150988) redo_append,(1150988 -63392) redo from dual;

REDO_APPEND       REDO
----------- ----------
       1380    1087596

SQL> drop table test;

Table dropped.

我们看到在Noarchivelog模式下,对于常规表的insert append只产生少量redo

b.在归档模式下

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  235999908 bytes
Fixed Size                   451236 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> @redo
SQL> create table test as select * from dba_objects where 1=0;

Table created.

SQL> select * from redo_size;

     VALUE
----------
     56288

SQL>
SQL> insert into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   1143948

SQL>
SQL> insert /*+ append */ into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   2227712

SQL> select (2227712 -1143948) redo_append,(1143948 -56288) redo from dual;

REDO_APPEND       REDO
----------- ----------
    1083764    1087660

SQL> drop table test;

Table dropped.

我们看到在归档模式下,对于常规表的insert append产生和insert同样的redo
此时的insert append实际上并不会有性能提高.
但是此时的append是生效了的

通过Logmnr分析日志得到以下结果:

SQL> select operation,count(*)
  2  from v$logmnr_contents
  3  group by operation;

OPERATION                          COUNT(*)
-------------------------------- ----------
COMMIT                                   17
DIRECT INSERT                         10470
INTERNAL                                 49
START                                    17
                                          1

我们注意到这里是DIRECT INSERT,而且是10470条记录,也就是每条记录都记录了redo.

2.对于Nologging的table的处理

a. 在归档模式下:

SQL> create table test nologging as select * from dba_objects where 1=0;

Table created.

SQL> select * from redo_size;

     VALUE
----------
   2270284

SQL>
SQL> insert into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   3357644

SQL>
SQL> insert /*+ append */ into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   3359024

SQL> select (3359024 -3357644) redo_append,(3357644 - 2270284) redo from dual;

REDO_APPEND       REDO
----------- ----------
       1380    1087360

SQL> drop table test;

Table dropped.

我们注意到,只有append才能减少redo

b.在非归档模式下:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  235999908 bytes
Fixed Size                   451236 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
SQL> alter database noarchivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> @redo
SQL> create table test nologging as select * from dba_objects where 1=0;

Table created.

SQL> select * from redo_size;

     VALUE
----------
     56580

SQL>
SQL> insert into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   1144148

SQL>
SQL> insert /*+ append */ into test select * from dba_objects;

10470 rows created.

SQL> select * from redo_size;

     VALUE
----------
   1145528

SQL> select (1145528 -1144148) redo_append,(1144148 -56580) redo from dual;

REDO_APPEND       REDO
----------- ----------
       1380    1087568

SQL>

同样只有append才能减少redo的生成.

这就是通常大家认识的情况.

2004年7月13日 星期二 23:41

If you have any question,please mail to eygle@itpub.net .


Oracle中password file的作用及说明-eygle.com

Oracle中password file的作用及说明

作者: Eygle

在数据库没有启动之前，数据库内建用户是无法通过数据库来验证身份的

口令文件中存放sysdba/sysoper用户的用户名及口令
允许用户通过口令文件验证，在数据库未启动之前登陆
从而启动数据库

如果没有口令文件，在数据库未启动之前就只能通过操作系统认证.

使用Rman，很多时候需要在nomount,mount等状态对数据库进行处理
所以通常要求sysdba权限如果属于本地DBA组，可以通过操作系统认证登陆
如果是远程sysdba登陆，需要通过passwordfile认证.

1.remote_login_passwordfile = NONE

此时停用口令文件验证，Oracle数据库不允许远程SYSDBA/SYSOPER身份登录
无法通过远程进行数据库起停等操作管理

local:

[oracle@jumper oracle]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Thu Apr 15 09:58:45 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> alter user sys identified by oracle;

User altered.

SQL> show parameter pass

NAME                      TYPE   VALUE
--------------------- ----------- ------------------------------
remote_login_passwordfile string NONE

remote:

E:\Oracle\ora92\bin>sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 -
Production on 星期四 4月 15 09:39:22 2004

Copyright (c) 1982, 2002, Oracle
Corporation. All rights reserved.

SQL> connect sys/oracle@hsjf as
sysdba
ERROR:
ORA-01017: invalid username/password; logon denied

此处实际上是无法通过口令文件验证

2.remote_login_passwordfile = exclusive

SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;

System altered.

SQL> startup force;
ORACLE instance started.

Total System Global Area 131142648 bytes
Fixed Size 451576 bytes
Variable Size 104857600 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> show parameter pass

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string EXCLUSIVE
SQL> alter user sys identified by oracle;

User altered.

remote:

E:\Oracle\ora92\bin>sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 -
Production on 星期四 4月 15 09:47:11 2004

Copyright (c) 1982, 2002, Oracle
Corporation. All rights reserved.

SQL> connect sys/oracle@hsjf as
sysdba
已连接。
SQL> show user
USER 为"SYS"
SQL>

这实际上就是通过口令文件验证登录的

3.进一步测试

如果此时我们删除passwdfile,sysdba/sysoper将无法认证，也就无法登陆数据库

Server:

SQL> !
[oracle@jumper oracle]$ cd $ORACLE_HOME/dbs
[oracle@jumper dbs]$ ls orapwhsjf
orapwhsjf
[oracle@jumper dbs]$ mv orapwhsjf orapwhsjf.bak
[oracle@jumper dbs]$

Remote:

E:\Oracle\ora92\bin>sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 - Production on 星期四 4月 15 09:50:14 2004

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> connect sys/oracle@hsjf as sysdba
ERROR:
ORA-01031: insufficient privileges

SQL>

这实际上就是无法通过口令文件验证身份

4.如果丢失了passwdfile

如果使用passwdfile却意外丢失，此时将不能启动数据库

SQL> startup force;
ORACLE instance started.

Total System Global Area 131142648 bytes
Fixed Size 451576 bytes
Variable Size 104857600 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

此时可以通过orapwd重建口令文件来解决
此处我们恢复口令文件既可

SQL> !
[oracle@jumper oracle]$ mv $ORACLE_HOME/dbs/orapwhsjf.bak orapwhsjf
[oracle@jumper oracle]$ exit
exit

SQL> alter database open;

Database altered.

SQL>

大致就是如此.

5. remote_login_passwordfile = shared

我们看一下Oracle9i文档中的说明:

SHARED

More than one database can use a password file. However, the only user recognized by the password file is SYS.

意思是说多个数据库可以共享一个口令文件,但是只可以识别一个用户:SYS

SQL> select * from v$pwfile_users;

USERNAME SYSDB SYSOP
------------------------------ ----- -----
SYS TRUE TRUE

SQL> grant sysdba to eygle;
grant sysdba to eygle
*
ERROR at line 1:
ORA-01994: GRANT failed: cannot add users to public password file

SQL> show parameter password

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string SHARED

我们看到,此时的口令文件中是不能添加用户的.

很多人的疑问在于:口令文件的缺省名称是orapw<sid>,怎么能够共享?

实际上是这样的: Oracle数据库在启动时,首先查找的是orapw<sid>的口令文件,如果该文件不存在,则开始查找,orapw的口令文件
如果口令文件命名为orapw,多个数据库就可以共享.

我们看一下测试:

[oracle@jumper dbs]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.3.0 - Production on Tue Jul 6 09:40:34 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !
[oracle@jumper dbs]$ ls
hsjf  initdw.ora  inithsjf.ora  init.ora  lkHSJF  orapwhsjf  spfilehsjf.ora
[oracle@jumper dbs]$ mv orapwhsjf orapwhsjf.bak
[oracle@jumper dbs]$ exit
exit

SQL> startup
ORACLE instance started.

Total System Global Area  235999908 bytes
Fixed Size                   451236 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'--这是最后查找的文件
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3

我们建立orapw口令文件,这时候可以打开数据库.

SQL> !
[oracle@jumper dbs]$ ls
hsjf  initdw.ora  inithsjf.ora  init.ora  lkHSJF  orapwhsjf.bak  spfilehsjf.ora
[oracle@jumper dbs]$ cp orapwhsjf.bak orapw
[oracle@jumper dbs]$ exit
exit

SQL> alter database open;

Database altered.

SQL> show parameter passw

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile            string      SHARED
SQL>

那么你可能会有这样的疑问,多个Exclusive的数据库是否可以共享一个口令文件(orapw)呢?

我们继续这个实验:

SQL> show parameter password

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string SHARED

[oracle@jumper dbs]$ strings orapw
]\[Z
ORACLE Remote Password file
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A

注意这里仅记录着INTERNAL/SYS的口令

REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE 时

SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;

System altered.

SQL> startup force;
ORACLE instance started.

Total System Global Area 235999908 bytes
Fixed Size 451236 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> !

[oracle@jumper bin]$ cd $ORACLE_HOME/dbs
[oracle@jumper dbs]$ strings orapw
]\[Z
ORACLE Remote Password file
HSJF
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A
[oracle@jumper dbs]$ exit
exit

注意这里,以EXCLUSIVE 方式启动以后,实例名称信息被写入口令文件.

此时如果有其他实例以Exclusive模式启动仍然可以使用这个口令文件,口令文件中的实例名称同时被改写.

也就是说,数据库只在启动过程中才读取口令文件,数据库运行过程中并不锁定该文件,类似于pfile/spfile文件.

SQL> select * from v$pwfile_users;

USERNAME SYSDB SYSOP
------------------------------ ----- -----
SYS TRUE TRUE

SQL> grant sysdba to eygle;

Grant succeeded.

SQL> select * from v$pwfile_users;

USERNAME SYSDB SYSOP
------------------------------ ----- -----
SYS TRUE TRUE
EYGLE TRUE FALSE

SQL> !
[oracle@jumper bin]$ cd $ORACLE_HOME/dbs
[oracle@jumper dbs]$ strings orapw
]\[Z
ORACLE Remote Password file
HSJF
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A
>EYGLE
B726E09FE21F8E83

注意此时可以增加SYSDBA用户，并且这些信息可以被写入到口令文件.

一旦口令文件中增加了其他SYSDBA用户,此文件不再能够被其他Exclusive的实例共享.

实际上，口令文件对于其他用户来说就是启到了一个 sudo 的作用.

6.重建口令文件

如果口令文件丢失,可以使用orapwd可以重建口令文件，语法如下:

[oracle@jumper oracle]$ orapwd
Usage: orapwd file=<fname> password=<password> entries=<users>

where
file - name of password file (mand),
password - password for SYS (mand),
entries - maximum number of distinct DBA and OPERs (opt),
There are no spaces around the equal-to (=) character.

2004年6月26日 星期六 11:57

2004年7月6日 星期二 9:26 更新

2004年7月6日 星期二 14:36 更新

If you have any question,please mail to eygle@itpub.net .


Kill Session-eygle.com

Oracle中Kill session的研究

作者: Eygle

itpub link:

http://www.itpub.net/235873.html

我们知道,在Oracle数据库中,可以通过kill session的方式来终止一个进程,其基本语法结构为:

alter system kill session 'sid,serial#' ;

被kill掉的session,状态会被标记为killed,Oracle会在该用户下一次touch时清除该进程.

我们发现当一个session被kill掉以后，该session的paddr被修改，如果有多个session被kill，那么多个session
的paddr都被更改为相同的进程地址:

SQL> select saddr,sid,serial#,paddr,username,status from v$session where username is not null;

SADDR           SID    SERIAL# PADDR    USERNAME                       STATUS
-------- ---------- ---------- -------- ------------------------------ --------
542E0E6C         11        314 542B70E8 EYGLE                          INACTIVE
542E5044         18        662 542B6D38 SYS                            ACTIVE

SQL> alter system kill session '11,314';

System altered.

SQL> select saddr,sid,serial#,paddr,username,status from v$session where username is not null;

SADDR           SID    SERIAL# PADDR    USERNAME                       STATUS
-------- ---------- ---------- -------- ------------------------------ --------
542E0E6C         11        314 542D6BD4 EYGLE                          KILLED
542E5044         18        662 542B6D38 SYS                            ACTIVE

SQL> select saddr,sid,serial#,paddr,username,status from v$session where username is not null;

SADDR           SID    SERIAL# PADDR    USERNAME                       STATUS
-------- ---------- ---------- -------- ------------------------------ --------
542E0E6C         11        314 542D6BD4 EYGLE                          KILLED
542E2AA4         14        397 542B7498 EQSP                           INACTIVE
542E5044         18        662 542B6D38 SYS                            ACTIVE

SQL> alter system kill session '14,397';

System altered.

SQL> select saddr,sid,serial#,paddr,username,status from v$session where username is not null;

SADDR           SID    SERIAL# PADDR    USERNAME                       STATUS
-------- ---------- ---------- -------- ------------------------------ --------
542E0E6C         11        314 542D6BD4 EYGLE                          KILLED
542E2AA4         14        397 542D6BD4 EQSP                           KILLED
542E5044         18        662 542B6D38 SYS                            ACTIVE

在这种情况下,很多时候，资源是无法释放的,我们需要查询spid，在操作系统级来kill这些进程.

但是由于此时v$session.paddr已经改变，我们无法通过v$session和v$process关联来获得spid

那还可以怎么办呢?

我们来看一下下面的查询:

  SQL> SELECT s.username,s.status,
  2  x.ADDR,x.KSLLAPSC,x.KSLLAPSN,x.KSLLASPO,x.KSLLID1R,x.KSLLRTYP,
  3  decode(bitand (x.ksuprflg,2),0,null,1)
  4  FROM x$ksupr x,v$session s
  5  WHERE s.paddr(+)=x.addr
  6  and bitand(ksspaflg,1)!=0;

USERNAME                       STATUS   ADDR       KSLLAPSC   KSLLAPSN KSLLASPO       KSLLID1R KS D
------------------------------ -------- -------- ---------- ---------- ------------ ---------- -- -
                                        542B44A8          0          0                       0
                               ACTIVE   542B4858          1         14 24069                 0    1
                               ACTIVE   542B4C08         26         16 15901                 0    1
                               ACTIVE   542B4FB8          7         46 24083                 0    1
                               ACTIVE   542B5368         12         15 24081                 0    1
                               ACTIVE   542B5718         15         46 24083                 0    1
                               ACTIVE   542B5AC8         79          4 15923                 0    1
                               ACTIVE   542B5E78         50         16 24085                 0    1
                               ACTIVE   542B6228        754         15 24081                 0    1
                               ACTIVE   542B65D8          1         14 24069                 0    1
                               ACTIVE   542B6988          2         30 14571                 0    1

USERNAME                       STATUS   ADDR       KSLLAPSC   KSLLAPSN KSLLASPO       KSLLID1R KS D
------------------------------ -------- -------- ---------- ---------- ------------ ---------- -- -
SYS                            ACTIVE   542B6D38          2          8 24071                 0
                                        542B70E8          1         15 24081               195 EV
                                        542B7498          1         15 24081               195 EV
SYS                            INACTIVE 542B7848          0          0                       0
SYS                            INACTIVE 542B7BF8          1         15 24081               195 EV

16 rows selected.

我们注意,红字标出的部分就是被Kill掉的进程的进程地址.

简化一点,其实就是如下概念:

SQL> select p.addr from v$process p where pid <> 1
  2  minus
  3  select s.paddr from v$session s;

ADDR
--------
542B70E8
542B7498

Ok，现在我们获得了进程地址，就可以在v$process中找到spid，然后可以使用Kill或者orakill在系统级来杀掉这些进程.

实际上,我猜测:

当在Oracle中kill session以后, Oracle只是简单的把相关session的paddr 指向同一个虚拟地址.

此时v$process和v$session失去关联,进程就此中断.

然后Oracle就等待PMON去清除这些Session.所以通常等待一个被标记为Killed的Session退出需要花费很长的时间.

如果此时被Kill的process，重新尝试执行任务，那么马上会收到进程中断的提示，process退出，此时Oracle会立即启动PMON
来清除该session.这被作为一次异常中断处理.

2004年6月25日 星期五

If you have any question,please mail to eygle@itpub.net .


Oracle中的进制转换-eygle.com

Oracle中的进制转换

1.16进制转换为10进制

可以通过to_number函数实现

SQL> select to_number('19f','xxx') from dual;

TO_NUMBER('19F','XXX')
----------------------
415

SQL> select to_number('f','xx') from dual;

TO_NUMBER('F','XX')
-------------------
15

2.10进制转换为16进制

可以通过to_char函数转换

SQL> select to_char(123,'xxx') from dual;

TO_C
----
7b

SQL> select to_char(4567,'xxxx') from dual;

TO_CH
-----
11d7

3.2进制转换为10进制

从Oracle9i开始,提供函数bin_to_num进行2进制到10进制的转换

SQL> select bin_to_num(1,1,0,1) a,bin_to_num(1,0) b from dual;

A B
----- ----------
13 2

SQL> select bin_to_num(1,1,1,0,1) from dual;

BIN_TO_NUM(1,1,1,0,1)
---------------------
29

3.进制转换也可以通过自定义函数实现

以下函数来自AskTom网站,是Tom给出的例子,供参考:

create or replace function to_base( p_dec in number, p_base in number
        )
return varchar2
is
l_str varchar2(255) default
        NULL;
l_num number default p_dec;
l_hex varchar2(16) default
        '0123456789ABCDEF';
begin
if ( trunc(p_dec) <> p_dec OR
        p_dec < 0 ) then
raise PROGRAM_ERROR;
end if;
loop
l_str
        := substr( l_hex, mod(l_num,p_base)+1, 1 ) || l_str;
l_num := trunc(
        l_num/p_base );
exit when ( l_num = 0 );
end loop;
return
        l_str;
end to_base;
/

create or replace function to_dec
( p_str in varchar2,
p_from_base in number default 16 ) return number
is
l_num number default 0;
l_hex varchar2(16) default '0123456789ABCDEF';
begin
for i in 1 .. length(p_str) loop
l_num := l_num * p_from_base + instr(l_hex,upper(substr(p_str,i,1)))-1;
end loop;
return l_num;
end to_dec;
/
show errors

create or replace function to_hex( p_dec in number ) return varchar2
is
begin
return to_base( p_dec, 16 );
end to_hex;
/
create or replace function to_bin( p_dec in number ) return varchar2
is
begin
return to_base( p_dec, 2 );
end to_bin;
/
create or replace function to_oct( p_dec in number ) return varchar2
is
begin
return to_base( p_dec, 8 );
end to_oct;
/

2004年6月16日 Wednesday

If you have any question,please mail to eygle@itpub.net .


使用DBMS_SUPPORT包-eygle.com

使用DBMS_SUPPORT包

DBMS_SUPPORT包从Oracle7.2引入,主要功能用以提供更完整的用户session跟踪信息

这个包可以通过运行 dbmssupp.sql 和 prvtsupp.plb 两个脚本来创建.

该脚本位于$ORACLE_HOME/rdbms/admin目录下

以下版本中都包含这些文件:

8.0.6, 8.1.7, 9.0.1, 9.2.0 and above

1.创建DBMS_SUPPORT Package

SQL> @?/rdbms/admin/dbmssupp.sql

Package created.

Package body created.

SQL> @?/rdbms/admin/prvtsupp.plb

Package body created.

2.主要函数及过程

SQL> desc dbms_support

FUNCTION MYSID RETURNS NUMBER

FUNCTION PACKAGE_VERSION RETURNS VARCHAR2

PROCEDURE START_TRACE
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 WAITS                          BOOLEAN                 IN     DEFAULT
 BINDS                          BOOLEAN                 IN     DEFAULT

PROCEDURE START_TRACE_IN_SESSION
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 SID                            NUMBER                  IN
 SERIAL                         NUMBER                  IN
 WAITS                          BOOLEAN                 IN     DEFAULT
 BINDS                          BOOLEAN                 IN     DEFAULT

PROCEDURE STOP_TRACE

PROCEDURE STOP_TRACE_IN_SESSION
 Argument Name                  Type                    In/Out Default?
 ------------------------------ ----------------------- ------ --------
 SID                            NUMBER                  IN
 SERIAL                         NUMBER                  IN

3.简单用法

SQL> SELECT DBMS_SUPPORT.MYSID from DUAL;

MYSID
----------
8

SQL> select dbms_support.PACKAGE_VERSION from dual;

PACKAGE_VERSION
--------------------------------------------------------------------------------
DBMS_SUPPORT Version 1.0 (17-Aug-1998) - Requires Oracle 7.2 - 8.0.5

4.进程跟踪(跟踪当前session及其他session)

SQL> exec dbms_support.start_trace

PL/SQL procedure successfully completed.

SQL> select count(*) from dba_users;

COUNT(*)
----------
34

SQL> exec dbms_support.stop_trace;

PL/SQL procedure successfully completed.

SQL> select sid,serial#,username from v$session
2 /

SID SERIAL# USERNAME
---------- ---------- ------------------------------
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 764 SYS

8 rows selected.

SQL> exec dbms_support.start_trace_in_session(4,1);

PL/SQL procedure successfully completed.

SQL> exec dbms_support.stop_trace_in_session(4,1);

PL/SQL procedure successfully completed.

5.Trace文件

以上跟踪生成的Trace文件可以在udump目录下找到.

SQL> show parameter user_dump

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string /opt/oracle/admin/hsjf/udump

2004年6月19日 星期六

If you have any question,please mail to eygle@itpub.net .


启用AutoTrace-eygle.com

启用AutoTrace

通过以下方法可以把Autotrace的权限授予Everyone，

如果你需要限制Autotrace权限，可以把对public的授权改为对特定user的授权。

D:\oracle\ora92>sqlplus /nolog

SQL*Plus: Release 9.2.0.1.0 - Production on 星期二 6月 3 15:16:03 2003

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> connect sys as sysdba
请输入口令:
已连接。
SQL> @?\rdbms\admin\utlxplan

表已创建。

SQL> create public synonym plan_table for plan_table;

同义词已创建。

SQL> grant all on plan_table to public ;

授权成功。

SQL> @?\sqlplus\admin\plustrce
SQL>
SQL> drop role plustrace;
drop role plustrace
*
ERROR 位于第 1 行:
ORA-01919: 角色'PLUSTRACE'不存在

SQL> create role plustrace;

角色已创建
SQL>
SQL> grant select on v_$sesstat to plustrace;

授权成功。

SQL> grant select on v_$statname to plustrace;

授权成功。

SQL> grant select on v_$session to plustrace;

授权成功。

SQL> grant plustrace to dba with admin option;

授权成功。

SQL>
SQL> set echo off

DBA用户首先被授予了plustrace角色,然后我们可以把plustrace授予public

这样所有用户都将拥有plustrace角色的权限.

SQL> grant plustrace to public ;

授权成功。

然后我们就可以使用AutoTrace的功能了.

SQL> connect eqsp/eqsp
已连接。
SQL> set autotrace on
SQL> set timing on
SQL>

关于Autotrace几个常用选项的说明:

SET AUTOTRACE OFF ---------------- 不生成AUTOTRACE 报告，这是缺省模式
SET AUTOTRACE ON EXPLAIN ------ AUTOTRACE只显示优化器执行路径报告
SET AUTOTRACE ON STATISTICS -- 只显示执行统计信息
SET AUTOTRACE ON ----------------- 包含执行计划和统计信息
SET AUTOTRACE TRACEONLY ------ 同set autotrace on，但是不显示查询输出

SQL> set autotrace traceonly
SQL> select table_name from user_tables;

已选择98行。

已用时间: 00: 00: 00.04

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 NESTED LOOPS
2 1 NESTED LOOPS (OUTER)
3 2 NESTED LOOPS (OUTER)
4 3 NESTED LOOPS (OUTER)
5 4 NESTED LOOPS (OUTER)
6 5 NESTED LOOPS
7 6 TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'
8 7 INDEX (RANGE SCAN) OF 'I_OBJ2' (UNIQUE)
9 6 TABLE ACCESS (CLUSTER) OF 'TAB$'
10 9 INDEX (UNIQUE SCAN) OF 'I_OBJ#' (NON-UNIQUE)
11 5 TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'
12 11 INDEX (UNIQUE SCAN) OF 'I_OBJ1' (UNIQUE)
13 4 INDEX (UNIQUE SCAN) OF 'I_OBJ1' (UNIQUE)
14 3 TABLE ACCESS (CLUSTER) OF 'USER$'
15 14 INDEX (UNIQUE SCAN) OF 'I_USER#' (NON-UNIQUE)
16 2 TABLE ACCESS (CLUSTER) OF 'SEG$'
17 16 INDEX (UNIQUE SCAN) OF 'I_FILE#_BLOCK#' (NON-UNIQUE)
18 1 TABLE ACCESS (CLUSTER) OF 'TS$'
19 18 INDEX (UNIQUE SCAN) OF 'I_TS#' (NON-UNIQUE)

Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1389 consistent gets
0 physical reads
0 redo size
2528 bytes sent via SQL*Net to client
569 bytes received via SQL*Net from client
8 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
98 rows processed

SQL>

2004年6月18日 星期五

If you have any question,please mail to eygle@itpub.net .


安装10g以后Oracle9i的DBCA无法启动问题之解决-eygle.com

安装10g以后Oracle9i的DBCA无法启动问题之解决

作者: Eygle

问题描述:

你可以也遇到这样的问题,在Windows上安转了Oracle10g以后，同一主机上的Oracle9i的DBCA可能会无法启动.

类似错误可能如下:

E:\Oracle\ora92\bin>dbca
Exception in thread "main" java.lang.UnsatisfiedLinkError: initializeCluster
at oracle.ops.mgmt.nativesystem.WindowsSystem.initializeCluster(WindowsSystem.java:390)
at oracle.ops.mgmt.cluster.GetActiveNodes.initializeCluster(GetActiveNodes.java:260)
at oracle.ops.mgmt.cluster.GetActiveNodes$ClusterWareThread.<init>(Compiled Code)
at oracle.ops.mgmt.cluster.GetActiveNodes.<init>(GetActiveNodes.java:139)
at oracle.ops.mgmt.cluster.GetActiveNodes.create(GetActiveNodes.java:158)
at
at oracle.sysman.assistants.dbca.backend.Host.checkOPS(Host.java:1815)
at oracle.sysman.assistants.dbca.backend.Host.<init>(Host.java:469)
at oracle.sysman.assistants.dbca.ui.UIHost.<init>(UIHost.java:185)
at oracle.sysman.assistants.dbca.ui.InteractiveHost.<init>(InteractiveHost.java:54)
at oracle.sysman.assistants.dbca.Dbca.getHost(Dbca.java:141)
at oracle.sysman.assistants.dbca.Dbca.execute(Dbca.java:85)
at oracle.sysman.assistants.dbca.Dbca.main(Dbca.java:161)
^C终止批处理操作吗(Y/N)? y

解决方法:

在 控制面板->系统->高级->环境变量->系统变量 里

找到PATH,暂时把Oracle10g的环境变量删除.

如,修改前:

e:\oracle\ora92\jre\1.4.2\bin\client;e:\oracle\ora92\jre\1.4.2\bin;e:\oracle\10.1.0\bin;
e:\oracle\ora92\bin;E:\oracle\10.1.0\jre\1.4.2\bin\client;E:\oracle\10.1.0\jre\1.4.2\bin;
e:\oracle\Report6i\bin;e:\oracle\Form6i\bin;C:\Program Files\Oracle\jre\1.3.1\bin;
C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;

可以修改为:

e:\oracle\ora92\jre\1.4.2\bin\client;e:\oracle\ora92\jre\1.4.2\bin; e:\oracle\ora92\bin;e:\oracle\Report6i\bin;e:\oracle\Form6i\bin; C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin; C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;

此时再次运行DBCA即可启动Oracle9i的DBCA.

此后，你可以手工把10g的环境变量添加回去.

2004年7月3日 星期六 17:10

If you have any question,please mail to eygle@itpub.net .


在Oracle中发送Email-eygle.com

在Oracle中发送Email

在Oracle中发送email，以下是Oracle提供的例子，共参考.

itpub link:

http://www.itpub.net/showthread.php?threadid=226086

1. CREATE PACKAGE

CREATE OR REPLACE PACKAGE demo_mail IS

----------------------- Customizable Section -----------------------

-- Customize the SMTP host, port and your domain name below.
smtp_host VARCHAR2(256) := 'smtp.eygle.com';
smtp_port PLS_INTEGER := 25;
smtp_domain VARCHAR2(256) := 'eygle.com';

-- Customize the signature that will appear in the email's MIME header.
-- Useful for versioning.
MAILER_ID CONSTANT VARCHAR2(256) := 'Mailer by Eygle';

--------------------- End Customizable Section ---------------------

-- A unique string that demarcates boundaries of parts in a multi-part email
-- The string should not appear inside the body of any part of the email.
-- Customize this if needed or generate this randomly dynamically.
BOUNDARY CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';

FIRST_BOUNDARY CONSTANT VARCHAR2(256) := '--' ||
        BOUNDARY || utl_tcp.CRLF;
LAST_BOUNDARY CONSTANT VARCHAR2(256) :=
        '--' || BOUNDARY || '--' ||
utl_tcp.CRLF;

-- A MIME type that denotes multi-part email (MIME)
        messages.
MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) :=
        'multipart/mixed; boundary="'||
BOUNDARY ||
        '"';
MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER := 76 / 4 * 3;

-- A simple email API for sending email in plain text in a single call.
-- The format of an email address is one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
-- The recipients is a list of email addresses separated by
-- either a "," or a ";"
PROCEDURE mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2);

-- Extended email API to send email in HTML or plain text with no size limit.
-- First, begin the email by begin_mail(). Then, call write_text() repeatedly
-- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
-- email in non-ASCII or multi-byte character set. End the email with
-- end_mail().
FUNCTION begin_mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection;

-- Write email body in ASCII
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);

-- Write email body in non-ASCII (including multi-byte). The email body
-- will be sent in the database character set.
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);

-- Write email body in binary
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
message IN RAW);

-- APIs to send email with attachments. Attachments are sent by sending
-- emails in "multipart/mixed" MIME format. Specify that MIME format when
-- beginning an email with begin_mail().

-- Send a single text attachment.
PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);

-- Send a binary attachment. The attachment will be encoded in Base-64
-- encoding format.
PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW,
mime_type IN VARCHAR2 DEFAULT 'application/octet',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);

-- Send an attachment with no size limit. First, begin the attachment
-- with begin_attachment(). Then, call write_text repeatedly to send
-- the attachment piece-by-piece. If the attachment is text-based but
-- in non-ASCII or multi-byte character set, use write_mb_text() instead.
-- To send binary attachment, the binary content should first be
-- encoded in Base-64 encoding format using the demo package for 8i,
-- or the native one in 9i. End the attachment with end_attachment.
PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL);

-- End the attachment.
PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE);

-- End the email.
PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);

-- Extended email API to send multiple emails in a session for better
-- performance. First, begin an email session with begin_session.
-- Then, begin each email with a session by calling begin_mail_in_session
-- instead of begin_mail. End the email with end_mail_in_session instead
-- of end_mail. End the email session by end_session.
FUNCTION begin_session RETURN utl_smtp.connection;

-- Begin an email in a session.
PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL);

-- End an email in a session.
PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);

-- End an email session.
PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);

END;
/
CREATE OR REPLACE PACKAGE BODY demo_mail IS

-- Return the next email address in the list of email addresses, separated
-- by either a "," or a ";". The format of mailbox may be in one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS

addr VARCHAR2(256);
i pls_integer;

FUNCTION lookup_unquoted_char(str IN VARCHAR2,
chrs IN VARCHAR2) RETURN pls_integer AS
c VARCHAR2(5);
i pls_integer;
len pls_integer;
inside_quote BOOLEAN;
BEGIN
inside_quote := false;
i := 1;
len := length(str);
WHILE (i <= len) LOOP

c := substr(str, i, 1);

IF (inside_quote) THEN
IF (c = '"')
        THEN
inside_quote := false;
ELSIF (c = '\') THEN
i := i + 1; --
        Skip the quote character
END IF;
GOTO next_char;
END IF;

IF (c = '"') THEN
inside_quote := true;
GOTO next_char;
END IF;

IF (instr(chrs, c) >= 1) THEN
RETURN i;
END IF;

<<next_char>>
i := i + 1;

END LOOP;

RETURN 0;

END;

BEGIN

addr_list := ltrim(addr_list);
i :=
        lookup_unquoted_char(addr_list, ',;');
IF (i >= 1) THEN
addr :=
        substr(addr_list, 1, i - 1);
addr_list := substr(addr_list, i +
        1);
ELSE
addr := addr_list;
addr_list := '';
END IF;

i := lookup_unquoted_char(addr, '<');
IF (i >=
        1) THEN
addr := substr(addr, i + 1);
i := instr(addr,
        '>');
IF (i >= 1) THEN
addr := substr(addr, 1, i -
        1);
END IF;
END IF;

RETURN addr;
END;

-- Write a MIME header
PROCEDURE write_mime_header(conn IN OUT NOCOPY utl_smtp.connection,
name IN VARCHAR2,
value IN VARCHAR2) IS
BEGIN
utl_smtp.write_data(conn, name || ': ' || value || utl_tcp.CRLF);
END;

-- Mark a message-part boundary. Set <last> to TRUE for the last boundary.
PROCEDURE write_boundary(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE) AS
BEGIN
IF (last) THEN
utl_smtp.write_data(conn, LAST_BOUNDARY);
ELSE
utl_smtp.write_data(conn, FIRST_BOUNDARY);
END IF;
END;

------------------------------------------------------------------------
PROCEDURE mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2) IS
conn utl_smtp.connection;
BEGIN
conn := begin_mail(sender, recipients, subject);
write_text(conn, message);
end_mail(conn);
END;

------------------------------------------------------------------------
FUNCTION begin_mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection IS
conn utl_smtp.connection;
BEGIN
conn := begin_session;
begin_mail_in_session(conn, sender, recipients, subject, mime_type,
priority);
RETURN conn;
END;

------------------------------------------------------------------------
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2) IS
BEGIN
utl_smtp.write_data(conn, message);
END;

------------------------------------------------------------------------
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2) IS
BEGIN
utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
END;

------------------------------------------------------------------------
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
message IN RAW) IS
BEGIN
utl_smtp.write_raw_data(conn, message);
END;

------------------------------------------------------------------------
PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
begin_attachment(conn, mime_type, inline, filename);
write_text(conn, data);
end_attachment(conn, last);
END;

------------------------------------------------------------------------
PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW,
mime_type IN VARCHAR2 DEFAULT 'application/octet',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE) IS
i PLS_INTEGER;
len PLS_INTEGER;
BEGIN

begin_attachment(conn, mime_type, inline, filename, 'base64');

-- Split the Base64-encoded attachment into multiple lines
i := 1;
len := utl_raw.length(data);
WHILE (i < len) LOOP
IF (i + MAX_BASE64_LINE_WIDTH < len) THEN
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i,
MAX_BASE64_LINE_WIDTH)));
ELSE
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i)));
END IF;
utl_smtp.write_data(conn, utl_tcp.CRLF);
i := i + MAX_BASE64_LINE_WIDTH;
END LOOP;

end_attachment(conn, last);

END;

------------------------------------------------------------------------
PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL) IS
BEGIN
write_boundary(conn);
write_mime_header(conn, 'Content-Type', mime_type);

IF (filename IS NOT NULL) THEN
IF (inline) THEN
write_mime_header(conn, 'Content-Disposition',
'inline; filename="'||filename||'"');
ELSE
write_mime_header(conn, 'Content-Disposition',
'attachment; filename="'||filename||'"');
END IF;
END IF;

IF (transfer_enc IS NOT NULL) THEN
write_mime_header(conn, 'Content-Transfer-Encoding', transfer_enc);
END IF;

utl_smtp.write_data(conn, utl_tcp.CRLF);
END;

------------------------------------------------------------------------
PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
utl_smtp.write_data(conn, utl_tcp.CRLF);
IF (last) THEN
write_boundary(conn, last);
END IF;
END;

------------------------------------------------------------------------
PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
end_mail_in_session(conn);
end_session(conn);
END;

------------------------------------------------------------------------
FUNCTION begin_session RETURN utl_smtp.connection IS
conn utl_smtp.connection;
BEGIN
-- open SMTP connection
conn := utl_smtp.open_connection(smtp_host, smtp_port);
utl_smtp.helo(conn, smtp_domain);
RETURN conn;
END;

------------------------------------------------------------------------
PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL) IS
my_recipients VARCHAR2(32767) := recipients;
my_sender VARCHAR2(32767) := sender;
BEGIN

-- Specify sender's address (our server allows bogus address
-- as long as it is a full email address (xxx@yyy.com).
utl_smtp.mail(conn, get_address(my_sender));

-- Specify recipient(s) of the email.
WHILE (my_recipients IS NOT NULL) LOOP
utl_smtp.rcpt(conn, get_address(my_recipients));
END LOOP;

-- Start body of email
utl_smtp.open_data(conn);

-- Set "From" MIME header
write_mime_header(conn, 'From', sender);

-- Set "To" MIME header
write_mime_header(conn, 'To', recipients);

-- Set "Subject" MIME header
write_mime_header(conn, 'Subject', subject);

-- Set "Content-Type" MIME header
write_mime_header(conn, 'Content-Type', mime_type);

-- Set "X-Mailer" MIME header
write_mime_header(conn, 'X-Mailer', MAILER_ID);

-- Set priority:
-- High Normal Low
-- 1 2 3 4 5
IF (priority IS NOT NULL) THEN
write_mime_header(conn, 'X-Priority', priority);
END IF;

-- Send an empty line to denotes end of MIME headers and
-- beginning of message body.
utl_smtp.write_data(conn, utl_tcp.CRLF);

IF (mime_type LIKE 'multipart/mixed%') THEN
write_text(conn, 'This is a multi-part message in MIME format.' ||
utl_tcp.crlf);
END IF;

END;

------------------------------------------------------------------------
PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
utl_smtp.close_data(conn);
END;

------------------------------------------------------------------------
PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
utl_smtp.quit(conn);
END;

END;
/

2.发送 MAIL：

CREATE OR REPLACE procedure MailTest IS
Begin
DEMO_MAIL.mail('eygle@itpub.net',
'gqgai@hurray.com.cn',
'Just a test',
'It is ok.');
end;
/

begin
MailTest;
end;

2004年6月24日 星期四

If you have any question,please mail to eygle@itpub.net .