Skip to content

Oracle - 9. page

本文介绍数据库实例关闭和启动过程的差异。承接上面《如何快速关闭数据库》,主要面向新接触oracle的dba

 

一: 启动数据库的几个阶段介绍

 

启动 Oracle 数据库有三个阶段:

· Start the instance
· Mount the database
· Open the database

可以通过在启动时发出不同的选项来控制哪个阶段命令。

STARTUP NOMOUNT

这只会启动 Oracle 实例。 甲骨文读取初始化参数文件 (pfile Or spfile) 用于确定控制文件所在的位置,在内存中创建系统全局区域 (SGA) 的大小以及背景
要创建的进程。 当实例启动时,将收到通知和SGA内存结构和大小的列表:

ORACLE instance started.
Total System Global Area 56011696 bytes
Fixed Size 52144 bytes
Variable Size 51785728 bytes
Database Buffers 4096000 bytes
Redo Buffers 77824 bytes

STARTUP MOUNT

此命令启动实例并装入数据库而不打开它。
Oracle 读取控制文件以获取有关数据文件和重做日志的信息,但不打开文件。 这是执行维护时必需的步骤,比如重命名数据文件、更改重做日志或启用等操作归档。
除了看到SGA列表外,还将看到“数据库”

STARTUP

此命令启动实例,然后挂载并打开数据库。 这数据库打开在线数据文件和在线重做日志,通常会获取
一个或多个回滚段。 当数据库打开时,将看到“数据库打开”已准备好进行正常的数据库操作。

如果使用“启动无挂载”或“启动挂载”,则必须使用 ALTERDATABASE 命令以继续打开数据库。
例如,从NOMOUNT 位置(即实例已启动,但数据库未加载或者打开),
需要使用两个命令:

ALTER DATABASE MOUNT;
ALTER DATABASE OPEN;

STARTUP RESTRICT

受限模式打开数据库,但仅打开特权用户(具有 DBA 的用户)授予的角色)可以使用数据库。

STARTUP FORCE

此命令执行关机中止和启动的组合。 在关闭或启动数据库时遇到问题时才会有到此命令。

 

二:关闭数据库的接个阶段介绍

 

 

SHUTDOWN NORMAL

这是关闭命令的默认选项;因此,可以发出关闭,数据库将正常关闭。

发出语句后不允许新连接。 在数据库已关闭,Oracle 等待所有当前连接的用户
断开与数据库的连接。 数据库的下一次启动不会需要任何实例恢复。

SHUTDOWN IMMEDIATE

当您想要快速关闭但仍允许数据库干净地关闭。

Oracle 正在处理的当前 SQL 语句将立即终止。任何未提交的事务都将回滚。 (如果长期未承诺
事务存在,关闭可能不会很快完成。 甲骨文确实如此不等待用户断开连接;它隐式回滚活动事务
并断开所有连接的用户的连接。

SHUTDOWN TRANSACTIONAL

此选项仅在版本 8.1.X 中可用。 在需要时使用此选项以执行计划内关闭,同时允许活动事务完成。
任何新的连接或交易都将被拒绝。 毕竟是活跃的事务完成,数据库将关闭,就好像立即选项
被使用了。

SHUTDOWN ABORT

此选项只能作为最后的手段使用。 在以下情况下使用:

· 数据库运行不正常,您无法关闭正常或立即关闭。
· 需要立即关闭数据库。
· 启动数据库实例时遇到问题。

所有当前正在处理的客户机 SQL 语句将立即终止。任何未提交的事务都不会回滚。 数据库不会等待
对于当前连接到数据库的用户断开连接,断开所有连接的用户。

数据库实例的下一次启动将需要实例恢复;因此下一次启动可能需要比平时更长的时间

数据库启动和关闭过程的差异对比

 

Oracle 的一般兼容政策是测试和支持每一个新的 Oracle 发行版与旧的发行版之间的兼容性,即

  • 如果新的版本发布时,旧的发行版仍然处于 Premier Support 阶段(之前称为 Primary Error Correction support)或者Market-Driven Support阶段,那么测试新的客户端和每一个旧的发行版的组合。
  • 如果旧的版本仍然在 Premier Support 阶段(之前称为 Primary Error Correction support),或者Market-Driven Support阶段, 或者在 Extended Support(之前称为 Extended Maintenance support)的前两年,那么测试旧的客户端和新的服务器版本的组合。
  • 如果 Oracle 认为支持其操作性有意义的话,那么会增加在新的版本和其它旧的发行版之间进行测试。

 

下面的矩阵总结了受支持的最经常使用的产品版本的客户端和服务器的组合。完整的矩阵在这篇文档的末尾。

仅当满足如下条件时,才会对新的交互性问题进行调查:当问题发生时,所涉及的两个发行版都处于一个有效的支持合同当中。

 

 

 

 

 

 

 

 

 

 

 

 

 

特别说明:

  • #1 – 只适用于11.2.0.3 和 11.2.0.4。对于Oracle Autonomous Transaction Processing 和 Oracle Autonomous Data Warehouse, 这里有额外的限制:11.2.0.4 是支持客户端的最低版本。

• 一般说明:

  1. 1. 对于不同版本之间的 database links 连接,必须受到上表中的双向支持。
    例如: 由于 11.2 -> 10.1 不被支持,那么这两个版本之间的双向的 database link 就都不被支持。
  2. 不受支持的组合可能似乎可以工作,但是对于特定的操作可能遇到错误。不应该依赖于他们似乎可以工作 – Oracle 不会对不受支持的组合遇到的问题进行调查。
  3. 由于新的数据库服务器兼容于有限的一组旧 OCI 客户端,升级数据库时,升级这些客户端软件可能不是必须的。但是,如果不升级客户端软件,一些新的特性可能无法运行。例如,10.2 的 Oracle 客户端可以连接到 11.2 数据库,但是无法利用客户端结果缓存(11.1 中引入)之类的新特性。
  4. Oracle Applications,或其它的 Oracle 产品,可能有上表中未列出的受支持的配置。
  5. 上表同样适用于不同的平台之间,以及 32/64位 Oracle 客户端/服务器之间,除非某个 Oracle 平台另有不支持公告说明。
  6. Unix BEQUEATH (BEQ)在不同发行版之间 不受支持 例如, 10.2 客户端到 11.2 服务器的 Oracle 连接,不管上表中列出的互操作性支持如何,若是使用 BEQ 协议适配器,则是不受支持的。参阅 Note 364252.1 了解更多细节。
  7. 本文提到的”Oracle Client” 并不适用于其它客户端产品,比如”Sql-plus Instant Client”
  8. Oracle Cloud Service上和客户端的互操作性取决于作为云的一部分运行的DB Server的版本
  9. 根据所使用的云服务,可能会有一些功能限制,请您参考云服务文档以了解任何此类功能限制。

 

完整的从oracle 7到oracle23c的版本兼容情况矩阵图参考如下:

 

Oracle 23c对前面版本的客户端兼容支持

1.CurrentActivity.sql

 

set lines 150
set pages 999
clear col

set termout off
set trimout on
set trimspool on

REM
REM Current transactions
REM
REM Will show only last transaction by a user
REM
REM May need to use 786472.1 for better picture
REM of activity

connect / as sysdba
alter session set nls_date_format=’dd-Mon-yyyy hh24:mi’;

col username format a10 wrapped heading “User”
col name format a22 wrapped heading “Undo Segment Name”
col xidusn heading “Undo|Seg #”
col xidslot heading “Undo|Slot #”
col xidsqn heading “Undo|Seq #”
col ubafil heading “File #”
col ubablk heading “Block #”
col start_time format a10 word_wrapped heading “Started”
col status format a8 heading “Status”
col blk format 999,999,999 heading “KBytes”
col used_urec heading “Rows”

spool undoactivity.out

prompt
prompt ############## RUNTIME ##############
prompt

col rdate head “Run Time”

select sysdate rdate from dual;

prompt
prompt ############## Current Uncommitted Transactions ##############
prompt

select start_time, username, r.name,
ubafil, ubablk, t.status, (used_ublk*p.value)/1024 blk, used_urec
from v$transaction t, v$rollname r, v$session s, v$parameter p
where xidusn=usn
and s.saddr=t.ses_addr
and p.name=’db_block_size’
order by 1;
spool off

set termout on
set trimout off
set trimspool off
clear col

 

2.LobData.sql

 

REM List table and column information for LOBs for a specific user
REM
REM UNDO handling with LOBs is not designed for frequent updates
REM Frequent updates are best handled with PCTVERSION at 100
REM This means you must have a lot of space available in the LOB
REM tablespace as all UNDO will be maintained over time.
REM
REM Using RETENTION does not work as expected
REM It is set to UNDO_RETENTION at the time of the creation of the
REM object. It does not change over time as UNDO_RETENTION
REM or auto-tuned undo retention changes.

set pages 999
set lines 110

spool lobdata.out

col column_name format a25 head “Column”
col table_name format a25 head “Table”
col tablespace_name format a25 head “Tablespace”
col pctversion format 999 head “PCTVersion %”
col segment_space_management format a30 head “Space|Mngmnt”
col retention format 999,999,999 head “Retention”

select l.table_name, l.column_name, l.tablespace_name, l.pctversion, l.retention,
t.segment_space_management
from dba_lobs l, dba_tablespaces t
where owner=upper(‘&USER’)
and l.tablespace_name = t.tablespace_name
/

spool off

 

3. undoconfig.sql

spool UndoConfig.out

ttitle off
set pages 999
set lines 150
set verify off

set termout off
set trimout on
set trimspool on

REM
REM ————————————————————————

REM
REM —————————————————————–
REM

set space 2

REM REPORTING TABLESPACE INFORMATION:
REM
REM This looks at Tablespace Sizing – Total bytes and free bytes
REM

column tablespace_name format a30 heading ‘TS Name’
column sbytes format 9,999,999,999 heading ‘Total MBytes’
column fbytes format 9,999,999,999 heading ‘Free MBytes’
column file_name format a30 heading ‘File Name’
column kount format 999 heading ‘Ext’

compute sum of fbytes on tablespace_name
compute sum of sbytes on tablespace_name
compute sum of sbytes on report
compute sum of fbytes on report

break on tablespace_name skip 2

select a.tablespace_name, a.file_name, round(a.bytes/1024/1024,0) sbytes,
round(sum(b.bytes/1024/1024),0) fbytes, count(*) kount, autoextensible
from dba_data_files a, dba_free_space b
where a.file_id = b.file_id
and a.tablespace_name in (select z.tablespace_name from dba_tablespaces z where retention like ‘%GUARANTEE’)
group by a.tablespace_name, a.file_name, a.bytes, autoextensible
order by a.tablespace_name
/

set linesize 160

REM
REM If you can significantly reduce physical reads by adding incremental
REM data buffers…do it. To determine whether adding data buffers will
REM help, set db_block_lru_statistics = TRUE and
REM db_block_lru_extended_statistics = TRUE in the init.ora parameters.
REM You can determine how many extra hits you would get from memory as
REM opposed to physical I/O from disk. **NOTE: Turning these on will
REM impact performance. One shift of statistics gathering should be enough
REM to get the required information.
REM

REM
REM —————————————————————–
REM

set lines 160

col tablespace_name format a30 heading “Tablespace”
col tb format a15 heading “TB Status”
col df format a10 heading “DF Status”
col extent_management format a15 heading “Extent|Management”
col allocation_type format a8 heading “Type”
col segment_space_management format a7 heading “Auto|Segment”
col retention format a11 heading “Retention|Level”
col autoextensible format a5 heading “Auto?”
col mx format 999,999,999 heading “Max Allowed”

select t.tablespace_name, t.status tb, d.status df,
extent_management, allocation_type, segment_space_management, retention,
autoextensible, (maxbytes/1024/1024) mx
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
and retention like ‘%GUARANTEE’
/

col status format a20 head “Status”
col cnt format 999,999,999 head “How Many?”

select status, count(*) cnt
from dba_rollback_segs
group by status
/

spool off

set termout on
set trimout off
set trimspool off

4.undodatafiles.sql

set lines 120
set pages 999
clear col

set termout off
set trimout on
set trimspool on

connect / as sysdba
alter session set nls_date_format=’dd-Mon-yyyy hh24:mi’;

spool undodatafiles.out

prompt
prompt ############## RUNTIME ##############
prompt

col rdate head “Run Time”

select sysdate rdate from dual;

prompt
prompt ############## DATAFILES ##############
prompt

col retention head “Retention”
col tablespace_name format a30 head “TBSP Name”
col file_id format 999 head “File #”
col a format 999,999,999,999,999 head “Bytes Alloc (MB)”
col b format 999,999,999,999,999 head “Max Bytes Used (MB)”
col autoextensible head “Auto|Ext”
col extent_management head “Ext Mngmnt”
col allocation_type head “Type”
col segment_space_management head “SSM”

select tablespace_name, file_id, sum(bytes)/1024/1024 a,
sum(maxbytes)/1024/1024 b,
autoextensible
from dba_data_files
where tablespace_name in (select tablespace_name from dba_tablespaces
where retention like ‘%GUARANTEE’ )
group by file_id, tablespace_name, autoextensible
order by tablespace_name
/

spool off
set termout on
set trimout off
set trimspool off
clear col

5.undoextends.sql

spool UndoExts.out

ttitle off
set pages 999
set lines 150
set verify off

set termout off
set trimout on
set trimspool on

REM
REM ————————————————————————

REM
REM —————————————————————–
REM

REM
REM REPORTING UNDO EXTENTS INFORMATION:
REM
REM —————————————————————–
REM
REM Undo Extents breakdown information
REM

ttitle center “Rollback Segments Breakdown” skip 2

col status format a20
col cnt format 999,999,999 head “How Many?”

select status, count(*) cnt from dba_rollback_segs
group by status
/

ttitle center “Undo Extents” skip 2

col segment_name format a30 heading “Name”
col “ACT BYTES” format 999,999,999,999 head “Active|Extents”
col “UNEXP BYTES” format 999,999,999,999 head “Unxpired|Extents”
col “EXP BYTES” format 999,999,999,999 head “Expired|Extents”

select segment_name,
nvl(sum(act),0) “ACT BYTES”,
nvl(sum(unexp),0) “UNEXP BYTES”,
nvl(sum(exp),0) “EXP BYTES”
from (
select segment_name,
nvl(sum(bytes),0) act,00 unexp, 00 exp
from DBA_UNDO_EXTENTS
where status=’ACTIVE’ group by segment_name
union
select segment_name,
00 act, nvl(sum(bytes),0) unexp, 00 exp
from DBA_UNDO_EXTENTS
where status=’UNEXPIRED’ group by segment_name
union
select segment_name,
00 act, 00 unexp, nvl(sum(bytes),0) exp
from DBA_UNDO_EXTENTS
where status=’EXPIRED’ group by segment_name
) group by segment_name;

ttitle center “Undo Extents Statistics” skip 2

col size format 999,999,999,999 heading “Size”
col “HOW MANY” format 999,999,999 heading “How Many?”
col st heading a12 heading “Status”

select distinct status st, count(*) “HOW MANY”, sum(bytes) “SIZE”
from dba_undo_extents
group by status
/

col segment_name format a30 heading “Name”
col TABLESPACE_NAME for a20
col BYTES for 999,999,999,999
col BLOCKS for 999,999,999
col status for a15 heading “Status”
col segment_name heading “Segment”
col extent_id heading “ID”

select SEGMENT_NAME, TABLESPACE_NAME, EXTENT_ID,
FILE_ID, BLOCK_ID, BYTES, BLOCKS, STATUS
from dba_undo_extents
order by 1,3,4,5
/

REM
REM —————————————————————–
REM
REM Undo Extents Contention breakdown
REM Take out column TUNED_UNDORETENTION if customer
REM prior to 10.2.x
REM
REM The time frame can be adjusted with this query
REM By default using around 4 hour window of time
REM
REM Ex.
REM Using sysdate-.04 looking at the last hour
REM Using sysdate-.16 looking at the last 4 hours
REM Using sysdate-.32 looking at the last 8 hours
REM Using sysdate-1 looking at the last 24 hours
REM

set linesize 140

ttitle center “Undo Extents Error Conditions (Default – Last 4 Hours)” skip 2

col UNXPSTEALCNT format 999,999,999 heading “# Unexpired|Stolen”
col EXPSTEALCNT format 999,999,999 heading “# Expired|Reused”
col SSOLDERRCNT format 999,999,999 heading “ORA-1555|Error”
col NOSPACEERRCNT format 999,999,999 heading “Out-Of-space|Error”
col MAXQUERYLEN format 999,999,999 heading “Max Query|Length”
col TUNED_UNDORETENTION format 999,999,999 heading “Auto-Ajusted|Undo Retention”
col hours format 999,999 heading “Tuned|(HRs)”

select inst_id, to_char(begin_time,’MM/DD/YYYY HH24:MI’) begin_time,
UNXPSTEALCNT, EXPSTEALCNT , SSOLDERRCNT, NOSPACEERRCNT, MAXQUERYLEN,
TUNED_UNDORETENTION, TUNED_UNDORETENTION/60/60 hours
from gv$undostat
where begin_time between (sysdate-.16)
and sysdate
order by inst_id, begin_time
/

spool off
set termout on
set trimout off
set trimspool off

6.undoheathcheck.sql

spool Undohealth.out

ttitle off
set pages 999
set lines 150
set verify off
set termout off
set trimout on
set trimspool on

REM
REM ————————————————————————

col name format a30
col gets format 9,999,999
col waits format 9,999,999

PROMPT ROLLBACK HIT STATISTICS:
REM

REM GETS – # of gets on the rollback segment header
REM WAITS – # of waits for the rollback segment header

set head on;

select name, waits, gets
from v$rollstat, v$rollname
where v$rollstat.usn = v$rollname.usn
/

col pct head “< 2% ideal” select ‘The average of waits/gets is ‘|| round((sum(waits) / sum(gets)) * 100,2)||’%’ PCT From v$rollstat / PROMPT REDO CONTENTION STATISTICS: REM REM If the ratio of waits to gets is more than 1% or 2%, consider REM creating more rollback segments REM REM Another way to gauge rollback contention is: REM column xn1 format 9999999 column xv1 new_value xxv1 noprint select class, count from v$waitstat where class in (‘system undo header’, ‘system undo block’, ‘undo header’, ‘undo block’ ) / set head off select ‘Total requests = ‘||sum(count) xn1, sum(count) xv1 from v$waitstat / select ‘Contention for system undo header = ‘|| (round(count/(&xxv1+0.00000000001),4)) * 100||’%’ from v$waitstat where class = ‘system undo header’ / select ‘Contention for system undo block = ‘|| (round(count/(&xxv1+0.00000000001),4)) * 100||’%’ from v$waitstat where class = ‘system undo block’ / select ‘Contention for undo header = ‘|| (round(count/(&xxv1+0.00000000001),4)) * 100||’%’ from v$waitstat where class = ‘undo header’ / select ‘Contention for undo block = ‘|| (round(count/(&xxv1+0.00000000001),4)) * 100||’%’ from v$waitstat where class = ‘undo block’ / REM REM NOTE: Not as useful with AUM configured REM REM If the percentage for an area is more than 1% or 2%, consider REM creating more rollback segments. Note: This value is usually very REM small REM and has been rounded to 4 places. REM REM ———————————————————————— REM REM The following shows how often user processes had to wait for space in REM the redo log buffer: select name||’ = ‘||value from v$sysstat where name = ‘redo log space requests’ / REM REM This value should be near 0. If this value increments consistently, REM processes have had to wait for space in the redo buffer. If this REM condition exists over time, increase the size of LOG_BUFFER in the REM init.ora file in increments of 5% until the value nears 0. REM ** NOTE: increasing the LOG_BUFFER value will increase total SGA size. REM REM ———————————————————————– col name format a15 col gets format 9999999 col misses format 9999999 col immediate_gets heading ‘IMMED GETS’ format 9999999 col immediate_misses heading ‘IMMED MISS’ format 9999999 col sleeps format 999999 PROMPT LATCH CONTENTION: REM REM GETS – # of successful willing-to-wait requests for a latch REM MISSES – # of times an initial willing-to-wait request was unsuccessful REM IMMEDIATE_GETS – # of successful immediate requests for each latch REM IMMEDIATE_MISSES = # of unsuccessful immediate requests for each latch REM SLEEPS – # of times a process waited and requests a latch after an REM initial willing-to-wait request REM REM If the latch requested with a willing-to-wait request is not REM available, the requesting process waits a short time and requests REM again. REM If the latch requested with an immediate request is not available, REM the requesting process does not wait, but continues processing REM set head on select name, gets, misses, immediate_gets, immediate_misses, sleeps from v$latch where name in (‘redo allocation’, ‘redo copy’) / set head off select ‘Ratio of MISSES to GETS: ‘|| round((sum(misses)/(sum(gets)+0.00000000001) * 100),2)||’%’ from v$latch where name in (‘redo allocation’, ‘redo copy’) / select ‘Ratio of IMMEDIATE_MISSES to IMMEDIATE_GETS: ‘|| round((sum(immediate_misses)/ (sum(immediate_misses+immediate_gets)+0.00000000001) * 100),2)||’%’ from v$latch where name in (‘redo allocation’, ‘redo copy’) / set head on REM REM If either ratio exceeds 1%, performance will be affected. REM REM Decreasing the size of LOG_SMALL_ENTRY_MAX_SIZE reduces the number of REM processes copying information on the redo allocation latch. REM REM Increasing the size of LOG_SIMULTANEOUS_COPIES will reduce contention REM for redo copy latches. REM REM —————————————————————– REM This looks at overall i/o activity against individual REM files within a tablespace REM REM Look for a mismatch across disk drives in terms of I/O REM REM Also, examine the Blocks per Read Ratio for heavily accessed REM TSs – if this value is significantly above 1 then you may have REM full tablescans occurring (with multi-block I/O) REM REM If activity on the files is unbalanced, move files around to balance REM the load. Should see an approximately even set of numbers across files REM set space 1 PROMPT REPORTING I/O STATISTICS: column pbr format 99999999 heading ‘Physical|Blk Read’ column pbw format 999999 heading ‘Physical|Blks Wrtn’ column pyr format 999999 heading ‘Physical|Reads’ column readtim format 99999999 heading ‘Read|Time’ column name format a55 heading ‘DataFile Name’ column writetim format 99999999 heading ‘Write|Time’ compute sum of f.phyblkrd, f.phyblkwrt on report select fs.name name, f.phyblkrd pbr, f.phyblkwrt pbw, f.readtim, f.writetim from v$filestat f, v$datafile fs where f.file# = fs.file# order by fs.name / REM REM —————————————————————– PROMPT GENERATING WAIT STATISTICS: REM REM This will show wait stats for certain kernel instances. This REM may show the need for additional rbs, wait lists, db_buffers REM column class heading ‘Class Type’ column count heading ‘Times Waited’ format 99,999,999 column time heading ‘Total Times’ format 99,999,999 select class, count, time from v$waitstat where count > 0
order by class
/

REM
REM Look at the wait statistics generated above (if any). They will
REM tell you where there is contention in the system. There will
REM usually be some contention in any system – but if the ratio of
REM waits for a particular operation starts to rise, you may need to
REM add additional resource, such as more database buffers, log buffers,
REM or rollback segments
REM
REM —————————————————————–

PROMPT ROLLBACK EXTENT STATISTICS:
REM

column usn format 999 heading ‘Undo #’
column extents format 999 heading ‘Extents’
column rssize format 999,999,999 heading ‘Size in|Bytes’
column optsize format 999,999,999 heading ‘Optimal|Size’
column hwmsize format 99,999,999 heading ‘High Water|Mark’
column shrinks format 9,999 heading ‘Num of|Shrinks’
column wraps format 9,999 heading ‘Num of|Wraps’
column extends format 999,999 heading ‘Num of|Extends’
column aveactive format 999,999,999 heading ‘Average size|Active Extents’
column rownum noprint

select usn, extents, rssize, optsize, hwmsize,
shrinks, wraps, extends, aveactive
from v$rollstat
order by rownum
/

spool off
set termout on
set trimout off
set trimspool off

 

7.undohistoryinfo.sql

 

set lines 120
set pages 999
clear col

set termout off
set trimout on
set trimspool on

connect / as sysdba
alter session set nls_date_format=’dd-hh24:mi’;

spool undohistoryinfo.out

prompt
prompt ############## RUNTIME ##############
prompt

col rdate head “Run Time”

select sysdate rdate from dual;

prompt
prompt ############## HISTORICAL DATA ##############
prompt

col x format 999,999 head “Max Concurrent|Last 7 Days”
col y format 999,999 head “Max Concurrent|Since Startup”

select max(maxconcurrency) x from v$undostat
/
select max(maxconcurrency) y from sys.wrh$_undostat
/

col i format 999,999 head “1555 Errors”
col j format 999,999 head “Undo Space Errors”

select sum(ssolderrcnt) i from v$undostat
where end_time > sysdate-2
/

select sum(nospaceerrcnt) j from v$undostat
where end_time > sysdate-2
/
clear break
clear compute

prompt
prompt ############## CURRENT STATUS OF SEGMENTS ##############
prompt ############## SNAPSHOT IN TIME INFO ##############
prompt ##############(SHOWS CURRENT UNDO ACTIVITY)##############
prompt

col segment_name format a30 head “Segment Name”
col “ACT BYTES” format 999,999,999,999 head “Active Bytes”
col “UNEXP BYTES” format 999,999,999,999 head “Unexpired Bytes”
col “EXP BYTES” format 999,999,999,999 head “Expired Bytes”

select segment_name, nvl(sum(act),0) “ACT BYTES”,
nvl(sum(unexp),0) “UNEXP BYTES”,
nvl(sum(exp),0) “EXP BYTES”
from (select segment_name, nvl(sum(bytes),0) act,00 unexp, 00 exp
from dba_undo_extents where status=’ACTIVE’ group by segment_name
union
select segment_name, 00 act, nvl(sum(bytes),0) unexp, 00 exp
from dba_undo_extents where status=’UNEXPIRED’ group by segment_name
union
select segment_name, 00 act, 00 unexp, nvl(sum(bytes),0) exp
from dba_undo_extents where status=’EXPIRED’ group by segment_name)
group by segment_name
order by 1
/

prompt
prompt ############## UNDO SPACE USAGE ##############
prompt

col usn format 999,999 head “Segment#”
col shrinks format 999,999,999 head “Shrinks”
col aveshrink format 999,999,999 head “Avg Shrink Size”

select usn, shrinks, aveshrink from v$rollstat
/
spool off
set termout on
set trimout off
set trimspool off
clear col

8.undoparameters.sql

 

set lines 120
set pages 999
clear col

set termout off
set trimout on
set trimspool on

connect / as sysdba
alter session set nls_date_format=’dd-Mon-yyyy hh24:mi’;

spool undoparameters.out

prompt
prompt ############## RUNTIME ##############
prompt

col rdate head “Run Time”

select sysdate rdate from dual;

col inst_id format 999 head “Instance #”
col Parameter format a35 wrap
col “Session Value” format a25 wrapped
col “Instance Value” format a25 wrapped

prompt
prompt ############## PARAMETERS ##############
prompt

select a.inst_id, a.ksppinm “Parameter”,
b.ksppstvl “Session Value”,
c.ksppstvl “Instance Value”
from x$ksppi a, x$ksppcv b, x$ksppsv c
where a.indx = b.indx and a.indx = c.indx
and a.inst_id=b.inst_id and b.inst_id=c.inst_id
and a.ksppinm in (‘_undo_autotune’, ‘_smu_debug_mode’,
‘_highthreshold_undoretention’,
‘undo_tablespace’,’undo_retention’,’undo_management’)
order by 2;

spool off
set termout on
set trimout off
set trimspool off
clear col

 

9. undopressure.sql

 

set lines 120
set pages 999
clear col

set termout off
set trimout on
set trimspool on

connect / as sysdba
alter session set nls_date_format=’dd-hh24:mi’;

spool undopressure.out

prompt
prompt ############## RUNTIME ##############
prompt

col rdate head “Run Time”

select sysdate rdate from dual;

prompt
prompt ############## WAITS FOR UNDO (Since Startup) ##############
prompt

col inst_id head “Instance#”
col eq_type format a3 head “Enq”
col total_req# format 999,999,999,999,999,999 head “Total Requests”
col total_wait# format 999,999 head “Total Waits”
col succ_req# format 999,999,999,999,999,999 head “Successes”
col failed_req# format 999,999,999999 head “Failures”
col cum_wait_time format 999,999,999 head “Cummalitve|Time”

select * from v$enqueue_stat where eq_type=’US’
union
select * from v$enqueue_stat where eq_type=’HW’
/

prompt
prompt ############## LOCKS FOR UNDO ##############
prompt

col addr head “ADDR”
col KADDR head “KADDR”
col sid head “Session”
col osuser format a10 head “OS User”
col machine format a15 head “Machine”
col program format a17 head “Program”
col process format a7 head “Process”
col lmode head “Lmode”
col request head “Request”
col ctime format 9,999 head “Time|(Mins)”
col block head “Blocking?”

select /*+ RULE */ a.SID, b.process,
b.OSUSER, b.MACHINE, b.PROGRAM,
addr, kaddr, lmode, request, round(ctime/60/60,0) ctime, block
from
v$lock a,
v$session b
where
a.sid=b.sid
and a.type=’US’
/

prompt
prompt ############## TUNED RETENTION HISTORY (Last 2 Days) ##############
prompt ############## LOWEST AND HIGHEST DATA ##############
prompt

col low format 999,999,999,999 head “Undo Retention|Lowest Tuned Value”
col high format 999,999,999,999 head “Undo Retention|Highest Tuned Value”

select end_time, tuned_undoretention from v$undostat where tuned_undoretention = (
select min(tuned_undoretention) low
from v$undostat
where end_time > sysdate-2)
/

select end_time, tuned_undoretention from v$undostat where tuned_undoretention = (
select max(tuned_undoretention) high
from v$undostat
where end_time > sysdate-2)
/

prompt
prompt ############## CURRENT TRANSACTIONS ##############
prompt

col sql_text format a40 word_wrapped head “SQL Code”

select a.start_date, a.start_scn, a.status, c.sql_text
from v$transaction a, v$session b, v$sqlarea c
where b.saddr=a.ses_addr and c.address=b.sql_address
and b.sql_hash_value=c.hash_value
/

select current_scn from v$database
/

col a format 999,999 head “UnexStolen”
col b format 999,999 head “ExStolen”
col c format 999,999 head “UnexReuse”
col d format 999,999 head “ExReuse”

prompt
prompt ############## WHO’S STEALING WHAT? (Last 2 Days) ##############
prompt

select unxpstealcnt a, expstealcnt b,
unxpblkreucnt c, expblkreucnt d
from v$undostat
where (unxpstealcnt > 0 or expstealcnt > 0)
and end_time > sysdate-2
/

spool off
set termout on
set trimout off
set trimspool off
clear col

 

10. undostatistics.sql

 

set lines 120
set pages 999
clear col

set termout off
set trimout on
set trimspool on

connect / as sysdba
alter session set nls_date_format=’dd-hh24:mi’;

spool undostatistics.out

prompt
prompt ############## RUNTIME ##############
prompt

col rdate head “Run Time”

select sysdate rdate from dual;

col current_scn head “SCN Now”
col start_date head “Trans Started”
col start_scn head “SCN for Trans”
col ses_addr head “ADDR”

prompt
prompt ############## Historical V$UNDOSTAT (Last 2 Days) ##############
prompt

col end_time format a18 Head “Date/Time”
col maxq format 999,999 head “Query|Maximum|Minutes”
col maxquerysqlid head “SqlID”
col undotsn format 999,999 head “TBS”
col undoblks format 999,999,999 head “Undo|Blocks”
col txncount format 999,999,999 head “# of|Trans”
col unexpiredblks format 999,999,999 head “# of Unexpired”
col expiredblks format 999,999,999 head “# of Expired”
col tuned format 999,999 head “Tuned Retention|(Minutes)”

select end_time, round(maxquerylen/60,0) maxq, maxquerysqlid,
undotsn, undoblks, txncount, unexpiredblks, expiredblks,
round(tuned_undoretention/60,0) Tuned
from dba_hist_undostat
where end_time > sysdate-2
order by 1
/

prompt
prompt ############## RECENT MISSES FOR UNDO (Last 2 Days) ##############
prompt

clear col
set lines 500
select * from v$undostat where maxquerylen > tuned_undoretention
and end_time > sysdate-2
order by 2
/

select * from sys.wrh$_undostat where maxquerylen > tuned_undoretention
and end_time > sysdate-2
order by 2
/

prompt
prompt ############## AUTO-TUNING TUNE-DOWN DATA ##############
prompt ############## ROLLBACK DATA (Since Startup) ##############
prompt

col name format a60 head “Name”
col value format 999,999,999 head “Counters”

select name, value from v$sysstat
where name like ‘%down retention%’ or name like ‘une down%’
or name like ‘%undo segment%’ or name like ‘%rollback%’
or name like ‘%undo record%’
/

prompt
prompt ############## Long Running Query History ##############
prompt

col end_time head “Date”
col maxquerysqlid head “SQL ID”
col runawayquerysqlid format a15 head “Runaway SQL ID”
col results format a35 word_wrapped head “Space Issues”
col status head “Status”
col newret head “Tuned Down|Retention”

select end_time, maxquerysqlid, runawayquerysqlid, status,
decode(status,1,’Slot Active’,4,’Reached Best Retention’,5,’Reached Best Retention’,
8, ‘Runaway Query’,9,’Runaway Query-Active’,10,’Space Pressure’,
11,’Space Pressure Currently’,
16, ‘Tuned Down (to undo_retention) due to Space Pressure’,
17,’Tuned Down (to undo_retention) due to Space Pressure-Active’,
18, ‘Tuning Down due to Runaway’, 19, ‘Tuning Down due to Runaway-Active’,
28, ‘Runaway tuned down to last tune down value’,
29, ‘Runaway tuned down to last tune down value’,
32, ‘Max Tuned Down – Not Auto-Tuning’,
33, ‘Max Tuned Down – Not Auto-Tuning (Active)’,
37, ‘Max Tuned Down – Not Auto-Tuning (Active)’,
38, ‘Max Tuned Down – Not Auto-Tuning’,
39, ‘Max Tuned Down – Not Auto-Tuning (Active)’,
40, ‘Max Tuned Down – Not Auto-Tuning’,
41, ‘Max Tuned Down – Not Auto-Tuning (Active)’,
42, ‘Max Tuned Down – Not Auto-Tuning’,
44, ‘Max Tuned Down – Not Auto-Tuning’,
45, ‘Max Tuned Down – Not Auto-Tuning (Active)’,
‘Other (‘||status||’)’) Results, spcprs_retention NewRet
from sys.wrh$_undostat
where status > 1
/

prompt
prompt ############## Details on Long Run Queries ##############
prompt

col sql_fulltext head “SQL Text”
Col sql_id heading “SQL ID”

select sql_id, sql_fulltext, last_load_time “Last Load”,
round(elapsed_time/1000000/60/60/24,0) “Elapsed Days”
from v$sql where sql_id in
(select maxquerysqlid from sys.wrh$_undostat
where status > 1)
/

spool off
set termout on
set trimout off
set trimspool off
clear col

 

11.

 

set lines 120
set pages 999
clear col

set termout off
set trimout on
set trimspool on

connect / as sysdba
alter session set nls_date_format=’dd-Mon-yyyy hh24:mi’;

spool undousage.out

prompt
prompt ############## RUNTIME ##############
prompt

col rdate head “Run Time”

select sysdate rdate from dual;

prompt
prompt ############## IN USE Undo Data ##############
prompt

select
((select (nvl(sum(bytes),0))
from dba_undo_extents
where tablespace_name in (select tablespace_name from dba_tablespaces
where retention like ‘%GUARANTEE’ )
and status in (‘ACTIVE’,’UNEXPIRED’)) *100) /
(select sum(bytes)
from dba_data_files
where tablespace_name in (select tablespace_name from dba_tablespaces
where retention like ‘%GUARANTEE’ )) “PCT_INUSE”
from dual;

select tablespace_name, extent_management, allocation_type,
segment_space_management, retention
from dba_tablespaces where retention like ‘%GUARANTEE’
/

col c format 999,999,999,999 head “Sum of Free”

select (nvl(sum(bytes),0)) c from dba_free_space
where tablespace_name in
(select tablespace_name from dba_tablespaces where retention like ‘%GUARANTEE’)
/

col d format 999,999,999,999 head “Total Bytes”

select sum(bytes) d from dba_data_files
where tablespace_name in
(select tablespace_name from dba_tablespaces where retention like ‘%GUARANTEE’)
/

PROMPT
PROMPT ############## UNDO SEGMENTS ##############
PROMPT

col status head “Status”
col z format 999,999 head “Total Extents”
break on report
compute sum on report of z

select status, count(*) z from dba_undo_extents
group by status
/

col z format 999,999 head “Undo Segments”

select status, count(*) z from dba_rollback_segs
group by status
/

clear break
clear compute

prompt
prompt ############## CURRENT STATUS OF SEGMENTS ##############
prompt ############## SNAPSHOT IN TIME INFO ##############
prompt ##############(SHOWS CURRENT UNDO ACTIVITY)##############
prompt

col segment_name format a30 head “Segment Name”
col “ACT BYTES” format 999,999,999,999 head “Active Bytes”
col “UNEXP BYTES” format 999,999,999,999 head “Unexpired Bytes”
col “EXP BYTES” format 999,999,999,999 head “Expired Bytes”

select segment_name, nvl(sum(act),0) “ACT BYTES”,
nvl(sum(unexp),0) “UNEXP BYTES”,
nvl(sum(exp),0) “EXP BYTES”
from (select segment_name, nvl(sum(bytes),0) act,00 unexp, 00 exp
from dba_undo_extents where status=’ACTIVE’ group by segment_name
union
select segment_name, 00 act, nvl(sum(bytes),0) unexp, 00 exp
from dba_undo_extents where status=’UNEXPIRED’ group by segment_name
union
select segment_name, 00 act, 00 unexp, nvl(sum(bytes),0) exp
from dba_undo_extents where status=’EXPIRED’ group by segment_name)
group by segment_name
order by 1
/

prompt
prompt ############## UNDO SPACE USAGE ##############
prompt

col usn format 999,999 head “Segment#”
col shrinks format 999,999,999 head “Shrinks”
col aveshrink format 999,999,999 head “Avg Shrink Size”

select usn, shrinks, aveshrink from v$rollstat
/
spool off
set termout on
set trimout off
set trimspool off
clear col

自动undo管理模式下的undo错误分析常用脚本

Oracle 每一个版本都发布的用于调查 ORA-1555 错误的脚本,二分切每一版本都有所不同。这些脚本只适用于自动 UNDO 管理 (AUM) 配置的环境。

脚本文件以本文档附件的形式提供。在mos上可以下载到,具体的脚本有如下列出的分类,下载地址参考此链接:http://www.ludatou.com/?page_id=2479

 

AUM 配置和 ORA-1555 全面分析

1. 配置:

UndoDatafiles.sql — spool 输出到位于默认目录位置的文件 undodatafiles.out 中。

UndoParameters.sql — spool 输出到位于默认目录位置的文件 undoparameters.out 中。

UndoUsage.sql — spool 输出到位于默认目录位置的文件 undousage.out 中。

2. 当前未提交的事务:

CurrentActivity.sql — spool 输出到位于默认目录位置的文件 undoactivity.out 中。

3. 历史 UNDO 信息:

UndoHistoryInfo.sql — spool 输出到位于默认目录位置的 undohistory.out 中。

UndoStatistics.sql — spool 输出到位于默认目录位置的 undostatistics.out 中。您可修改此报告以显示适当的分析时间范围。默认情况下,查看最后两天的 V$UNDOSTAT 数据。在 V$UNDOSTAT 视图中,数据会保留七天。

4. 等待/锁定分析:

UndoPressure.sql — spool 输出到位于默认目录位置的 undopressure.out 中。

5. 调查 LOB 问题:

LobData.sql — spool 输出到位于默认目录位置的 lobdata.out 中。

 

1.  配置

示例 undodatafiles.out

############## RUNTIME ##############

Run Time
—————–
05-Jul-2023 08:53

############## DATAFILES ##############

Aut
TBSP Name                   File #   Bytes Alloc (MB) Max Bytes Used (MB) (MB)     Ext
—————————— —— ————————- ———————————— ——
SMALLUNDO                  3                              200                                     200     YES

查看配置数据。AUTOEXTEND 是否打开?如果 UNDO 表空间配置为随着空间需求自动增长,这会对数据库造成影响,数据库可能不会重新使用超过Retention设置的过期 Undo extent,以减少发生 ORA-1555 的几率。表空间进而会随着新的需求增长。

示例 undoparameters.out

############## RUNTIME ##############

Run Time
—————–
05-Jul-2023 08:56

############## PARAMETERS ##############

Instance #  Parameter                              Session Value          Instance Value
————– ———————————– ————————- ————————-
1                 _smu_debug_mode                              33554432                  33554432
1                _undo_autotune                                         TRUE                        TRUE
1                undo_management                                    AUTO                       AUTO
1                undo_retention                                                900                             900
1                undo_tablespace                        SMALLUNDO          SMALLUNDO

查看影响 Undo Retention规则的参数设置。

‘_smu_debug_mode’=33554432 会强制让自动优化程序基于系统中运行时间最长的 SQL 的执行时间来计算自动的 undo retention。在默认情况下,自动调整后的保留时间会增长到很长的时间段,空间压力将成为 Undo 表空间中的重大问题。

‘_undo_autotune’=false 是一些 AUM bug 的权宜方法,但这会对分析产生重大影响。V$UNDOSTAT 中不会再进一步跟踪其他数据,显式指定的的 UNDO_RETENTION 设置是影响 undo Retention处理的关键。

示例 undousage.out

############## RUNTIME ##############

Run Time
————————–
05-JUL-2023 08:58

############## IN USE Undo Data ##############

PCT_INUSE
—————-
23.625

TABLESPACE_NAME    EXTENT_MAN    ALLOCATIO      SEGMEN      RETENTION
——————————— ———————— ———————- —————- —————–
SMALLUNDO                  LOCAL                    SYSTEM             MANUAL    NOGUARANTEE

Sum of Free
—————-
65,536

Total Bytes
—————-
209,715,200

############## UNDO SEGMENTS ##############

Status              Total Extents
—————— —————–
UNEXPIRED                    21
EXPIRED                        807
ACTIVE                          195
————-
sum                               1,023

Status               Total Segments
——————– ——————-
ONLINE                                  11
————-
sum                                          11

2. 当前未提交的事务

示例 undoactivity.out

############## RUNTIME ##############

Run Time
—————–
19-Jul-2023 09:43

############## Current Uncommitted Transactions ##############

Started    User     Undo Segment Name            File #       Block #       Status         KBytes     Rows
———— ——— ————————————- ———— ————– ————– ————- ———-
01/19/23 KEN      _SYSSMU8_1245875459$                  3            9735     ACTIVE       48,664   614,178
09:43:02

查看未提交的事务。该事务有多大?什么用户在处理该事务?随着时间的推移,其是否显示为未提交?这在预期之内吗?在此事务之前开始的任何长时间运行的查询、或在此事务之前使用闪回功能都必须创建此数据的旧“副本”。

3.  历史 UNDO 信息

示例 – undohistory.out

############## RUNTIME ##############

Run Time
—————–
05-Jul-2023 09:08

############## HISTORICAL DATA ##############

Max Concurrent
Last 7 Days
——————–
5

Max Concurrent
Since Startup
———————–
5

1555 Errors
—————
0

Undo Space Errors
————————-
0

############## CURRENT STATUS OF SEGMENTS ##############
############## SNAPSHOT IN TIME INFO ##############
##############(SHOWS CURRENT UNDO ACTIVITY)##############

Segment Name                      Active Bytes     Unexpired Bytes Expired Bytes
———————————– ——————— ———————- ——————–
_SYSSMU10_1245875459$                           0             1,114,112                 65,536
_SYSSMU1_1245875459$                             0             3,211,264          75,497,472
_SYSSMU2_1245875459$                             0                196,608                 65,536
_SYSSMU3_1245875459$                             0             1,507,328          55,115,776
_SYSSMU4_1245875459$             43,253,760                           0                          0
_SYSSMU5_1245875459$                             0             1,048,576          19,922,944
_SYSSMU6_1245875459$                             0                327,680                          0
_SYSSMU7_1245875459$                             0             1,114,112                 65,536
_SYSSMU8_1245875459$                             0                458,752            4,849,664
_SYSSMU9_1245875459$                             0             1,179,648                 65,536

10 rows selected.

############## UNDO SPACE USAGE ##############

Segment#      Shrinks     Avg Shrink Size
—————– ————- ———————–
0                0                              0
1                5                2,424,832
2                5                1,402,470
3                6                2,457,600
4                2                  425,984
5                4                1,638,400
6                4                1,523,712
7                2                1,048,576
8                5                2,031,616
9                1                2,621,440
10                2                1,114,112

11 rows selected.

了解并发性信息。有多少并发性事务相互重叠?如果不断看到高并发的未提交事务,是否自动调整的 retention 正在正确处理工作负载?

对于当前未提交的工作,还可以检查运行时的段活动情况。

同时查看 UNDO 改动的信息。这些段的工作负载是否平衡?收缩是否均匀地分布在段中?是否有任何段承受的压力大于其他段?

示例 undostatistics.out

############## RUNTIME ##############

Run Time
—————–
05-09:08

############## Historical V$UNDOSTAT (Last 2 Days) ##############

Query
Maximum                                               Undo     # of                                                     Tuned Ret
Date/Time Minutes   SqlID                 TBS        Blocks    Trans   # of Unexpired    # of Expired Minutes
————- ————- ——————– ———– ——— ———- ——————— —————- —————
03-09:15                 14 0rc4km05kgzb9           14          39       160                        312           25,024                  29
03-09:25                   4 0rc4km05kgzb9           14          36       220                        312           25,024                  43
03-09:35                 14 0rc4km05kgzb9           14         327      200                            8           25,024                  43
03-09:45                   4 0rc4km05kgzb9           14           20      202                        464           24,896                  29
. . .
05-08:37                   1 0rc4km05kgzb9           14           22      195                           80          25,344                  15
05-08:47                12 0rc4km05kgzb9            14           35      216                           48          25,376                  15
05-08:57                  2 0rc4km05kgzb9            14           33      183                           56          25,368                  15

284 rows selected.

############## RECENT MISSES FOR UNDO (Last 2 Days) ##############

no rows selected

no rows selected

############## AUTO-TUNING TUNE-DOWN DATA ##############
############## ROLLBACK DATA (Since Startup) ##############

Name                                                                                                        Counters
————————————————————————————- ————
user rollbacks                                                                                                 4,959
transaction tables consistent reads – undo records applied                          3
transaction tables consistent read rollbacks                                                    0
data blocks consistent reads – undo records applied                          300,730
rollbacks only – consistent read gets                                                       11,384
cleanouts and rollbacks – consistent read gets                                             39
rollback changes – undo records applied                                                18,529
transaction rollbacks                                                                                       190
total number of undo segments dropped                                                         0
tune down retentions in space pressure                                                           0
global undo segment hints helped                                                                     1
global undo segment hints were stale                                                               0
local undo segment hints helped                                                                       0
local undo segment hints were stale                                                                  0
undo segment header was pinned                                                             90,532
IMU CR rollbacks                                                                                           6,183
SMON posted for undo segment recovery                                                       0
SMON posted for undo segment shrink                                                            0

18 rows selected.

############## Long Running Query History ##############

Date                    SQL ID                Runaway SQL ID                          Space Issues
——————– ———————- —————————————– ————————————————
02-19:05              0rc4km05kgzb9                                                          Max Tuned Down – Not Auto-Tuning
02-19:15              0rc4km05kgzb9                                                          Reached Best Retention
02-19:25              0rc4km05kgzb9                                                          Reached Best Retention
02-19:35              0rc4km05kgzb9                                                          Reached Best Retention
02-19:45              0rc4km05kgzb9                                                          Reached Best Retention

############## Details on Long Run Queries ##############

SQL ID                 SQL Text                                                                                             Last Load                  Elapsed Days
———————- ——————————————————————————— ————————– ——————
0rc4km05kgzb9    select 1 from obj$ where name=’DBA_QUEUE_SCHEDULES’  2009-08-04/13:30:06                     19

查看报告中在设定时间内收集的关于 undo 活动的数据(默认为 2 天)。

第二部分将显示在 V$UNDOSTAT 中的七天或在实例生命周期中,查询持续时间大于调整后的Retention时间的情况。

是否有大量的“调低”相关活动?“调低”是自动调整 AUM 的一种功能,将会收缩保留时间以减少 UNDO 空间压力。这可指向尚未引发 ORA-30036 错误的空间问题。

最后调查长时运行查询数据。这些可能是我们预期内的,但也有助于指出意外的查询活动。

4. 等待/锁定分析

示例 undopressure.out

############## RUNTIME ##############

Run Time
—————–
05-08:58

############## WAITS FOR UNDO (Since Startup) ##############

Cummalitve
Instance# Enq Total Requests   Total Waits       Successes           Failures             Time
————- —— ——————– —————- ———————— ————— ——————
1                 HW                  2,104                     0                       2,104                    0                       0
1                  US                        58                     0                            58                    0                       0

############## LOCKS FOR UNDO ##############

no rows selected

############## TUNED RETENTION HISTORY (Last 2 Days) ##############
############## LOWEST AND HIGHEST DATA ##############

END_TIME TUNED_UNDORETENTION
—————– ————————————–
05-08:58                                                      900
05-08:57                                                      900
05-08:37                                                      900
05-07:17                                                      900
05-04:17                                                      900
05-03:57                                                      900
05-03:37                                                      900
05-02:57                                                      900
05-02:37                                                      900
05-02:17                                                      900
05-01:17                                                      900

11 rows selected.

END_TIME TUNED_UNDORETENTION
—————– ————————————-
04-17:57                                                   2227

############## CURRENT TRANSACTIONS ##############

START_DATE  START_SCN   STATUS            SQL Code
——————— —————— —————- —————————————-
05-08:58               53717782         ACTIVE       update abc_tmp set edition_name=”

CURRENT_SCN
———————
53734654

############## WHO’S STEALING WHAT? (Last 2 Days) ##############

UnexStolen ExStolen UnexReuse ExReuse
————— ———— ————— ———–
0              22                   0              0
0              12                   0              0

查看等待和锁定信息。高等待和性能问题可能与已知的 UNDO 性能 bug 匹配。同时查看高、低调整后的Retention信息。在此报告中,您是否发现被盗 extent 的证据?未过期 extent 是否被盗?

5. 调查 LOB 问题

示例 lobdata.out

Table               Column                                                Tablespace       PCTVersion %   Retention
—————— ———————————————- ——————– ——————– ————-
CTEST             DATA_OBJECT                                TB1                                                          900
PAA_TEST    RESPONDER_COMMENT              TB1                                                          900
EMP_O           PICTURE                                             USERS                                      10
EMP_O           RESUME                                             USERS                                      10
TEST               COMMENTS                                      TB1                                                          900

5 rows selected.

如果定期更新 LOB 数据,LOB 对象上发生 ORA-1555 就可能是预期内的。PCTVersion 默认为 10%,如果持续对 LOB 数据进行了更改,那么这个此值通常需要调高很多。有时 100%(保留所有更改)还不足以适应工作负载。常规的 ORA-1555 诊断/分析对与 LOB 相关的 ORA-1555 错误是没有用的。LOB 产生的 UNDO 不是使用 UNDO 表空间中的 extent,而是保留在 LOB 表空间中。

 

规范使用脚本用以诊断和分析 ORA-1555 错误(自动undo管理模式下的undo错误分析常用脚本)

有经验的DBA都知道SHUTDOWN ABORT 是关闭数据库的最快方式。

但是,以这种形式关闭数据库会使数据库处于不一致的状态(没有回滚),在这种情况下的备份在下次启动时需要恢复 。

在8.1.6以前的版本里,数据库是不推荐使用SHUTDOWN ABORT,因为在这么老的版本上这么做导致数据库损坏的概率很大。

 

在执行快速关闭之前,建议按照如下顺序来操作:

1.通过下面的查询判定干净的关闭数据库需要多少回滚(以字节计算)

select sum(used_ublk) * <undo / rollback segment 表空间的block size> from v$transaction;

2. SHUTDOWN ABORT

将不进行事务回滚,快速的中断所有进程 (客户端 和 后台)。

 

A SHUTDOWN IMMEDIATE时SMON会尝试中断所有客户端进程(SIGKILL),但是很多情况下SMON无法及时完成,这是使用SHUTDOWN ABORT的原因。

3.在下次启动时,SMON会回滚事务。

可以通过STARTUP RESTRICT启动

然后通过下面的查询语句查看回滚(块的个数)

select sum(distinct(ktuxesiz)) from x$ktuxe where ktuxecfl = ‘DEAD’;

6.当回滚完成 (当上次关闭数据库时候,活动事务不多的情况下,有可能启动后立刻就完成了), 执行 SHUTDOWN IMMEDIATE。
当完成此步骤后,数据库将干净的关闭

 

这里早前碰见过一个BUG,一个没有发布的SQLPLUS内部bug会阻止SQLPLUS会话被SMON中断,客户端进程的truss / pdump等会显示SQLPLUS会话在等待WAITPID

 

各版本Oracle数据库快速关闭的方式