optimizer_index_cost_adj参数的作用

optimizer_index_cost_adj
这个初始化参数optimizer_index_cost_adj用于改变通过索引扫描来访问表数据的成本.参数的有效值从1到10000.
缺省值是100.如果这个参数的值大于100那么使用索引扫描的成本更昂贵因而会选择执行全表扫描.如果这个参数值
小于100那么使用索引扫描的成本更低.

为了理解这个参数对成本计算公式的影响.下面将说明一下关于索引范围扫描的成本计算公式

索引范围扫描有几个关键步骤:
1.访问索引的根块
2.通过分支块来定位包含第一个键的叶子块
3.对于满足搜索条件的每一个索引健进行以下操作;
抽取rowid引用的数据块
通过rowid访问数据块.

一个索引范围扫描所有执行的物理读取的次数等于定位包含第一个键的叶子块所要访问的分支块的个数(命名为blevel)
加上要扫描的叶子块的个数(命名为leaf_blocks)乘以操作的选择性,加上通过rowid要访问的数据块的个数
(命名为clustering_factor)乘以操作的选择性.另外还有考虑初始化参数optimizer_index_cost_adj的影响
计算公式大致如下:

io_cost=(blevel+(leaf_blocks+clustering_factor)*selectivity)*(optimizer_index_cost_adj/100)

下面进行测试(查询语句为select * from test where object_id<200)

create table test as select * from dba_objects;

create index idx_object_id on test(object_id);

analyze table test compute statistics;

SQL> select LEAF_BLOCKS,BLEVEL ,clustering_factor from user_indexes where index_name='IDX_OBJECT_ID';

LEAF_BLOCKS     BLEVEL CLUSTERING_FACTOR
----------- ---------- -----------------
        161          1              1665

SQL> select low_value,high_value from user_tab_col_statistics where table_name='TEST' and   column_name='OBJECT_ID';

LOW_VALUE                                                        HIGH_VALUE
---------------------------------------------------------------- ----------------------------------------------- -----------------
C103                                                             C3083632

SQL>
SQL> select utl_raw.cast_to_number('C3083632') high_value from dual;

HIGH_VALUE
----------
     75349
SQL> select utl_raw.cast_to_number('C103') low_value from dual;

 LOW_VALUE
----------
         2

其实列的最大值与最小值可以直接查询

SQL>select min(object_id),max(object_id) from test;

MIN(OBJECT_ID) MAX(OBJECT_ID)
-------------- --------------
2              75349
计算选择性
<谓词的选择性=(limit- low_value)/(high_vlaue-low_value)
limit就是查询条件的值
SQL>select round((200-2)/(75349-2),5) selectivity from dual;

SELECTIVITY
-----------
0.00263

因为io_cost的计算方法如下:

io_cost=(blevel+(leaf_blocks+clustering_factor)*selectivity)*(optimizer_index_cost_adj/100)
SQL> show parameter optimizer_index_cost_adj

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_index_cost_adj integer 100
optimizer_index_cost_adj=100
blevel=1;
leaf_blocks=161
clustering_factor=1665
selecttivity=0.00263

SQL>select (1+ceil(161*(round((200-2)/(75349-2),5)))+ceil(1665*(round((200-2)/(75349-2),5))))*(100/100) cost
from dual;

COST
----------
7

SQL>conn jy/jy@jy_201
已连接。
SQL>set autotrace trace explain
SQL> select  * from test where object_id<200;

执行计划
----------------------------------------------------------
Plan hash value: 985375477

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

| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |

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

|   0 | SELECT STATEMENT            |               |   191 | 19100 |     7   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| TEST          |   191 | 19100 |     7   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_OBJECT_ID |   191 |       |     2   (0)| 00:00:01 |

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


Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("OBJECT_ID"<200)

可以看到总的成本也和我们计算出来的一样也是7
当把optimizer_index_cost_adj设置为50时

SQL>alter session set optimizer_index_cost_adj=50;

Session altered.

SQL> show parameter optimizer_index_cost_adj;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_index_cost_adj integer 50

optimizer_index_cost_adj=50
blevel=1;
leaf_blocks=161
clustering_factor=1665
selecttivity=0.00263

SQL>select (1+ceil(161*(round((200-2)/(75349-2),5)))+ceil(1665*(round((200-2)/(75349-2),5))))*(50/100) cost from
dual;

COST
----------
3.5

我们计算出来是3.5四舍五入就是4与下面oracle计算的是一样

SQL> set autotrace trace explain
SQL> select  * from test where object_id<200;

Execution Plan
----------------------------------------------------------
Plan hash value: 985375477

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

| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |

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

|   0 | SELECT STATEMENT            |               |   191 | 19100 |     4   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| TEST          |   191 | 19100 |     4   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_OBJECT_ID |   191 |       |     1   (0)| 00:00:01 |

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


Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("OBJECT_ID"<200)

初始化参数optimizer_index_cost_adj会直接影响索引访问的成本.当这个参数设置的值比缺省值小时,
所有成本按比例减小.在有些情况下可能出现问题因为查询优化器对评估结果做了round操作.这意味着即使
一些索引的对象统计不同,它们可能会有相同的成本.如果一些成本是相同的,那么查询优化器将会根据索引
的名字来选择使用的索引.也就是按索引的第一个字母进行排序.这个问题用一个例子来说明.当改变初始化
参数optimizer_index_cost_adj后索引范围扫描操作选择索引的变化.

drop table test purge;

SQL> create table test
  2  as
  3  select rownum as id,
  4         round(dbms_random.normal*10000) as val1,
  5         100+round(ln(rownum/3.25+2)) as val2,
  6         100+round(ln(rownum/3.25+2)) as val3,
  7         dbms_random.string('p',250) as pad
  8  from all_objects
  9  where rownum< =1000
 10  order by dbms_random.value;

SQL> create index idx_val2 on test (val2);

Index created.

Elapsed: 00:00:00.18
SQL> create index idx_val3 on test(val3);

Index created.

Elapsed: 00:00:00.09

SQL> show parameter optimizer_index_cost_adj

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
optimizer_index_cost_adj             integer     100

SQL> SELECT * FROM test WHERE val2 = 111 AND val3 = 111;
------------------------------------------------
| Id | Operation                   | Name     |
------------------------------------------------
|  0 | SELECT STATEMENT            |          |
|* 1 |  TABLE ACCESS BY INDEX ROWID| TEST     |
|* 2 |   INDEX RANGE SCAN          | IDX_VAL3 |
------------------------------------------------
1 - filter("VAL2"=11)
2 - access("VAL3"=11)

SQL> ALTER SESSION SET optimizer_index_cost_adj = 10;
SQL> SELECT * FROM test WHERE val1 = 111 AND val2 = 111;
------------------------------------------------
| Id | Operation                   | Name    |
------------------------------------------------
|  0 | SELECT STATEMENT            |         |
|* 1 |  TABLE ACCESS BY INDEX ROWID| TEST    |
|* 2 |   INDEX RANGE SCAN          | IDX_VAL2|
------------------------------------------------
1 - filter("VAL3"=111)
2 - access("VAL2"=111)

为了避免这种不稳定性,建议不要设置optimizer_index_cost_adj为一个很小的值.该参数是一个动态参数
可以在实例及会话级别进行修改.

TNS-01189: The listener could not authenticate the user

数据库服务器让系统管理员修改IP后启动监听报TNS-01189故障

[root@171db ~]# su - oracle
[oracle@171db ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 31-MAY-2013 10:49:58

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=171db)(PORT=1521)))
TNS-01189: The listener could not authenticate the user

下面是官方文档对这个故障的解释

TNS-01189: The listener could not authenticate the user
Cause: The user attempted to issue a privileged administrative command, but
could not be successfully authenticated by the listener using the local OS
authentication mechanism. This may occur due to one of the following reasons:
1. The user is running a version of LSNRCTL that is lower than the version of the
listener.
2. The user is attempting to administer the listener from a remote node.
3. The listener could not obtain the system resources needed to perform. the
authentication.
4. The local network connection between the listener and LSNRCTL was
terminated unexpectedly during authentication message exchange, such as if
LSNRCTL program was suddenly aborted.
5. The communication between the listener and LSNRCTL is being intercepted by
a malicious user.
6. The software that the user is running is not following the authentication
protocol, indicating a malicious user.
Action: Make sure that administrative commands are issued using the LSNRCTL
tool that is of a version equal or greater than the version of the listener, and that
the tool and the listener are running on the same node. You can issue the
VERSION command to find out the version of the listener. If a malicious user is
suspected, use the information provided in the listener log file to determine the
source and nature of the requests. Enable listener tracing for more information. If
the error persists, contact Oracle Support Services.

对于这个问题解决思路是先检查/etc/hosts的配置,因为修改过ip,现在ip是
172.18.100.211,原来是172.18.100.171,而监听使用的
是机器名:

[root@171db ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.18.100.171  171db

果然/etc/hosts中的ip是172.18.100.171没有修改过来
将其修改为172.18.100.211 171db
再来启动监听

[oracle@171db admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 31-MAY-2013 10:58:09

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Starting /DBSoftware/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.2.0 - Production
System parameter file is /DBSoftware/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /DBSoftware/app/oracle/diag/tnslsnr/171db/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.18.100.211)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.18.100.211)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date                31-MAY-2013 10:58:09
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /DBSoftware/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /DBSoftware/app/oracle/diag/tnslsnr/171db/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.18.100.211)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

[oracle@171db admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 31-MAY-2013 11:09:38

Copyright (c) 1991, 2010, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.18.100.211)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date                31-MAY-2013 10:58:09
Uptime                    0 days 0 hr. 11 min. 28 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /DBSoftware/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /DBSoftware/app/oracle/diag/tnslsnr/171db/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.18.100.211)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 2 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

问题解决了

ORA-01207: file is more recent than control file – old control file

一个实例从A机冷备份到B机启动数据库报ORA-01207故障:

ALTER DATABASE OPEN
Errors in file /DBSoftware/app/oracle/diag/rdbms/orcl/orcl/t
race/orcl_ora_10048.trc:
ORA-01122: database file 5 failed verification check
ORA-01110: data file 5: '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA.ORA'
ORA-01207: file is more recent than control file - old control file
ORA-1122 signalled during: ALTER DATABASE OPEN...

造成这个原因是因为控制文件与数据文件不一致
控制文件是旧的。此时我们可以通过重建控制文件或者从旧的数据备份开始恢复。
恢复步骤如下:

SQL> alter database backup controlfile to trace;

Database altered.

SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/DBSoftware/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_10048.trc

然后从跟踪文件找到创建控制文件的语句

SQL> shutdown immeidate;
SP2-0717: illegal SHUTDOWN option
SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup pfile=/DBSoftware/app/oracle/product/10.2.0/db_1/
dbs/initorcl.ora nomount
ORACLE instance started.

Total System Global Area 4977278976 bytes
Fixed Size                  2235016 bytes
Variable Size            3657434488 bytes
Database Buffers         1308622848 bytes
Redo Buffers                8986624 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS  NOARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 1168
  7  LOGFILE
  8    GROUP 1 '/DBSoftware/app/oracle/oradata/orcl/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/DBSoftware/app/oracle/oradata/orcl/redo02.log'  SIZE 50M BLOCKSIZE 512,
 10    GROUP 3 '/DBSoftware/app/oracle/oradata/orcl/redo03.log'  SIZE 50M BLOCKSIZE 512
 11  -- STANDBY LOGFILE
 12  DATAFILE
 13    '/DBSoftware/app/oracle/oradata/orcl/system01.dbf',
 14    '/DBSoftware/app/oracle/oradata/orcl/sysaux01.dbf',
 15    '/DBSoftware/app/oracle/oradata/orcl/undotbs01.dbf',
 16    '/DBSoftware/app/oracle/oradata/orcl/users01.dbf',
 17    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA.ORA',
 18    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA01.ORA',
 19    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA02.ORA',
 20    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA03.ORA',
 21    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA04.ORA',
 22    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA05.ORA',
 23    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA06.ORA',
 24    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA07.ORA',
 25    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA08.ORA',
 26    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA09.ORA',
 27    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA10.ORA',
 28    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA11.ORA',
 29    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA12.ORA',
 30    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA13.ORA',
 31    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA14.ORA',
 32    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA15.ORA',
 33    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA16.ORA',
 34    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA17.ORA',
 35    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA18.ORA',
 36    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA19.ORA',
 37    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/E:DATAHYGEIA20.ORA',
 38    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDAVE.ORA',
 39    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_IAS_ORASDPM.ORA',
 40    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_AUG.ORA',
 41    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_EONEPRF_IDX.ORA',
 42    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_MAR.ORA',
 43    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_BRSADATA.ORA',
 44    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDM_ARCHIVE.ORA',
 45    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV_BIPLATFORM.ORA',
 46    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_IAS_ORASDPXDMS.ORA',
 47    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_ENTX_MP_IDX.ORA',
 48    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_NOV.ORA',
 49    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA.ORA',
 50    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_DEC.ORA',
 51    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_ORABAM.ORA',
 52    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_PS_LG_IDX.ORA',
 53    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_MON_IDX.ORA',
 54    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLHYGEIA_MM.ORA',
 55    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV_MDS.ORA',
 56    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_IAS_ORASDPSDS.ORA',
 57    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_ND_IDX.ORA',
 58    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_TX_DT_IDX.ORA',
 59    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_ENTONE_IDX.ORA',
 60    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_JUL.ORA',
 61    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLOLTS_SVRMGSTORE.ORA',
 62    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLOLTS_BATTRSTORE.ORA',
 63    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_MO_LG_IDX.ORA',
 64    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_PL_LG_IDX.ORA',
 65    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDM.ORA',
 66    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLOLTS_DEFAULT.ORA',
 67    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLOLTS_ATTRSTORE.ORA',
 68    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_QA_HT_DATA.ORA',
 69    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_JUN.ORA',
 70    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_IAS_ORASDPLS.ORA',
 71    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_US_ND_IDX.ORA',
 72    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_JAN.ORA',
 73    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_OCT.ORA',
 74    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_TX_LG_IDX.ORA',
 75    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_DATA_MAY.ORA',
 76    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_INDX.ORA',
 77    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_SOAINFRA.ORA',
 78    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_TBS_OAAM_ND_HS_IDX.ORA',
 79    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLDEV1_OAM.ORA',
 80    '/DBSoftware/app/oracle/product/10.2.0/db_1/dbs/
D:APPADMINISTRATORORADATAORCLOLTS_CT_STORE.ORA',
 81    '/DBSoftware/app/oracle/oradata/orcl/system02.dbf',
 82    '/DBSoftware/app/oracle/oradata/orcl/DEV1_portalidx.dbf',
 83    '/DBSoftware/app/oracle/oradata/orcl/DEV1_iasactivities.dbf',
 84    '/DBSoftware/app/oracle/oradata/orcl/DEV1_urmserver.dbf',
 85    '/DBSoftware/app/oracle/oradata/orcl/DEV1_iaswebcenter.dbf',
 86    '/DBSoftware/app/oracle/oradata/orcl/DEV1_odi_user.dbf',
 87    '/DBSoftware/app/oracle/oradata/orcl/DEV1_iasjive.dbf',
 88    '/DBSoftware/app/oracle/oradata/orcl/DEV1_ocs.dbf',
 89    '/DBSoftware/app/oracle/oradata/orcl/DEV1_social.dbf',
 90    '/DBSoftware/app/oracle/oradata/orcl/DEV1_biplatform.dbf',
 91    '/DBSoftware/app/oracle/oradata/orcl/DEV1_orairm.dbf',
 92    '/DBSoftware/app/oracle/oradata/orcl/DEV1_ipm.dbf',
 93    '/DBSoftware/app/oracle/oradata/orcl/DEV1_portaldoc.dbf',
 94    '/DBSoftware/app/oracle/oradata/orcl/DEV1_portallog.dbf',
 95    '/DBSoftware/app/oracle/oradata/orcl/DEV1_webcenter_portlet.dbf',
 96    '/DBSoftware/app/oracle/oradata/orcl/DEV1_discoptm5cache.dbf',
 97    '/DBSoftware/app/oracle/oradata/orcl/DEV1_portal.dbf',
 98    '/DBSoftware/app/oracle/oradata/orcl/DEV1_discopstore.dbf',
 99    '/DBSoftware/app/oracle/oradata/orcl/DEV1_ocssearch.dbf',
100    '/DBSoftware/app/oracle/oradata/orcl/DEV1_mds.dbf',
101    '/DBSoftware/app/oracle/oradata/orcl/DEV1_discoptm5meta.dbf'
102  CHARACTER SET ZHS16GBK
103  ;

Control file created.



SQL> alter database open;

Database altered.

SQL> create spfile from pfile;

File created.

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

Total System Global Area 4977278976 bytes
Fixed Size                  2235016 bytes
Variable Size            3657434488 bytes
Database Buffers         1308622848 bytes
Redo Buffers                8986624 bytes
Database mounted.
Database opened.

再重建临时表空间

ALTER TABLESPACE TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/temp01.dbf' REUSE;
ALTER TABLESPACE DEV1_SOCIAL_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_socialtemp.dbf' REUSE;
ALTER TABLESPACE DEV1_ODI_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_odi_temp.dbf' REUSE;
ALTER TABLESPACE DEV1_IAS_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_iastemp.dbf' REUSE;
ALTER TABLESPACE DEV1_OCSSEARCH_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_ocssearchtemp.dbf' REUSE;
ALTER TABLESPACE DEV1_ORAIRM_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_orairmtemp.dbf' REUSE;
ALTER TABLESPACE DEV1_IPM_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_ipmtemp.dbf' REUSE;
ALTER TABLESPACE DEV1_OCS_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_ocstemp.dbf' REUSE;
ALTER TABLESPACE DEV1_URMSERVER_TEMP ADD TEMPFILE '/DBSoftware/app/oracle/oradata/orcl/DEV1_urmservertemp.dbf' REUSE;

rhel6.3 安装oracle10g,link步骤时报错make: *** [nmccollector] Error 2

在redhat6.3上安装10g时当安装到83%报如下错

 - Linking liborasdk
/oracle/u01/oracle/product/10.2.0/db_1/bin/genorasdksh
$Id: genorasdksh.sh 02-mar-2005.16:22:46 mchengjr Exp $
Generating FULL ORASDK library...
Creating /oracle/u01/oracle/product/10.2.0/db_1/lib/liborasdk.so.10.2
-rwxrwx---. 1 oracle oinstall 16887634 May 24 16:48 liborasdk.so.10.2
lrwxrwxrwx. 1 oracle oinstall 17 May 24 16:48 liborasdk.so -> liborasdk.so.10.2
/usr/bin/make -f ins_rdbms.mk ipc_udp/rm -f /oracle/u01/oracle/product/10.2.0/db_1/lib/libskgxp10.so
cp /oracle/u01/oracle/product/10.2.0/db_1/lib//libskgxpu.so /oracle/u01/oracle/product/10.2.0/db_1/lib/libskgxp10.so
/usr/bin/make -f ins_emdb.mk collector ORACLE_HOME=/oracle/u01/oracle/product/10.2.0/db_1/make -f /oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/ins_emdb.mk relink_exe EXENAME=nmccollector
make[1]: Entering directory `/oracle/u01/oracle/product/10.2.0/db_1/sysman/lib'
gcc -o /oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/nmccollector -L/oracle/u01/oracle/product/10.2.0/db_1/lib/ -L/oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/     `cat /oracle/u01/oracle/product/10.2.0/db_1/lib/sysliblist` -Wl,-rpath,/oracle/u01/oracle/product/10.2.0/db_1/lib -lm    `cat /oracle/u01/oracle/product/10.2.0/db_1/lib/sysliblist` -ldl -lm   -L/oracle/u01/oracle/product/10.2.0/db_1/lib -Wl,-export-dynamic /oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/snmccolm.o /oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/libnmccol.a /oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/libnmcbuf.a /oracle/u01/oracle/product/10.2.0/db_1/sysman/lib//libnmadbg.a /oracle/u01/oracle/product/10.2.0/db_1/rdbms/lib/libdsga10.a /oracle/u01/oracle/product/10.2.0/db_1/lib/libserver10.a /oracle/u01/oracle/product/10.2.0/db_1/lib/libclntsh.so    `cat /oracle/u01/oracle/product/10.2.0/db_1/lib/sysliblist` -ldl -lm
/oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/snmccolm.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[1]: *** [/oracle/u01/oracle/product/10.2.0/db_1/sysman/lib/nmccollector] Error 1
make[1]: Leaving directory `/oracle/u01/oracle/product/10.2.0/db_1/sysman/lib'
make: *** [nmccollector] Error 2

对于这个错可以先忽略让其继续安装,等安装完成打上05的补丁就行

绑定变量的优缺点与绑定变量窥视对执行计划的影响

绑定变量

绑定变量会从两个方面来影响应用程序.第一,从开发角度来说,使用绑定变量会使用程序变得简单或复杂
(更准确的来说是使用绑定变量会减少或增加代码量).在这种情况下,使用绑定变量的影响依赖于执行sql
语句的应用程序接口来定的,例如,如果你的程序是使用plsql编码那么使用绑定变量会变得容易,但是
如果你的应用程序是使用java的jdbc那么不使用绑定变量编码会容易些.第二从性能角度来看,使用绑定
变量有优点也有缺点.

使用绑定变量的优点
绑定变量的优点是允许在库缓存中共享游标这样可以避免硬解析以及硬解析所花的开锁.下面的例子说明了
使用绑定变量来共享游标的情况

SQL> create table t (n number(12),v varchar2(4000));

Table created

SQL> variable n number
SQL> variable v varchar2(32)
SQL> execute :n:=1;:v:='Helicon';

PL/SQL procedure successfully completed
n
---------
1
v
---------
Helicon

SQL> insert into t(n,v) values(:n,:v);

1 row inserted
n
---------
1
v
---------
Helicon

SQL> execute :n:=2;:v:='Trantor';

PL/SQL procedure successfully completed
n
---------
2
v
---------
Trantor

SQL> insert into t(n,v) values(:n,:v);

1 row inserted
n
---------
2
v
---------
Trantor

SQL> execute :n:=3;:v:='Kalgan';

PL/SQL procedure successfully completed
n
---------
3
v
---------
Kalgan

SQL> insert into t(n,v) values(:n,:v);

1 row inserted
n
---------
3
v
---------
Kalgan

SQL> commit;

Commit complete


SQL> select sql_id,sql_text,child_number,executions
  2  from v$sql where sql_text like'insert into t(n,v) values(:n,:v)%';

SQL_ID        SQL_TEXT                             CHILD_NUMBER EXECUTIONS
------------- -----------------------------------  ------------ ----------
dunwv1qwg6nrv insert into t(n,v) values(:n,:v)       0          3

然而有些情况下尽管使用了绑定变量还是会生成一些子游标.下面的例子同样使用
insert into t(n,v) values(:n,:v)语句只是将变量v的长度改为2000

SQL> variable v varchar2(2000)
SQL> execut :n:=4;:v:='Terminus';

PL/SQL 过程已成功完成。

SQL> insert into t(n,v) values(:n,:v);

已创建 1 行。

SQL> commit;

提交完成。

SQL> variable v varchar2(129)
SQL> execut :n:=5;:v:='JY';

PL/SQL 过程已成功完成。

SQL> insert into t(n,v) values(:n,:v);

已创建 1 行。

SQL> commit;

提交完成。

SQL> select sql_id,sql_text,child_number,executions
  2  from v$sql where sql_text like'insert into t(n,v) values(:n,:v)%';

SQL_ID        SQL_TEXT                                       CHILD_NUMBER EXECUTIONS
------------- ---------------------------------------------- ------------ ----------
dunwv1qwg6nrv insert into t(n,v) values(:n,:v)                    0          3
dunwv1qwg6nrv insert into t(n,v) values(:n,:v)                    1          2

一个新的子游标生成了(1)因为在前面三个insert语句与第四个与第五个insert语句的执行环境发生了改变.错误的匹配
可以通过查询v$sql_shared_cursor来查看原因,原因就是因为绑定变量

SQL> SELECT child_number, bind_mismatch
2 FROM v$sql_shared_cursor
3 WHERE sql_id = 'dunwv1qwg6nrv';
CHILD_NUMBER BIND_MISMATCH
------------ -------------
0 N
1 N

当数据库引擎应用绑定变量等级时会发什么了.使用绑定变量等级这个功能的目的是为了最小化子游标的个数.
根据绑定变量的大小分成四组.绑定变量长度小于等于32字节的为第一组.绑定变量长度在33和128字节之间的
为第二组. 绑定变量的长度在129和2000字节之间的为第三组,绑定变量长度大于2000字节的为第四组.
绑定变量的数字类型的变量的长度最大长度为22字节.下面的查询v$sql_bind_metadata视图显示了绑定变量
最大长度的一组.注意尽管使用的绑定变量的长度是129但是用到的长度还是2000

SQL> SELECT s.child_number, m.position, m.max_length,
  2  decode(m.datatype,1,'VARCHAR2',2,'NUMBER',m.datatype) AS datatype
  3  FROM v$sql s, v$sql_bind_metadata m
  4  WHERE s.sql_id = 'dunwv1qwg6nrv'
  5  AND s.child_address = m.address
  6  ORDER BY 1, 2;

CHILD_NUMBER   POSITION MAX_LENGTH DATATYPE
------------ ---------- ---------- ----------------------------------------
           0          1         22 NUMBER
           0          2         32 VARCHAR2
           1          1         22 NUMBER
           1          2       2000 VARCHAR2

如果说每一次都有一个新的子游标被创建,那么一个执行计划也会生成.一个新的执行计划是否等于
另一个子游标所使用的执行计划还是取决于绑定变量的值.

缺点
在where子句中使用绑定变量的缺点是查询优化器的关键的信息被隐藏了.事实上,对于查询优化器来说,
使用文本字面值会比绑定变量更好,使用文本值,它能够改善其评估.当优化器检查条件值是否超出可用值的
范围(小于最小或大于最大值)和当优化器使用直方图时尤其如此.下面举例说明这种情况.创建一个表t,它有
1000行数据,在id列上,它的值从1到1000

SQL> create table t(id number(12),name varchar2(12));

表已创建。
SQL> create index idx_t on t(id);

索引已创建。

SQL> begin
  2  for i in 1 .. 1000 loop
  3   insert into t values(i,''||i);
  4  end loop;
  5  commit;
  6  end;
  7  /

PL/SQL 过程已成功完成。

SQL> SELECT count(id), count(DISTINCT id), min(id), max(id) FROM t;

 COUNT(ID) COUNT(DISTINCTID)    MIN(ID)    MAX(ID)
---------- ----------------- ---------- ----------
      1000              1000          1       1000

当一个用户要从表t中查询id小于等于990的所有记录时,查询优化器(由于对象统计信息)知道这个表的99%
的记录被选择了,因此查询优化器会使用全表扫描.同时也要注意查询所返回的行数据所对应的评估基数(
执行计划中的行数)

SQL> select count(name) from t where id< =990;

COUNT(NAME)
-----------
        990


执行计划
----------------------------------------------------------
Plan hash value: 2966233522

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |    21 |     3   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |      |     1 |    21 |            |          |
|*  2 |   TABLE ACCESS FULL| T    |   990 | 20790 |     3   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("ID"<=990)

Note
-----
   - dynamic sampling used for this statement (level=2)


统计信息
----------------------------------------------------------
          7  recursive calls
          0  db block gets
         20  consistent gets
          0  physical reads
          0  redo size
        340  bytes sent via SQL*Net to client
        376  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

当另一个用户从表t中查询id小于10的所有记录时,查询优化器会知道只有1%的数据被选择.因此优化器会使用
索引扫描.

SQL> select count(name) from t where id<10;

COUNT(NAME)
-----------
          9


执行计划
----------------------------------------------------------
Plan hash value: 1883549804

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

| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time

     |

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

|   0 | SELECT STATEMENT             |       |     1 |    21 |     3   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE              |       |     1 |    21 |            |     |

|   2 |   TABLE ACCESS BY INDEX ROWID| T     |     9 |   189 |     3   (0)| 00:00:01 |

|*  3 |    INDEX RANGE SCAN          | IDX_T |     9 |       |     2   (0)| 00:00:01 |

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


Predicate Information (identified by operation id):
---------------------------------------------------

   3 - access("ID"<10)

Note
-----
   - dynamic sampling used for this statement (level=2)


统计信息
----------------------------------------------------------
          9  recursive calls
          0  db block gets
         14  consistent gets
          0  physical reads
          0  redo size
        339  bytes sent via SQL*Net to client
        376  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
          
          
 

无论何时处理绑定变量,查询优化器会忽略绑定变量的值.因此想要很好的评估谓词的基数变得不可能.
为了避免这个问题,从oracle9i开始引入了绑定变量窥视功能

注意:绑定变量窥视功能在oracle9i中不支持jdbc驱动

绑定变量窥视功能很简单.当在进行物理优化阶段时,查询优化器将会窥视绑定变量的值并使用它们当作文本值.
使用这种做法的问题是生成的执行计划依赖于第一次执行所提供的值.下面将举例说明这个问题,第一次执行时
使用id< =990作为查询条件.然后查询优化器会选择执行全表扫描.正是这种选择,自从这个游标被共享后(sql_id 和子游标相同),那么它将会影响使用id<10作为查询条件的第二个查询.

SQL> variable id number
SQL> execute :id:=990;

PL/SQL 过程已成功完成。

SQL> set autotrace on;
SQL> select count(name) from t where id< =:id;

COUNT(NAME)
-----------
        990


执行计划
----------------------------------------------------------
Plan hash value: 2966233522

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |    21 |     2   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |      |     1 |    21 |            |          |
|*  2 |   TABLE ACCESS FULL| T    |    50 |  1050 |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("ID"<=TO_NUMBER(:ID))

Note
-----
   - dynamic sampling used for this statement (level=2)


统计信息
----------------------------------------------------------
        278  recursive calls
          0  db block gets
         52  consistent gets
          9  physical reads
          0  redo size
        340  bytes sent via SQL*Net to client
        376  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          4  sorts (memory)
          0  sorts (disk)
          1  rows processed

SQL> variable id number
SQL> execute :id:=10;

PL/SQL 过程已成功完成。

SQL> set autotrace on
SQL> select count(name) from t where id< =:id;

COUNT(NAME)
-----------
         10


执行计划
----------------------------------------------------------
Plan hash value: 2966233522

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |    21 |     2   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |      |     1 |    21 |            |          |
|*  2 |   TABLE ACCESS FULL| T    |    50 |  1050 |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("ID"<=TO_NUMBER(:ID))

Note
-----
   - dynamic sampling used for this statement (level=2)


统计信息
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          4  consistent gets
          0  physical reads
          0  redo size
        339  bytes sent via SQL*Net to client
        376  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

当然,如果第一次执行条件id< =10的查询,查询优化器会选择索引扫描,注意为了避免与之前的查询的游标 共享,可以重启数据库或清空共享池,我是重启数据库

SQL> variable id number;
SQL> execute :id:=10;

PL/SQL 过程已成功完成。

SQL> set autotrace on;
SQL> select count(name) from t where id=:id;

COUNT(NAME)
———–
          1


执行计划
———————————————————-
Plan hash value: 1883549804

——————————————————————————–

——

| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time

     |

————————————————————————————–

|   0 | SELECT STATEMENT             |       |     1 |    21 |     1   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE              |       |     1 |    21 |            |     |

|   2 |   TABLE ACCESS BY INDEX ROWID| T     |    10 |   210 |     1   (0)| 00:00:01 |

|*  3 |    INDEX RANGE SCAN          | IDX_T |     4 |       |     1   (0)| 00:00:01 |

————————————————————————————–


Predicate Information (identified by operation id):
—————————————————

   3 – access(“ID”=TO_NUMBER(:ID))

Note
—–
   – dynamic sampling used for this statement (level=2)


统计信息
———————————————————-
        278  recursive calls
          0  db block gets
         49  consistent gets
          7  physical reads
          0  redo size
        339  bytes sent via SQL*Net to client
        376  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          4  sorts (memory)
          0  sorts (disk)
          1  rows processed



SQL> execute :id:=990;

PL/SQL 过程已成功完成。

SQL> set autotrace on;
SQL> select count(name) from t where id< =:id;

COUNT(NAME)
-----------
      990


执行计划
----------------------------------------------------------
Plan hash value: 1883549804

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

------

| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time

     |

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

|   0 | SELECT STATEMENT             |       |     1 |    21 |     1   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE              |       |     1 |    21 |            |     |

|   2 |   TABLE ACCESS BY INDEX ROWID| T     |    10 |   210 |     1   (0)| 00:00:01 |

|*  3 |    INDEX RANGE SCAN          | IDX_T |     4 |       |     1   (0)| 00:00:01 |

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


Predicate Information (identified by operation id):
---------------------------------------------------

   3 - access("ID"=TO_NUMBER(:ID))

Note
-----
   - dynamic sampling used for this statement (level=2)


统计信息
----------------------------------------------------------
        278  recursive calls
          0  db block gets
         49  consistent gets
          7  physical reads
          0  redo size
        339  bytes sent via SQL*Net to client
        376  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          4  sorts (memory)
          0  sorts (disk)
          1  rows processed

必须要理解的是游标保存在库缓存中共享多久它就能被重用多久,这种情况是不会顾及执行计划的效率的

为了解决这个问题,在oracle11g中有一个新功能叫做扩展游标共享(也叫自适应游标共享).它的目的就是
识别哪些重复使用一个已经存的可用的游标而导致效率低下的执行.为了理解这个功能是怎样工作的.
我们先来查看一个v$sql视图在oracle11g中的变化:
is_bind_sensitive:如果不仅仅绑定变量窥视会被用来生成执行计划而且执行计划还依赖于窥视的值
那么这个列的值就为Y;否则为N

is_bind_aware:这个列指示游标是否正在使用扩展游标共享,如果是,这个列的值为Y;如果不是这个列的值为N.
如果这个列的值为N.那么这个游标就被标记为过期的它将不再被使用.

is_shareable:这个列指示游标是否能被共享.如果能被共享这个列的值就为Y.否则为N.如果为N,
这个游标就被标记为过期的它将不再被使用.

在前面的例子中,游标能共享但是对绑定变量不敏感也不能不扩展游标

SQL> SELECT child_number, is_bind_sensitive, is_bind_aware, is_shareable
2 FROM v$sql WHERE sql_id = ‘7y1vyk0wnb2ut’ ORDER BY child_number;

CHILD_NUMBER IS_BIND_SENSITIVE IS_BIND_AWARE IS_SHAREABLE
———— —————– ————- ————
0 N N Y

当使用不同的变量值让游标执行多次时会出现意想不到的情况.在使用id=10和id=990执行多次,对v$sql的查询
会有不同.注意,v$sql视图中child_number为0的游标是不能共享但两个新的子游标使用扩展游标共享

SQL> SELECT child_number, is_bind_sensitive, is_bind_aware, is_shareable
2 FROM v$sql
3 WHERE sql_id = '7y1vyk0wnb2ut'
4 ORDER BY child_number;
CHILD_NUMBER IS_BIND_SENSITIVE IS_BIND_AWARE IS_SHAREABLE
------------ ----------------- ------------- ------------
0                 N                   N           N
1                 N                   Y           Y
2                 N                   Y           Y

你可能希望查看这个游标相关的执行计划,你可以看到一个新的子游标的执行计划是执行全表扫描,而另外的
执行计划是执行索引扫描

----------------------------------------------------------
Plan hash value: 1883549804

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

| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time

     |

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

|   0 | SELECT STATEMENT             |       |     1 |    21 |     1   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE              |       |     1 |    21 |            |     |

|   2 |   TABLE ACCESS BY INDEX ROWID| T     |    10 |   210 |     1   (0)| 00:00:01 |

|*  3 |    INDEX RANGE SCAN          | IDX_T |     4 |       |     1   (0)| 00:00:01 |

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

----------------------------------------------------------
Plan hash value: 1883549804

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |     1 |    21 |     2   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |      |     1 |    21 |            |          |
|*  2 |   TABLE ACCESS FULL| T    |    990 |  1050 |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------

----------------------------------------------------------
Plan hash value: 1883549804

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

------

| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time

     |

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

|   0 | SELECT STATEMENT             |       |     1 |    21 |     1   (0)| 00:00:01 |

|   1 |  SORT AGGREGATE              |       |     1 |    21 |            |     |

|   2 |   TABLE ACCESS BY INDEX ROWID| T     |    10 |   210 |     1   (0)| 00:00:01 |

|*  3 |    INDEX RANGE SCAN          | IDX_T |     4 |       |     1   (0)| 00:00:01 |

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

为了进一步分析生成两个子游标的原因,有一些新的动态性能视图可以使用
v$sql_cs_statistics, v$sql_cs_selectivity,v$sql_cs_histogram,第一步来显示每个子游标的相关
执行统计信息是否使用了窥视.在下面的输出中,可以确定子游标为1的处理的行数要比子游标为2的多很多.
因此,在这种情况,查询优化器选择全表扫描而另一个使用索引扫描

SQL> SELECT child_number, peeked, executions, rows_processed, buffer_gets
2 FROM v$sql_cs_statistics
3 WHERE sql_id = '7y1vyk0wnb2ut'
4 ORDER BY child_number;
CHILD_NUMBER PEEKED EXECUTIONS ROWS_PROCESSED BUFFER_GETS
------------ ------ ---------- -------------- -----------
0              Y         1        10                  3
1              Y         1       990                 19
2              Y         1        10                  3

v$sql_cs_selectivity视图显示了每一个子游标每一个谓词相关的基数选择范围.事实上,数据库引擎不会
对每一个绑定变量值创建一个新的子游标而是让一组值有相同的选择范围,那么这一组值有相同的执行计划.

SQL> SELECT child_number, predicate, low, high
2 FROM v$sql_cs_selectivity
3 WHERE sql_id = '7y1vyk0wnb2ut'
4 ORDER BY child_number;
CHILD_NUMBER PREDICATE LOW           HIGH
------------ --------- ---------- ----------
1            

总之,如果为了要增加查询优化器生成高效的执行计划的概率你不应该使用绑定变量,绑定变量窥视可能会有帮助,
但不幸地是,有时会生成一个低效的执行计划.唯一的例外是只有在oracle11G中使用了自适应游标共享才解决这个问题

任何功能只有当它的优点大于它的缺点时才选择使用.在有些情况下很容易判断,例如,在没有where子句的情况下,
sql语句没有理由不使用绑定变量(如,insert语句).另一方面当查询优化器使用直方图提供重要信息时要不惜代价的
避免使用绑定变量否则使用绑定变量窥视有很高的风险.在其它的情况是否使用绑定变量主要考虑以下两点:

sql语句处理少量数据:每当少量数据被处理时,sql语句的解析时间可能接近或超过sql语句的执行时间.在这种情况下
使用绑定变量通常是可取的办法.尤其是对哪些经常执行的sql语句来说更是如此.通常这样的语句使用在数据录入系统
(也就是通常所说的OLTP系统).

sql语句处理大量数据:每当大量数据被处理时,sql语句的解析时间通常比sql语句的执行时间低几个数量级.在这种
情况下,使用绑定变量对整个sql语句的响应时间不会有什么影响,但它可能会增加查询优化器生成低效执行计划的概率.
因此,通常这时是不使用绑定变量.一般来说,象批量job,报表,或数据仓库(OLAP)是不使用绑定变量的

修改参数引发的ORA-00600: internal error code, arguments: [qctcte1],..

将cursor_sharing从EXACT修改为similar为了降低硬解析但是执行下面的语句时报

ORA-00600: internal error code, arguments: [qctcte1], [0], [], [], [], [], []

select t.*, level as org_level from (select a.aab034 as center_id, a.aab034 as org_code, b.aaa013 as org_name,
to_number(a.aaz198) as org_id, :"SYS_B_0" as org_up_id, :"SYS_B_1" as org_type from af01 a, aa13 b
where a.aab034 = b.aaa027 union all select a.aaa027 as center_id, a.baf013 as org_code, b.aab069 as org_
name, to_number(a.aaf013) as org_id, to_number(c.aaz198) as org_up_id, :"SYS_B_2" as org_type fro
m af08 a, ae10 b, af01 c where a.aaf013 = b.aaz001 and a.aaa027 = c.aab034 union all select a.aaa027 as center_id,
c.aaf030 as org_code, b.aab069 as org_name, to_number(c.aaz070) as org_id, to_number(a.aaf013
) as org_up_id, :"SYS_B_3" as org_type from af08 a, ae10 b, af02 c where c.aaz070 = b.aaz001 and c.aaf013 =
a.aaf013) t start with org_up_id = :"SYS_B_4" connect by prior org_id = org_up_id order siblings by org_code

后将cursor_sharing从similar修改为exact解决了这个问题
看来调整参数会带来意想不到的结果
修改cursor_sharing参数引发的ORA-00600: internal error code, arguments: [qctcte1], [0], []..

ORA-27090,ORA-00600: internal error code, arguments: [4194],的解决方法

由于突然断电,在恢复供电后启动数据库报以下错误信息:

ALTER DATABASE OPEN
Fri May 17 14:22:14 CST 2013
Beginning crash recovery of 1 threads
 parallel recovery started with 7 processes
Fri May 17 14:22:14 CST 2013
Started redo scan
Fri May 17 14:22:14 CST 2013
Completed redo scan
 57 redo blocks read, 4 data blocks need recovery
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p003_14475.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Additional information: 3
Additional information: 1
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Warning: recovery process cannot use async I/O
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p006_14483.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Additional information: 3
Additional information: 1
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Warning: recovery process cannot use async I/O
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p004_14477.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Additional information: 3
Additional information: 1
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Warning: recovery process cannot use async I/O
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p005_14479.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Additional information: 3
Additional information: 1
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p000_14469.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Additional information: 3
Additional information: 1
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Warning: recovery process cannot use async I/O
Fri May 17 14:22:15 CST 2013
Warning: recovery process cannot use async I/O
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p001_14471.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Additional information: 3
Additional information: 1
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Warning: recovery process cannot use async I/O
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p002_14473.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Additional information: 3
Additional information: 1
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Warning: recovery process cannot use async I/O
Fri May 17 14:22:15 CST 2013
Started redo application at
 Thread 1: logseq 15220, block 3
Fri May 17 14:22:15 CST 2013
Recovery of Online Redo Log: Thread 1 Group 2 Seq 15220 Reading mem 0
  Mem# 0: /oradata/test/redo02.ora
  Mem# 1: /oradata/test/redo12.ora
Fri May 17 14:22:15 CST 2013
Completed redo application
Fri May 17 14:22:15 CST 2013
Completed crash recovery at
 Thread 1: logseq 15220, block 60, scn 12785313401558
 4 data blocks read, 4 data blocks written, 57 redo blocks read
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p001_14471.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Additional information: 128
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p006_14483.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Additional information: 128
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p005_14479.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Additional information: 128
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p004_14477.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Additional information: 128
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p003_14475.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Additional information: 128
Additional information: 65536
Fri May 17 14:22:15 CST 2013
Errors in file /orac/admin/test/bdump/test_p002_14473.trc:
ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Additional information: 128
Additional information: 65536
Fri May 17 14:22:16 CST 2013
Thread 1 advanced to log sequence 15221 (thread open)
Thread 1 opened at log sequence 15221
  Current log# 3 seq# 15221 mem# 0: /oradata/test/redo03.ora
  Current log# 3 seq# 15221 mem# 1: /oradata/test/redo13.ora
Successful open of redo thread 1
Fri May 17 14:22:17 CST 2013
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Fri May 17 14:22:17 CST 2013
SMON: enabling cache recovery
Fri May 17 14:22:19 CST 2013
Successfully onlined Undo Tablespace 1.
Fri May 17 14:22:19 CST 2013
SMON: enabling tx recovery
Fri May 17 14:22:19 CST 2013
Database Characterset is ZHS16GBK
Opening with internal Resource Manager plan
Fri May 17 14:22:20 CST 2013
Errors in file /orac/trace/test_ora_14467.trc:
ORA-00600: internal error code, arguments: [4194], [40], [4], [], [], [], [], []
Doing block recovery for file 2 block 27642
Resuming block recovery (PMON) for file 2 block 27642
Block recovery from logseq 15221, block 53 to scn 12785313405025
Fri May 17 14:22:24 CST 2013
Recovery of Online Redo Log: Thread 1 Group 3 Seq 15221 Reading mem 0
  Mem# 0: /oradata/test/redo03.ora
  Mem# 1: /oradata/test/redo13.ora
Block recovery stopped at EOT rba 15221.55.16
Block recovery completed at rba 15221.55.16, scn 2976.3490728813
Doing block recovery for file 2 block 89
Resuming block recovery (PMON) for file 2 block 89
Block recovery from logseq 15221, block 53 to scn 12785313401708
Fri May 17 14:22:24 CST 2013
Recovery of Online Redo Log: Thread 1 Group 3 Seq 15221 Reading mem 0
  Mem# 0: /oradata/test/redo03.ora
  Mem# 1: /oradata/test/redo13.ora
Block recovery completed at rba 15221.55.16, scn 2976.3490728813
Fri May 17 14:22:24 CST 2013
Errors in file /orac/trace/test_ora_14467.trc:
ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []
DEBUG: Replaying xcb 0x1196da808, pmd 0x118394558 for failed op 8
Doing block recovery for file 2 block 4266
No block recovery was needed
Fri May 17 14:22:26 CST 2013
Errors in file /orac/trace/test_ora_14467.trc:
ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []
ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []
Fri May 17 14:22:27 CST 2013
Errors in file /orac/trace/test_ora_14467.trc:
ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []
ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []
Fri May 17 14:22:31 CST 2013
DEBUG: Replaying xcb 0x1196da808, pmd 0x118394558 for failed op 8
Doing block recovery for file 2 block 4266
No block recovery was needed
Fri May 17 14:22:33 CST 2013
Errors in file /orac/admin/test/bdump/test_pmon_14433.trc:
ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []
Fri May 17 14:22:34 CST 2013
Errors in file /orac/admin/test/bdump/test_pmon_14433.trc:
ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []
PMON: terminating instance due to error 472

对于ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O
这个错误可以修改操作系统内核参数
内核参数的值:fs.aio-max-nr设置太低,推荐设置为fs.aio-max-nr= 3145728。修改参数使用/sbin/sysctl -p重新加载参数后,重启数据库即可。

对于ORA-00600: internal error code, arguments: [4194], [56], [4], [], [], [], [], []

这个是回滚表空间出错,
可以先使用手功管理的回滚表空间的方式将数据库打开
设置如下参数

undo_tablespace='SYSTEM'
undo_management='MANUAL'
SQL> create pfile from spfile;

File created.

[root@powerdb dbs]# vi inittest.ora
test.__db_cache_size=2868903936
test.__java_pool_size=16777216
test.__large_pool_size=16777216
test.__shared_pool_size=285212672
test.__streams_pool_size=16777216
*.audit_file_dest='/orac/admin/test/adump'
*.background_dump_dest='/orac/admin/test/bdump'
*.compatible='10.2.0.5.0'
*.control_files='/oradata/test/control01.ctl','/oradata/test/control02.ctl','/oradata/test/control03.ctl'
*.core_dump_dest='/orac/admin/test/cdump'
*.db_block_size=8192
*.db_cache_size=0
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='test'
*.db_recovery_file_dest='/orac/flash_recovery_area'
*.db_recovery_file_dest_size=21474836480
*.db_writer_processes=5
*.dispatchers='(PROTOCOL=TCP) (SERVICE=testXDB)'
*.job_queue_processes=10
*.max_dump_file_size='500'
*.open_cursors=700
*.optimizer_mode='ALL_ROWS'
*.pga_aggregate_target=805306368
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.sessions=600
*.sga_max_size=3221225472
*.sga_target=3221225472
*.sort_area_size=1048576
#*.undo_management='AUTO'
*.undo_retention=120
#*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/orac/trace'
undo_tablespace='SYSTEM'
undo_management='MANUAL'

修改参数后使用修改的参数文件来启动数据库

SQL> startup pfile=/orac/10.2.0/db_1/dbs/inittest.ora
ORACLE instance started.

Total System Global Area 3221225472 bytes
Fixed Size                  2099752 bytes
Variable Size             335545816 bytes
Database Buffers         2868903936 bytes
Redo Buffers               14675968 bytes
Database mounted.
Database opened.

然后创建新的回滚表空间

SQL> create undo tablespace undotbs02 datafile '/oradata/test/undotbs02.dbf' size 5G;

Tablespace created.

删除原来的回滚表空间

SQL> drop tablespace undotbs1;

Tablespace dropped.

将回滚表空间设置为新创建的回滚表空间

SQL> alter system set undo_tablespace="undotbs02" scope=spfile;

System altered.

将回滚表空间管理方式设置为自动

SQL> alter system set undo_management=auto scope=spfile;

System altered.

修改服务器参数文件

SQL> create pfile from spfile;

File created.

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

Total System Global Area 3221225472 bytes
Fixed Size                  2099752 bytes
Variable Size             352323032 bytes
Database Buffers         2852126720 bytes
Redo Buffers               14675968 bytes
Database mounted.
Database opened.
SQL> select * from v$tablespace;

       TS# NAME                           INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
         0 SYSTEM                         YES NO  YES
         2 SYSAUX                         YES NO  YES
         4 USERS                          YES NO  YES
         3 TEMP                           NO  NO  YES
         6 HYGEIA                         YES NO  YES
         9 UNDOTBS02                      YES NO  YES

6 rows selected.

Linux系统下挂载NTFS移动硬盘的一个例子

先要下载ntfs-3g

下载地址:http://www.tuxera.com/community/ntfs-3g-download/
步骤一:解压安装NTFS-3G。

tar -xvzf ntfs-3g_ntfsprogs-2013.1.13.tgz

cd ntfs-3g_ntfsprogs-2013.1.13
执行安装过程如下所示:
  ./configure
  make
  make install
  之后系统会提示安装成功,下面就可以用ntfs-3g来实现对NTFS分区的读写了
步骤二:配置挂载NTFS格式的移动硬盘

1. 首先得到NTFS分区的信息

  sudo fdisk -l | grep NTFS
[[root@node6 ~]# sudo fdisk -l | grep NTFS
/dev/sdd1   *           1      601099   312571136    7  HPFS/NTFS
[root@node6 ~]#

2. 设置挂载点,用如下命令实现挂载

[root@node6 ~]# mkdir -p /jybackup
  mount -t ntfs-3g  

[root@node6 fuse-2.7.4]# mount -t ntfs-3g /dev/sdd1 /jybackup
可能会报错
FATAL: Module fuse not found.
ntfs-3g-mount: fuse device is missing, try 'modprobe fuse' as root

意思是没找到fuse模块,下载

http://jaist.dl.sourceforge.net/sourceforge/fuse/fuse-2.7.4.tar.gz


#tar zxvf fuse-2.7.4.tar.gz

#cd fuse-2.7.4

#./configure --prefix=/usr

#make

#make install

#make clean

注意:执行./configure别忘了加参数–prefix=/usr,否则默认安装在/usr/local/lib,这样有需要编辑/etc /ld.so.conf把/usr/local/lib加进去,再执行/sbin/ldconfig,不然安装ntfs-3g会有错误。

然后再进行挂载

[root@node6 fuse-2.7.4]# mount -t ntfs-3g /dev/sdd1 /jybackup
[root@node6 fuse-2.7.4]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             125G   13G  106G  11% /
/dev/sda1              99M   18M   76M  20% /boot
tmpfs                  28G     0   28G   0% /dev/shm
/dev/sdc1             111G  104M  105G   1% /backup
/dev/sdd1             299G   95G  204G  32% /jybackup

从输出结果可以看到/dev/sdd1已经被mount到系统中了

3. 如果想实现开机自动挂载,可以在/etc/fstab里面添加如下格式语句
   ntfs-3g silent,umask=0,locale=zh_CN.utf8 0 0
  这样可以实现NTFS分区里中文文件名的显示。

4. 卸载分区可以用umount实现,用
  umount   或者   umount

重建控制文件时resetlogs与noresetlogs的使用情况

重建控制文件时resetlogs与noresetlogs的使用情况

控制文件中记录着数据库的数据文件,日志文件,备份数据等信息,更为重要的,控制文件中还记录了数据库的检查点
和scn信息,这些信息在数据恢复的过程中将起到关键性作用.

一个正常运行的数据库,通常控制文件都存在多份镜像,这些镜像的内容是完全相同的,oracle缺省就创建多份控制
文件更说明了控制文件的重要:

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/product/11.2.0/oradata/jingyong/control01.ctl
/u01/app/oracle/product/11.2.0/oradata/jingyong/control02.ctl

可以通过如下一条命令将控制文件的创建语句备份到跟踪文件中:

SQL> alter database backup controlfile to trace;

Database altered.

SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_18818.trc

SQL> host sz /u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_18818.trc
rz
Starting zmodem transfer.  Press Ctrl+C to cancel.
  100%       8 KB    8 KB/s 00:00:01       0 Errors

此跟踪文件中会记录控制文件的创建脚本,脚本包含两个主要的段落,其中一段如下所示:

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "JINGYONG" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo01.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo02.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo03.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbf',
  '/u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbf',
  '/u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbf',
  '/u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf',
  '/u01/app/oracle/product/11.2.0/oradata/jingyong/example01.dbf',
  '/u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbf'
CHARACTER SET ZHS16GBK
;

当数据库处于nomount状态下时,可以通过运行这段脚本创建控制文件,控制文件会自动创建到参数文件中
记录控制文件的位置(原来的控制文件在创建过程会被覆盖).这里需要理解的一个主要选项是:
noresetlogs/resetlogs.在跟踪文件中包含如下注释,详细解释了这两个选项的含义:

-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script. file, edited as necessary, and executed when there is a
-- need to re-create the control file.

当数据库当前的redo log都可用时,可以通过noresetlogs参数重建控制文件,此时oracle能够从日志文件中
读取redo信息,记录到控制文件中,由于redo中记录的信息足以重演所有提交成功的事务,所以最终能够实现
完全恢复,成功打开数据库,这时的数据库就如同进行了一次断电之后的实例恢复,数据没有损失,重做日志
可以继续向前写入:

下面测试来看一下以noresetlogs重建控制文件进行数据库恢复的过程
先在数据库正常运行状态下对控制文件执行一次转储:

SQL> alter session set events 'immediate trace name controlf level 12';

Session altered.

SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_19350.trc

这个转储文件中将包含数据库的检查点,redo thread信息,数据文件等信息,看一下
log file records内容:

***************************************************************************
LOG FILE RECORDS
***************************************************************************
 (size = 72, compat size = 72, section max = 16, section in-use = 3,
  last-recid= 3, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 10, numrecs = 16)
LOG FILE #1:
  name #3: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo01.log
 Thread 1 redo log links: forward: 2 backward: 0
 siz: 0x19000 seq: 0x00000010 hws: 0x2 bsz: 512 nab: 0x1e flg: 0x1 dup: 1
 Archive links: fwrd: 0 back: 0 Prev scn: 0x0000.000ea466
 Low scn: 0x0000.000ea474 05/02/2013 11:40:58
 Next scn: 0x0000.000ea4db 05/02/2013 11:44:07
LOG FILE #2:
  name #2: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo02.log
 Thread 1 redo log links: forward: 3 backward: 1
 siz: 0x19000 seq: 0x00000011 hws: 0x1 bsz: 512 nab: 0xffffffff flg: 0x8 dup: 1
 Archive links: fwrd: 0 back: 0 Prev scn: 0x0000.000ea474
 Low scn: 0x0000.000ea4db 05/02/2013 11:44:07
 Next scn: 0xffff.ffffffff 01/01/1988 00:00:00
LOG FILE #3:
  name #1: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo03.log
 Thread 1 redo log links: forward: 0 backward: 2
 siz: 0x19000 seq: 0x0000000f hws: 0x2 bsz: 512 nab: 0x2 flg: 0x1 dup: 1
 Archive links: fwrd: 0 back: 0 Prev scn: 0x0000.000e8ed8
 Low scn: 0x0000.000ea466 05/02/2013 11:40:52
 Next scn: 0x0000.000ea474 05/02/2013 11:40:58

从记录信息中我们可以看到redo02.log文件的next scn:0xffff.ffffffff,所以redo02.log文件是当前的
日志文件,我们可以从v$log视图中查看当前的重做日志组

SQL> select group#,status from v$log;

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 CURRENT
         3 INACTIVE

接下来通过shutdown abort模拟一次数据库故障:

SQL> shutdown abort;
ORACLE instance shut down.

启动数据库到nomount状态,再来使用noresetlogs参数来重建控制文件:

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  238530560 bytes
Fixed Size                  1335724 bytes
Variable Size             150998612 bytes
Database Buffers           83886080 bytes
Redo Buffers                2310144 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "JINGYONG" NORESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo02.log'  SIZE 50M BLOCKSIZE 512,
 10    GROUP 3 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo03.log'  SIZE 50M BLOCKSIZE 512
 11  -- STANDBY LOGFILE
 12  DATAFILE
 13    '/u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbf',
 14    '/u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbf',
 15    '/u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbf',
 16    '/u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf',
 17    '/u01/app/oracle/product/11.2.0/oradata/jingyong/example01.dbf',
 18    '/u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbf'
 19  CHARACTER SET ZHS16GBK
 20  ;

Control file created.

此时再来对控制文件进行一次转储,检查log file records部分:

SQL> alter session set events 'immediate trace name controlf level 12';

Session altered.

SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_19438.trc

***************************************************************************
LOG FILE RECORDS
***************************************************************************
 (size = 72, compat size = 72, section max = 16, section in-use = 3,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 10, numrecs = 16)
LOG FILE #1:
  name #2: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo01.log
 Thread 1 redo log links: forward: 2 backward: 0
 siz: 0x19000 seq: 0x00000010 hws: 0x2 bsz: 512 nab: 0x1e flg: 0x0 dup: 1
 Archive links: fwrd: 2 back: 3 Prev scn: 0x0000.000ea466
 Low scn: 0x0000.000ea474 05/02/2013 11:40:58
 Next scn: 0x0000.000ea4db 05/02/2013 11:44:07
LOG FILE #2:
  name #1: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo02.log
 Thread 1 redo log links: forward: 3 backward: 1
 siz: 0x19000 seq: 0x00000011 hws: 0x1 bsz: 512 nab: 0xffffffff flg: 0xa dup: 1
 Archive links: fwrd: 0 back: 1 Prev scn: 0x0000.000ea474
 Low scn: 0x0000.000ea4db 05/02/2013 11:44:07
 Next scn: 0xffff.ffffffff 01/01/1988 00:00:00
LOG FILE #3:
  name #3: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo03.log
 Thread 1 redo log links: forward: 0 backward: 2
 siz: 0x19000 seq: 0x0000000f hws: 0x2 bsz: 512 nab: 0x2 flg: 0x0 dup: 1
 Archive links: fwrd: 1 back: 0 Prev scn: 0x0000.00000000
 Low scn: 0x0000.000ea466 05/02/2013 11:40:52
 Next scn: 0x0000.000ea474 05/02/2013 11:40:58

从上面的记录我们可以看到重建的控文件能够从当前的日志文件获得正确的SCN及时间点等信息.同样地,控制
文件也能够从数据文件中获得详细的检查点信息:

***************************************************************************
DATA FILE RECORDS
***************************************************************************
 (size = 520, compat size = 520, section max = 100, section in-use = 6,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 11, numrecs = 100)
DATA FILE #1:
  name #9: /u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbf
creation size=0 block size=8192 status=0x12 head=9 tail=9 dup=1
 tablespace 0, index=1 krfil=1 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:119 scn: 0x0000.000ea4db 05/02/2013 11:44:07
 Stop scn: 0xffff.ffffffff 05/02/2013 12:44:28
 Creation Checkpointed at scn:  0x0000.00000007 08/13/2009 23:00:53
 thread:0 rba:(0x0.0.0)
 .....
 DATA FILE #2:
  name #8: /u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbf
creation size=0 block size=8192 status=0x12 head=8 tail=8 dup=1
 tablespace 1, index=2 krfil=2 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:119 scn: 0x0000.000ea4db 05/02/2013 11:44:07
 Stop scn: 0xffff.ffffffff 05/02/2013 12:44:28
 Creation Checkpointed at scn:  0x0000.00000874 08/13/2009 23:00:57
 thread:0 rba:(0x0.0.0)
 .....
 DATA FILE #3:
  name #7: /u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbf
creation size=0 block size=8192 status=0x12 head=7 tail=7 dup=1
 tablespace 2, index=3 krfil=3 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:47 scn: 0x0000.000ea4db 05/02/2013 11:44:07
 Stop scn: 0xffff.ffffffff 05/02/2013 12:44:28
 Creation Checkpointed at scn:  0x0000.000b7982 08/13/2009 23:56:54
 thread:0 rba:(0x0.0.0)
 .....
 DATA FILE #4:
  name #6: /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf
creation size=0 block size=8192 status=0x12 head=6 tail=6 dup=1
 tablespace 4, index=4 krfil=4 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:118 scn: 0x0000.000ea4db 05/02/2013 11:44:07
 Stop scn: 0xffff.ffffffff 05/02/2013 12:44:28
 Creation Checkpointed at scn:  0x0000.00004743 08/13/2009 23:01:06
 thread:0 rba:(0x0.0.0)
 ....
 DATA FILE #5:
  name #5: /u01/app/oracle/product/11.2.0/oradata/jingyong/example01.dbf
creation size=0 block size=8192 status=0x12 head=5 tail=5 dup=1
 tablespace 6, index=5 krfil=5 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:43 scn: 0x0000.000ea4db 05/02/2013 11:44:07
 Stop scn: 0xffff.ffffffff 05/02/2013 12:44:28
 Creation Checkpointed at scn:  0x0000.000bf3fe 04/25/2013 14:05:52
 thread:0 rba:(0x0.0.0)
 ....
 DATA FILE #6:
  name #4: /u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbf
creation size=0 block size=8192 status=0x12 head=4 tail=4 dup=1
 tablespace 7, index=6 krfil=6 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:11 scn: 0x0000.000ea96d 05/02/2013 12:00:47
 Stop scn: 0xffff.ffffffff 05/02/2013 12:44:28
 Creation Checkpointed at scn:  0x0000.000e9b4f 05/02/2013 08:43:22
 thread:0 rba:(0x0.0.0)
 .....

从上面的信息可以知道由于数据库是异常关闭的,所以数据文件的Stop scn:为无穷大:
Stop scn: 0xffff.ffffffff,接下来对数据库执行恢复,当恢复完成后再对控制文件进行转储:

SQL> recover database;
Media recovery complete.

SQL> alter session set events 'immediate trace name controlf level 12';

Session altered.

SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_19450.trc

来观察此跟踪文件中的数据文件信息:

***************************************************************************
DATA FILE RECORDS
***************************************************************************
 (size = 520, compat size = 520, section max = 100, section in-use = 6,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 11, numrecs = 100)
DATA FILE #1:
  name #9: /u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbf
creation size=0 block size=8192 status=0x2 head=9 tail=9 dup=1
 tablespace 0, index=1 krfil=1 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:120 scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Stop scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Creation Checkpointed at scn:  0x0000.00000007 08/13/2009 23:00:53
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #2:
  name #8: /u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbf
creation size=0 block size=8192 status=0x2 head=8 tail=8 dup=1
 tablespace 1, index=2 krfil=2 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:120 scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Stop scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Creation Checkpointed at scn:  0x0000.00000874 08/13/2009 23:00:57
 thread:0 rba:(0x0.0.0)
....
DATA FILE #3:
  name #7: /u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbf
creation size=0 block size=8192 status=0x2 head=7 tail=7 dup=1
 tablespace 2, index=3 krfil=3 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:48 scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Stop scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Creation Checkpointed at scn:  0x0000.000b7982 08/13/2009 23:56:54
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #4:
  name #6: /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf
creation size=0 block size=8192 status=0x2 head=6 tail=6 dup=1
 tablespace 4, index=4 krfil=4 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:119 scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Stop scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Creation Checkpointed at scn:  0x0000.00004743 08/13/2009 23:01:06
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #5:
  name #5: /u01/app/oracle/product/11.2.0/oradata/jingyong/example01.dbf
creation size=0 block size=8192 status=0x2 head=5 tail=5 dup=1
 tablespace 6, index=5 krfil=5 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:44 scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Stop scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Creation Checkpointed at scn:  0x0000.000bf3fe 04/25/2013 14:05:52
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #6:
  name #4: /u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbf
creation size=0 block size=8192 status=0x2 head=4 tail=4 dup=1
 tablespace 7, index=6 krfil=6 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:12 scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Stop scn: 0x0000.000efd7d 05/02/2013 12:43:16
 Creation Checkpointed at scn:  0x0000.000e9b4f 05/02/2013 08:43:22
 thread:0 rba:(0x0.0.0)
 ....
 

经过恢复之后,数据文件达到了一致状态,checkpoint scn(0x0000.000efd7d)和Stop scn(0x0000.000efd7d)
达到了一致,此时数据库就完成了恢复,数据库可以顺利启动:

SQL> ALTER SYSTEM ARCHIVE LOG ALL;

System altered.

SQL> ALTER DATABASE OPEN;

Database altered.

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/product/11.2.0/oradata/jingyong/temp01.dbf'
  2       SIZE 30M  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 40M;

Tablespace altered.

现在我们来实验使用resetlogs方式来重建控制文件:
模拟数据库故障

SQL> shutdown abort;
ORACLE instance shut down.

以resetlogs来重建控制文件
SQL> startup nomount
ORACLE instance started.

Total System Global Area  238530560 bytes
Fixed Size                  1335724 bytes
Variable Size             150998612 bytes
Database Buffers           83886080 bytes
Redo Buffers                2310144 bytes
SQL> CREATE CONTROLFILE REUSE DATABASE "JINGYONG" RESETLOGS  ARCHIVELOG
  2      MAXLOGFILES 16
  3      MAXLOGMEMBERS 3
  4      MAXDATAFILES 100
  5      MAXINSTANCES 8
  6      MAXLOGHISTORY 292
  7  LOGFILE
  8    GROUP 1 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo01.log'  SIZE 50M BLOCKSIZE 512,
  9    GROUP 2 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo02.log'  SIZE 50M BLOCKSIZE 512,
 10    GROUP 3 '/u01/app/oracle/product/11.2.0/oradata/jingyong/redo03.log'  SIZE 50M BLOCKSIZE 512
 11  -- STANDBY LOGFILE
 12  DATAFILE
 13    '/u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbf',
 14    '/u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbf',
 15    '/u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbf',
 16    '/u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf',
 17    '/u01/app/oracle/product/11.2.0/oradata/jingyong/example01.dbf',
 18    '/u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbf'
 19  CHARACTER SET ZHS16GBK
 20  ;

Control file created.

此时对控制文件进行一次转储

SQL> alter session set events 'immediate trace name controlf level 12';

Session altered.

SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/jingyong/jingyong/trace/jingyong_ora_19598.trc

观察转储的跟踪文件中的log file record的信息:

***************************************************************************
LOG FILE RECORDS
***************************************************************************
 (size = 72, compat size = 72, section max = 16, section in-use = 3,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 10, numrecs = 16)
LOG FILE #1:
  name #3: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo01.log
 Thread 1 redo log links: forward: 2 backward: 0
 siz: 0x19000 seq: 0x00000000 hws: 0x0 bsz: 512 nab: 0x0 flg: 0x1 dup: 1
 Archive links: fwrd: 0 back: 0 Prev scn: 0x0000.00000000
 Low scn: 0x0000.00000000 01/01/1988 00:00:00
 Next scn: 0x0000.00000000 01/01/1988 00:00:00
LOG FILE #2:
  name #2: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo02.log
 Thread 1 redo log links: forward: 3 backward: 1
 siz: 0x19000 seq: 0x00000000 hws: 0x0 bsz: 512 nab: 0x0 flg: 0x1 dup: 1
 Archive links: fwrd: 0 back: 0 Prev scn: 0x0000.00000000
 Low scn: 0x0000.00000000 01/01/1988 00:00:00
 Next scn: 0x0000.00000000 01/01/1988 00:00:00
LOG FILE #3:
  name #1: /u01/app/oracle/product/11.2.0/oradata/jingyong/redo03.log
 Thread 1 redo log links: forward: 0 backward: 2
 siz: 0x19000 seq: 0x00000000 hws: 0x0 bsz: 512 nab: 0x2 flg: 0xb dup: 1
 Archive links: fwrd: 0 back: 0 Prev scn: 0x0000.00000000
 Low scn: 0x0000.00000000 01/01/1988 00:00:00
 Next scn: 0x0000.00000000 01/01/1988 00:00:00

从上面的信息可以看到此时控制文件中的日志信息都是空的,oracle认为resetlogs方式下,当前的日志文件
已经损坏,那么就意味着oracle可能会丢失提交成功的数据,恢复将是一次不完全的介质恢复.

此时的数据文件信息如下:

***************************************************************************
DATA FILE RECORDS
***************************************************************************
 (size = 520, compat size = 520, section max = 100, section in-use = 6,
  last-recid= 0, old-recno = 0, last-recno = 0)
 (extent = 1, blkno = 11, numrecs = 100)
DATA FILE #1:
  name #9: /u01/app/oracle/product/11.2.0/oradata/jingyong/system01.dbf
creation size=0 block size=8192 status=0x12 head=9 tail=9 dup=1
 tablespace 0, index=1 krfil=1 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:123 scn: 0x0000.000efd80 05/02/2013 12:53:11
 Stop scn: 0xffff.ffffffff 05/02/2013 13:01:12
 Creation Checkpointed at scn:  0x0000.00000007 08/13/2009 23:00:53
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #2:
  name #8: /u01/app/oracle/product/11.2.0/oradata/jingyong/sysaux01.dbf
creation size=0 block size=8192 status=0x12 head=8 tail=8 dup=1
 tablespace 1, index=2 krfil=2 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:123 scn: 0x0000.000efd80 05/02/2013 12:53:11
 Stop scn: 0xffff.ffffffff 05/02/2013 13:01:12
 Creation Checkpointed at scn:  0x0000.00000874 08/13/2009 23:00:57
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #3:
  name #7: /u01/app/oracle/product/11.2.0/oradata/jingyong/undotbs01.dbf
creation size=0 block size=8192 status=0x12 head=7 tail=7 dup=1
 tablespace 2, index=3 krfil=3 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:51 scn: 0x0000.000efd80 05/02/2013 12:53:11
 Stop scn: 0xffff.ffffffff 05/02/2013 13:01:12
 Creation Checkpointed at scn:  0x0000.000b7982 08/13/2009 23:56:54
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #4:
  name #6: /u01/app/oracle/product/11.2.0/oradata/jingyong/users01.dbf
creation size=0 block size=8192 status=0x12 head=6 tail=6 dup=1
 tablespace 4, index=4 krfil=4 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:122 scn: 0x0000.000efd80 05/02/2013 12:53:11
 Stop scn: 0xffff.ffffffff 05/02/2013 13:01:12
 Creation Checkpointed at scn:  0x0000.00004743 08/13/2009 23:01:06
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #5:
  name #5: /u01/app/oracle/product/11.2.0/oradata/jingyong/example01.dbf
creation size=0 block size=8192 status=0x12 head=5 tail=5 dup=1
 tablespace 6, index=5 krfil=5 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:47 scn: 0x0000.000efd80 05/02/2013 12:53:11
 Stop scn: 0xffff.ffffffff 05/02/2013 13:01:12
 Creation Checkpointed at scn:  0x0000.000bf3fe 04/25/2013 14:05:52
 thread:0 rba:(0x0.0.0)
 ....
DATA FILE #6:
  name #4: /u01/app/oracle/product/11.2.0/oradata/jingyong/jy01.dbf
creation size=0 block size=8192 status=0x12 head=4 tail=4 dup=1
 tablespace 7, index=6 krfil=6 prev_file=0
 unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
 Checkpoint cnt:15 scn: 0x0000.000efd80 05/02/2013 12:53:11
 Stop scn: 0xffff.ffffffff 05/02/2013 13:01:12
 Creation Checkpointed at scn:  0x0000.000e9b4f 05/02/2013 08:43:22
 thread:0 rba:(0x0.0.0)
 ....
 

从上面的信息可以知道由于数据库是异常关闭的,所以数据文件的Stop scn:为无穷大:
Stop scn: 0xffff.ffffffff

不完全恢复最终要求数据库通过resetlogs方式打开,resetlogs将会强制清空或重建联机重做日志文件.
此时执行恢复必须使用backup controlfile选项,否则将会报错:

SQL> recover database;
ORA-00283: recovery session canceled due to errors
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done

SQL> recover database using backup controlfile;
ORA-00279: change 982400 generated at 05/02/2013 12:53:11 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0/flash_recovery_area/JINGYONG/archivelog/2013_05_0
2/o1_mf_1_18_%u_.arc
ORA-00280: change 982400 for thread 1 is in sequence #18


Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.

如果在线日志操坏,那么恢复到最后,oracle提示的最后一个归档日志将是不存在的(如果在线日志没有
损坏,则可以指定在线日志文件执行恢复),此时可以输入cancel取消恢复,然后可以强制打开数据库:

alter database open resetlogs;

SQL> recover database using backup controlfile;
ORA-00279: change 1003572 generated at 05/02/2013 13:20:06 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/product/11.2.0/flash_recovery_area/JINGYONG/archivelog/2013_05_0
2/o1_mf_1_19_%u_.arc
ORA-00280: change 1003572 for thread 1 is in sequence #19


Specify log: {=suggested | filename | AUTO | CANCEL}
/u01/app/oracle/product/11.2.0/oradata/jingyong/redo01.log
Log applied.
Media recovery complete.
SQL> alter database open resetlogs;

Database altered.

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/product/11.2.0/oradata/jingyong/temp01.dbf'
  2       SIZE 30M  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 40M;

Tablespace altered.

oracle并行进程的ORA-27090故障的解决

RAC数据库出现ORA-27090错误

/u01/app/oracle/admin/yyjm/bdump/yyjm2_p000_6379.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1
System name:Linux
Node name:node6
Release:2.6.18-92.el5
Version:#1 SMP Tue Apr 29 13:16:15 EDT 2008
Machine:x86_64
Instance name: yyjm2
Redo thread mounted by this instance: 2
Oracle process number: 42
Unix process pid: 6379, image: oracle@node6 (P000)

*** SERVICE NAME:(SYS$BACKGROUND) 2013-05-04 07:19:48.850
*** SESSION ID:(716.11196) 2013-05-04 07:19:48.850
*** 2013-05-04 07:19:48.850
Start recovery for domain 0, valid = 0, flags = 0x1
*** 2013-05-04 07:19:49.082
KCRP: blocks claimed = 10, eliminated = 0
----- Recovery Hash Table Statistics ---------
Hash table buckets = 4194304
Longest hash chain = 1
Average hash chain = 10/10 = 1.0
Max compares per lookup = 0
Avg compares per lookup = 0/10 = 0.0
----------------------------------------------
ORA-27090: Message 27090 not found;  product=RDBMS; facility=ORA
Linux-x86_64 Error: 4: Interrupted system call
Additional information: 3
Additional information: 128
Additional information: 65536
----- Recovery Hash Table Statistics ---------
Hash table buckets = 4194304
Longest hash chain = 1
Average hash chain = 10/10 = 1.0
Max compares per lookup = 1
Avg compares per lookup = 33/33 = 1.0
----------------------------------------------

该问题是发生在RAC一个节点崩溃后,所有的错误都发生在并行进程PNNN上。MOS上说这个问题是由于系统参数配置不当所致:ORA-27090: MESSAGE 27090 NOT FOUND; [ID 579108.1]。

内核参数的值:aio-max-nr设置太低,推荐设置为fs.aio-max-nr= 3145728。修改参数使用/sbin/sysctl -p重新加载参数后,重启数据库即可。
下面是OTN上对该问题的讨论
https://forums.oracle.com/forums/thread.jspa?threadID=859368