Skip to content

19c的重要特性之一DML重定向,原理发送到ADG备库上的DML操作,自动转发到主库执行,然后通过主库日志传递到备库实时应用,在保证了ACID的前提下,增强了备库的功能性

在 18c 中,这个特性是否启用通过隐含参数 _enable_proxy_adg_redirect 控制;

在 19c 中,则由显式参数 ADG_REDIRECT_DML控制;

SQL> show parameter ADG_REDIRECT_DML

NAME TYPE VALUE
———————————— ———– ——————————
adg_redirect_dml boolean FALSE

SQL> alter system set adg_redirect_dml=true scope=both;

System altered.

SQL> create user test identified by test;
create user test identified by test
*
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

SQL> create table test(id int,sdate char(20));
create table test(id int,sdate char(20))
*
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access

SQL> conn luda/luda
Connected.
SQL> show parameter ADG_REDIRECT_DML

NAME TYPE VALUE
———————————— ———– ——————————
adg_redirect_dml boolean TRUE
SQL>
alter session set events ‘10046 trace name context forever ,level 12′;

insert into test values (1, to_char(current_timestamp at time zone dbtimezone,’dd-mon-rr hh:mi:ss’));

alter session set events ‘10046 trace name context off’;

select distinct(m.sid),p.pid,p.tracefile from v$mystat m,v$session s,v$process p where m.sid=s.sid and s.paddr=p.addr;

SID PID
———- ———-
TRACEFILE
——————————————————————————–
223 44
/u01/app/oracle/diag/rdbms/std/orcl/trace/orcl_ora_1768553.trc

格式化输出

tkprof /u01/app/oracle/diag/rdbms/std/orcl/trace/orcl_ora_1768553.trc /home/oracle/orcl_ora_1768553.out

[oracle@oracle19c ~]$ cat orcl_ora_1768553.out

TKPROF: Release 19.0.0.0.0 – Development on Mon Apr 27 07:56:09 2020

Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.

Trace file: /u01/app/oracle/diag/rdbms/std/orcl/trace/orcl_ora_1768553.trc
Sort options: default

********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************

The following statement encountered a error during parse:

insert into test values (1, to_char(current_timestamp at time zone dbtimezone,’dd-mon-rr hh:mi:ss’))

Error encountered: ORA-01157
********************************************************************************

SQL ID: 8r8b2pyy9qjm2 Plan Hash: 0

alter session set events ‘10046 trace name context forever, level 12’

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

Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 106

Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
—————————————- Waited ———- ————
SQL*Net message to client 3 0.00 0.00
SQL*Net message from client 3 26.12 47.13
SQL*Net break/reset to client 3 0.00 0.00
single-task message 1 0.01 0.01
SQL*Net message from dblink 7 0.01 0.02
SQL*Net message to dblink 6 0.00 0.00
SQL*Net vector data to dblink 1 0.00 0.00
asynch descriptor resize 1 0.00 0.00
Disk file operations I/O 1 0.00 0.00
control file sequential read 8 0.00 0.00
********************************************************************************

SQL ID: 06nvwn223659v Plan Hash: 0

alter session set events ‘10046 trace name context off’

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

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 106

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

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

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

Misses in library cache during parse: 1
Misses in library cache during execute: 1

Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
—————————————- Waited ———- ————
SQL*Net message to client 3 0.00 0.00
SQL*Net message from client 3 26.12 47.13
SQL*Net break/reset to client 3 0.00 0.00
single-task message 1 0.01 0.01
SQL*Net message from dblink 7 0.01 0.02
SQL*Net message to dblink 6 0.00 0.00
SQL*Net vector data to dblink 1 0.00 0.00
asynch descriptor resize 1 0.00 0.00
Disk file operations I/O 1 0.00 0.00
control file sequential read 8 0.00 0.00

OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

call count cpu elapsed disk query current rows
——- —— ——– ———- ———- ———- ———- ———-
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
——- —— ——– ———- ———- ———- ———- ———-
total 0 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0

2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
********************************************************************************
Trace file: /u01/app/oracle/diag/rdbms/std/orcl/trace/orcl_ora_1768553.trc
Trace file compatibility: 12.2.0.0
Sort options: default

1 session in tracefile.
2 user SQL statements in trace file.
0 internal SQL statements in trace file.
2 SQL statements in trace file.
2 unique SQL statements in trace file.
88 lines in trace file.
47 elapsed seconds in trace file.

Oracle 19C ADG的自动DML重定向 ADG_REDIRECT_DML

RDA Remote Diagnostic Agent

RDA Remote Diagnostic Agent远程诊断代理是Oracle Support售后服务使用的标准工具之一,当用户在Metalink上提交SR(TAR)时可能Oracle GCS(Global Customer Service)支持会需要让用户从MOS上下载RDA工具,通过RDA收集丰富的数据库环境信息(如包含OS、DB、CRS等),以便原厂售后直接从RDA report中抓取诊断信息,避免了因诊断信息不足 而反复信息交互所浪费的时间 ; 此外Oracle的一些ACS高级客户服务的现场服务过程中也会利用到RDA,例如当用户要求ACS到现场进行月度或季度巡检是RDA就是标准的检查工具。

 

说具体参考My Oracle Support(metalink)的《Remote Diagnostic Agent (RDA) 4 – Getting Started [ID 314422.1]》专栏中下载到各个平台的最新版RDA。

首先配置就是选择我们要使用的RDA module和一些临时设置,先来认识一下有哪些module:

 

将下载到的rda zip包解压

[oracle@vrh8 ~]$ unzip /tmp/p9079828_418_LINUX.zip 

[oracle@vrh8 ~]$ cd rda

[oracle@vrh8 rda]$ ./rda.sh -h
Usage: rda.pl [-bcdflntvwxy] [-ABCDEHIKLMPQRSTV] [-e list] [-m dir]
              [-s name] [-o out] [-p prof] arg ...
        -A      Authentify user through the setup file
        -B      Start background collection
        -C      Collect diagnostic information
        -D      Delete specified modules from the setup
        -E      Explain specified error numbers
        -H      Halt background collection
        -I      Regenerate the index
        -K      Kill background collection
        -L      List the modules available
        -M      Display the related manual pages
        -O      Render output specifications from STDIN
        -P      Package the reports (tar or zip)
        -Q      Display the related setup questions
        -R      Generate specified reports
        -S      Setup specified modules
        -T      Execute test modules
        -V      Display component version numbers
        -b      Don't backup setup file before saving
        -c      Check the RDA installation and exit
        -d      Set debug mode
        -e list Specify a list of alternate setting definitions (var=val,...)
        -f      Set force mode
        -h      Display the command usage and exit
        -l      Use a lock file to prevent concurrent usage of a setup file
        -m dir  Specify the module directory ('modules' by default)
        -n      Start a new data collection
        -o out  Specify the file for background collection output redirection
        -p prof Specify the setup profile ('Default' by default)
        -q      Set quiet mode
        -s name Specify the setup name ('setup' by default)
        -t      Set trace mode
        -v      Set verbose mode
        -w      Wait as long as the background collection daemon is active
        -x      Produce module cross reference
        -y      Accept all defaults and skip all pauses

列出所有可用module

[oracle@vrh8 rda]$ ./rda.sh -L Module

Available data collection modules are:
  ACFS     Collects ASM Cluster File System Information
  ACT      Collects Oracle E-Business Suite Application Information
  ADBA     Collects ACS Oracle Database Assessment
  ADX      Collects AutoConfig and Rapid Clone Information
  AGT      Collects Enterprise Manager Agent Information
  APEX     Collects APEX Information
  ASAP     Collects Oracle Communications ASAP Information
  ASBR     Collects Application Server Backup and Recovery Information
  ASG      Collects Application Server Guard Information
  ASIT     Collects Oracle Application Server Installation Information
  ASM      Collects Automatic Storage Management Information
  B2B      Collects Oracle Business to Business Information
  BAM      Collects Business Activity Monitoring Information
  BEE      Collects Beehive Information
  BI       Collects Oracle Business Intelligence Enterprise Edition Info.
  BPEL     Collects Oracle BPEL Process Manager Information
  BR       Collects Database Backup and Recovery Information
  BRM      Collects Oracle Communications BRM Information
  CCR      Collects OCM Diagnostic Information
  CFG      Collects Key Configuration Information
  COHR     Collects Oracle Coherence Information
  CONT     Collects Oracle Content Services Information
  CRID     Collects Oracle Access Manager (COREid) Information
  D2PC     Collects Distributed Transaction Information
  DB       Controls RDBMS Data Collection
  DBA      Collects RDBMS Information
  DBC      Collects Database Control Information
  DBM      Collects RDBMS Memory Information
  DEV      Collects Oracle Developer Information
  DG       Collects Data Guard Information
  DNFS     Collects Direct NFS Information
  DSCS     Collects Discussions Information
  DSCV     Collects Oracle Discoverer Information
  ECM      Controls Oracle Enterprise Content Management 11g Data Collection
  EM       Collects Enterprise Manager OMS and Repository Info (Obsolete)
  END      Finalizes the Data Collection
  EPMA     Collects Enterprise Performance Management Architect Information
  ESB      Collects Enterprise Service Bus Information
  ESS      Collects Oracle Essbase Information
  ESSO     Collects Oracle Enterprise Single Sign-On Information
  EXA      Collects Exadata Information
  FLTR     Controls Report Content Filtering
  GRDN     Collects Oracle Guardian Information
  GRID     Controls Grid Control Data Collection
  GTW      Collects Transparent/Procedural Gateway Information
  HFM      Collects Oracle Hyperion Financial Management information
  HPL      Collects Oracle Hyperion Planning Information
  IA       Collects Intelligent Agent Information
  IAS      Collects Web Server Information
  IFS      Collects iFS (iFS, CMSDK, Files) Information
  INI      Initializes the Data Collection
  INST     Collects the Oracle Installation Information
  IPSA     Collects Oracle Communications IP Service Activator Information
  J2EE     Collects J2EE/OC4J Information
  JDBC     Collects Oracle Java DB Connectivity (JDBC) Information
  JDEV     Collects Oracle JDeveloper Information
  JIVE     Collects Jive Information
  LANG     Collects Oracle Language Information
  LOAD     Produces the External Collection Reports
  LOG      Collects Database Trace and Log Files
  MAIL     Collects Oracle Collaboration Suite Mail Information
  MSLG     Collects Microsoft Languages Information
  ND       Collects Oracle Communications Network Discovery Information
  NET      Collects Network Information
  NM       Collects Oracle Communications Network Mediation Information
  NPRF     Samples Performance Information (root not required)
  OCAL     Collects Oracle Calendar Information
  OCFS     Collects Oracle Cluster File System Information
  OCM      Setting up Configuration Manager Interface
  OCS      Controls Oracle Collaboration Suite Data Collection
  ODI      Collects Oracle Data Integrator Information
  ODM      Collects Oracle Data Mining Information
  OES      Collects Oracle Express Server Information
  OID      Collects Oracle Internet Directory Information
  OIM      Collects Oracle Identity Manager Information
  OLAP     Collects OLAP Information
  OMM      Collects Oracle Multimedia or Oracle interMedia Information
  OMS      Collects Oracle Management Server Information (obsolete)
  ONET     Collects Oracle Net Information
  OS       Collects the Operating System Information
  OVD      Collects Oracle Virtual Directory Information
  OVMM     Collects Oracle VM Manager Information
  OVMS     Collects Oracle VM Server Information
  OWB      Collects Oracle Warehouse Builder Information
  OWSM     Collects Oracle Web Services Manager Information
  PDA      Collects Oracle Portal Information
  PDBA     Collects PeopleSoft Information from an Oracle Database
  PERF     Collects Performance Information
  PLNC     Collects Oracle PL/SQL Native Compilation Information
  PROF     Collects the User Profile
  PS       Collects Oracle Communications Policy Services Information
  PWEB     Collects PeopleSoft Information from Web Application Server
  RAC      Collects Cluster Information
  RACD     Performs a Database Hang Analysis
  RDSP     Produces the Remote Data Collection Reports
  RET      Collects Oracle Retail Information
  REXE     Performs the Remote Data Collections
  RPRF     Samples Performance Information (root privileges required)
  RSRC     Collects Database Resource Manager Information
  RTC      Collects Real Time Communication Information
  SEBL     Collects Siebel Information
  SES      Collects Oracle Secure Enterprise Search Information
  SMPL     Controls Sampling
  SOA      Collects Oracle SOA Suite Information
  SP       Collects SQL*Plus/iSQL*Plus Information
  SSO      Collects Single Sign-On Information
  STC      Collects Streams Configuration Information
  STM      Collects Streams Monitoring Information
  TOPL     Collects Oracle TopLink Information
  TTEN     Collects Oracle TimesTen In-Memory Database Information
  UCM      Collects Oracle Universal Content Management Information
  UOA      Collects Oracle Universal Online Archive 11g Information
  WAC      Collects Web Access Client Information
  WCI      Collects Oracle WebCenter Information
  WEBC     Collects Oracle Web Cache Information
  WKSP     Collects Workspaces Information
  WLS      Collects Oracle WebLogic Server Information
  WMC      Collects Webmail Client Information
  WRLS     Collects Wireless Information
  XDB      Collects XDB Information
  XSMP     Samples User Defined Data
  XTRA     Collects User Defined Data

 

 

如以上列表中RAC模块用来Collects Cluster Information收集集群信息, 而RACD模块则负责收集RAC数据库挂起的相关信息Performs a Database Hang Analysis。

 

我们在配置RDA的时可以直接执行./rda.sh, 脚本会提示我们需要选择启用哪些Module,但是因为Module过多,整个配置过程就会浪费很多时间。

 

为了避免每配置一套新环境都要大费周章确认那么多模块, 所以在RDA中定义了很多典型场景使用的profile, 这些profile已经配好了固定的一些Module , 下面我们来看一下RDA profile:

 

 

列出所有目前可用的profile

[oracle@vrh8 rda]$ ./rda.sh -L profiles
Available profiles are:
  9iAS               Oracle Application Server 9i problems
  AS10g              Oracle Application Server 10g problems
  AS10g_Identity     Oracle Identity Management 10g problems
  AS10g_MidTier      Oracle Application Server 10g Middle Tier problems
  AS10g_Repository   Oracle Application Server 10g metadata repository problems
  AS10g_WebTier      Oracle Application Server 10g WebTier problems
  AS_BackupRecovery  Oracle Application Server backup/recovery problems
  Act                Oracle Application Overview
  AppsCheck          Equivalent to AppsCheck
  AsmFileSystem      Oracle ASM Cluster File System problems
  Bam                Business Activity Monitoring problems
  Beehive            Oracle Beehive problems
  DB10g              Oracle Database 10g problems
  DB11g              Oracle Database 11g problems
  DB8i               Oracle Database 8i problems
  DB9i               Oracle Database 9i problems
  DB_Assessment      Oracle Database assessment collections
  DB_BackupRecovery  Oracle Database backup and recovery problems
  DB_Perf            Oracle Database performance problems
  DataGuard          Data Guard problems
  DirectNFS          Direct NFS problems
  Discoverer10g      Oracle Discoverer 10g problems
  Discoverer11g      Oracle Discoverer 11g problems
  EnterpriseSearch   Oracle Secure Enterprise Search problems
  Essbase            Oracle Essbase problems
  FM11g_Bi           Business Intelligence Enterprise Edition 11g problems
  FM11g_Ecm          Oracle Enterprise Content Management 11g problems
  FM11g_Forms        Oracle Forms 11g problems
  FM11g_Identity     Oracle Identity Management 11g problems
  FM11g_Odi          Oracle Data Integrator Standalone 11g problems
  FM11g_Portal       Oracle Portal 11g problems
  FM11g_Reports      Oracle Reports 11g problems
  FM11g_Soa          Oracle SOA Suite 11g problems
  FM11g_WebTier      Oracle Fusion Middleware 11g Web Tier problems
  FM11g_WlsBi        Business Intelligence Enterprise Edition 11g with WLS
  FM11g_WlsForms     Oracle Forms 11g with WLS problems
  FM11g_WlsIdentity  Oracle Identity Management 11g with WLS problems
  FM11g_WlsOdi       Oracle Data Integrator Suite 11g with WLS problems
  FM11g_WlsPortal    Oracle Portal 11g with WLS problems
  FM11g_WlsReports   Oracle Reports 11g with WLS problems
  FM11g_WlsWebTier   Oracle Fusion Middleware 11g Web Tier with WLS problems
  FinManagement      Oracle Hyperion Financial Management problems
  GridControl        Grid Control problems
  InterMedia         Oracle interMedia problems
  Linux              Linux problems
  LinuxPerf          Linux performance problems
  Maa_Assessment     Maximum Availability Architecture assessment collections
  Multimedia         Oracle Multimedia problems
  OSMonitor          Operating System performance sampling
  OVMManager         Oracle VM Manager problems
  Pda10g             Portal 10g problems
  Pda11g             Portal 11g problems
  Pda9i              Portal 9i problems
  PeopleSoft_DB      PeopleSoft Oracle Database tier assessment collections
  PeopleSoft_Web     PeopleSoft Web application server assessment collections
  Rac                Real Application Cluster problems
  Rac_AdvancedAsm    Cluster with ASM problems (ASM advanced mode)
  Rac_Asm            Cluster with ASM problems
  Rac_Assessment     Real Application Cluster assessment collections
  Rac_Perf           Cluster performance problems
  Retail             Oracle Retail problems
  Security           Filter sensitive information from the reports
  SupportInformer70  Oracle Communication BRM 7.0 problems
  SupportInformer72  Oracle Communication BRM 7.2 problems
  SupportInformer73  Oracle Communication BRM 7.3 problems
  SupportInformer74  Oracle Communication BRM 7.4 problems
  TimesTen           Oracle TimesTen problems
  TopLink10g         Oracle TopLink 10g problems
  WebCenter10g       Oracle WebCenter 10g problems
  WebCenter11g       Oracle WebCenter 11g problems
  WebCenterCont10g   Oracle WebCenter 10g with Oracle Content Services problems
  WebLogicServer     Oracle WebLogic Server problems

 

 

上例列出了该版本RDA默认就有的Profile , 如DB11g这个profile是用来收集11g Database数据库的诊断信息的, 而DB10g 是收集10g Database诊断信息的, DB_Perf是收集数据库性能诊断信息的。

可以具体了解 这些profile 预设了哪些Module:

 

 

[oracle@vrh8 rda]$ ./rda.sh -M -p DB11g
NAME
    Profile DB11g - Oracle Database 11g problems

MODULES
    The DB11g profile uses the following modules:
      OS        Collects the Operating System Information
      PROF      Collects the User Profile
      PERF      Collects Performance Information
      NET       Collects Network Information
      ONET      Collects Oracle Net Information
      INST      Collects the Oracle Installation Information
      DB        Controls RDBMS Data Collection
      DBA       Collects RDBMS Information
      DBM       Collects RDBMS Memory Information
      LOG       Collects Database Trace and Log Files
      DNFS      Collects Direct NFS Information
      SP        Collects SQL*Plus/iSQL*Plus Information
      GRID      Controls Grid Control Data Collection
      AGT       Collects Enterprise Manager Agent Information
      DBC       Collects Database Control Information

[oracle@vrh8 rda]$ ./rda.sh -M -p DB10g
NAME
    Profile DB10g - Oracle Database 10g problems

MODULES
    The DB10g profile uses the following modules:
      OS        Collects the Operating System Information
      PROF      Collects the User Profile
      PERF      Collects Performance Information
      NET       Collects Network Information
      ONET      Collects Oracle Net Information
      INST      Collects the Oracle Installation Information
      DB        Controls RDBMS Data Collection
      DBA       Collects RDBMS Information
      DBM       Collects RDBMS Memory Information
      LOG       Collects Database Trace and Log Files
      SP        Collects SQL*Plus/iSQL*Plus Information
      GRID      Controls Grid Control Data Collection
      AGT       Collects Enterprise Manager Agent Information
      DBC       Collects Database Control Information

 

 

除了module之外profile可能还定义了一些临时变量如force_onet_tests 是否强制做oracle net网络测试等, 可以用-f( Set force mode)选项来列出这些temporary settings:

 

 

[oracle@vrh8 rda]$ ./rda.sh -fM -p DB10g
NAME
    Profile DB10g - Oracle Database 10g problems

MODULES
    The DB10g profile uses the following modules:
      OS        Collects the Operating System Information
      PROF      Collects the User Profile
      PERF      Collects Performance Information
      NET       Collects Network Information
      ONET      Collects Oracle Net Information
      INST      Collects the Oracle Installation Information
      DB        Controls RDBMS Data Collection
      DBA       Collects RDBMS Information
      DBM       Collects RDBMS Memory Information
      LOG       Collects Database Trace and Log Files
      SP        Collects SQL*Plus/iSQL*Plus Information
      GRID      Controls Grid Control Data Collection
      AGT       Collects Enterprise Manager Agent Information
      DBC       Collects Database Control Information

SETTINGS
    The DB10g profile sets the following temporary settings:
      force_db_tests=1
      force_dba_tests=1
      force_dbm_tests=1
      force_log_tests=1
      force_onet_tests=1

 

 

也可以列出全部预定义的profile的Module信息:

 

 

[oracle@vrh8 rda]$ ./rda.sh -xv profiles
Treating profiles ...
Profile Cross Reference

Defined Profiles:
  9iAS               S100OS, S105PROF, S110PERF, S120NET, S130INST, S300IAS,
                     S305ASBR, S306ASG, S310J2EE, S330SSO, S340OID, S350WEBC
  AS10g              S100OS, S105PROF, S110PERF, S120NET, S130INST, S300IAS,
                     S305ASBR, S306ASG, S310J2EE, S330SSO, S340OID, S350WEBC
  AS10g_Identity     S100OS, S105PROF, S110PERF, S120NET, S130INST, S300IAS,
                     S305ASBR, S306ASG, S310J2EE, S330SSO, S340OID, S342OVD
  AS10g_MidTier      S100OS, S105PROF, S110PERF, S120NET, S130INST, S249WRLS,
                     S290DEV, S300IAS, S310J2EE, S325PDA, S350WEBC, S390DSCV
  AS10g_Repository   S100OS, S105PROF, S110PERF, S120NET, S130INST, S300IAS,
                     S305ASBR, S306ASG, S310J2EE
  AS10g_WebTier      S100OS, S105PROF, S110PERF, S120NET, S130INST, S300IAS,
                     S310J2EE, S350WEBC, S410GRID
  AS_BackupRecovery  S100OS, S300IAS, S305ASBR
  Act                S100OS, S105PROF, S110PERF, S130INST, S500ACT
  AppsCheck          S100OS, S105PROF, S110PERF, S130INST, S500ACT
  AsmFileSystem      S100OS, S105PROF, S120NET, S122ONET, S130INST, S402ASM,
                     S403ACFS
  Bam                S100OS, S105PROF, S110PERF, S120NET, S374BAM
..........

 

 

 

使用-Q 选项可以更详细地列出profile相关的问题:

 

 

[oracle@vrh8 rda]$ ./rda.sh -Q -p DB11g

NAME
    S120NET - Collects Network Information

SETTING DESCRIPTION
  NETWORK_PING_TESTS
    "Do you want RDA to perform the network ping tests (Y/N)?"

  LOCAL_NODE
    "Enter the name of the node the script is running on (used for ping
    tests)"

  WAN_NODE
    "Enter a remote node connecting to this server (used for ping tests)"

  RDBMS_NODE
    "Enter the node hosting the database instance (used for ping tests)"

  WEB_NODE
    "Enter the node where the Web Server/Forms server is on (used for ping
    tests)"

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

 

 

通过继承profile的定义可以快速配置RDA,例如我们尝试使用DB11g这个profile:

 

 

[oracle@vrh8 rda]$ ./rda.sh -S -p DB11g

使用profile后RDA问你的问题明显减少了哦

之后在运行rda.sh就会收集信息了

[oracle@vrh8 rda]$ ./rda.sh
-------------------------------------------------------------------------------
RDA Data Collection Started 06-Feb-2012 01:23:22
-------------------------------------------------------------------------------
Processing Initialization module ...
Enter the password for 'SYSTEM':
Please re-enter it to confirm:
Processing OCM module ...
Processing PERF module ...
Processing CFG module ...
Processing OS module ..

 

 

可能你还是觉得麻烦:”我使用oracle操作系统用户登录的,为啥每次还要输密码呢?直接sysdba不行吗?” 对于有些内部视图X$ View的查询也确实需要sysdba权限, 我们可以如下设置来使用sysdba身份:

 

[oracle@vrh8 rda]$ ./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DB11g

[oracle@vrh8 rda]$ ./rda.sh
-------------------------------------------------------------------------------
RDA Data Collection Started 06-Feb-2012 01:27:37
-------------------------------------------------------------------------------
Processing Initialization module ...
Processing OCM module ...
Processing PERF module ...
Processing CFG module ...
Processing OS module ...

 

 

除了单独使用某个profile外,我们还可以组合使用多个profile,使用-p profile1-profile2这样的语法即可,如:

 

[oracle@vrh8 rda]$ ./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DB11g-DataGuard

使用-p profile1-profile2这样的模式即可

 

 

RDA经过配置后会默认将配置信息写到其目录下的setup.cfg文件中,之后再使用rda.sh收集信息即会沿用该cfg文件:

 

 

cat setup.cfg

# Oracle Remote Diagnostic Agent - Setup Information
###############################################################################

#------------------------------------------------------------------------------
# Data Collection Overview
#------------------------------------------------------------------------------
# S000INI=pending
# S010CFG=pending
# S020SMPL=pending
# S090OCM=pending
# S100OS=pending
# S105PROF=pending
# S110PERF=pending
# S120NET=pending
# S122ONET=pending
# S130INST=pending
# S200DB=skip
# S201DBA=pending
# S203DBM=pending
# S204LOG=pending
# S205BR=pending
# S212DNFS=skip
# S213SP=skip
# S400RAC=pending
# S400RACD=skip
# S401OCFS=skip
# S405DG=pending
# S410GRID=skip
# S420AGT=skip
# S430DBC=skip
# S909RDSP=skip
# S919LOAD=pending
# S990FLTR=skip
www.askmaclean.com
www.askmaclean.com
# S999END=pending
.................

 

 

除了最常见的DB11g 、 DB10g外还有一些很有用的profile可以加速我们对问题的诊断, 在这里分享一下:

 

 

For 11g

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DB11g

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1 -p DB11g
--收集alert文本

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1,DBCONTROL_SERVER_IN_USE=1 -p DB11g
--收集DBcontrol信息

./rda.sh -vSCRPfy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1 -p DB11g
--收集诊断信息并打包

DB10g 

./rda.sh -S -p DB10g

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DB10g

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,DBCONTROL_SERVER_IN_USE=1 -p DB10g

DB9i

./rda.sh -S -p DB9i

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DB9i

DB_BackupRecovery 收集备份恢复信息

./rda.sh -S -p DB_BackupRecovery

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,RMAN_IN_USE=0 -p DB_BackupRecovery
--不使用RMAN备份

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,RMAN_IN_USE=1,RMAN_CATALOG=0 -p DB_BackupRecovery
--使用RMAN但不使用CATALOG恢复目录

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,RMAN_IN_USE=1,RMAN_CATALOG=1,RMAN_SCHEMA=rman,RMAN_EXPORT_USER=rman@catlogdb -p DB_BackupRecovery

DB_Perf 收集数据库性能信息

./rda.sh -S -p DB_Perf

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DB_Perf

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,PERF_START_TIME=11-Mar-2010_12:00,PERF_END_TIME=11-Mar-2010_13:00 -p DB_Perf
--指定收集性能信息的时间段 

DataGuard 收集dg 信息

./rda.sh -S -p DataGuard

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DataGuard

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ONET_IN_USE=1,ALERT_TEXT=1 -p DataGuard
--同时也收集Oracle Net Services信息

RAC 收集Real Application Cluster CRS信息

./rda.sh -S -p Rac

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p Rac

RAC ASM   收集 Rac + Clusterware + Asm 信息

./rda.sh -S -p Rac_Asm

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ASM_ORACLE_SID=+ASM1 -p Rac_Asm

Rac_AdvancedAsm 收集更详细的Rac + Clusterware + Asm 信息

./rda.sh -S -p Rac_AdvancedAsm

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ASM_ORACLE_SID=+ASM1 -p Rac_AdvancedAsm

Rac_Perf  收集RAC数据库性能信息

./rda.sh -S -p Rac_Perf

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p Rac_Perf

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,PERF_START_TIME=11-Mar-2010_12:00,PERF_END_TIME=11-Mar-2010_13:00 -p Rac_Perf

DirectNFS 

./rda.sh -S -p DirectNFS

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p DirectNFS

AsmFileSystem

./rda.sh -S -p AsmFileSystem

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p AsmFileSystem

DB_Assessment 

./rda.sh -S -p Rac_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p Rac_Assessment

 Rac_Assessment

./rda.sh -S -p Rac_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p Rac_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ASM_ORACLE_SID=+ASM1 -p Rac_Assessment

 Maa_Assessment

./rda.sh -S -p Maa_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/ -p Maa_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ASM_ORACLE_SID=+ASM1 -p Maa_Assessment

Exadata_Assessment

./rda.sh -S -p Exadata_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1 -p Exadata_Assessment

 ./rda.sh -vSCRPfy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1,EXA_COLLECT_CELL=0 -p Exadata_Assessment

 ./rda.sh -vSCRPfy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1 -p Exadata_Assessment

Maa_Exa_Assessment

./rda.sh -S -p Maa_Exa_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1 -p Maa_Exa_Assessment

./rda.sh -Sy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1,EXA_COLLECT_CELL=0 -p Maa_Exa_Assessment

./rda.sh -vSCRPfy -e SQL_SYSDBA=1,SQL_LOGIN=/,ALERT_TEXT=1 -p Maa_Exa_Assessment

 

 

 

还可以利用rda对OS做数据库软件安装前的预检查,如将需要安装11.2g,则执行 ./rda.sh -T hcve:

 

 

[oracle@vrh8 rda]$ ./rda.sh -T hcve
Processing HCVE tests ...
Available Pre-Installation Rule Sets:
1. Oracle Database 10g R1 (10.1.0) Preinstall (Linux-x86)
2. Oracle Database 10g R1 (10.1.0) Preinstall (Linux AMD64)
3. Oracle Database 10g R1 (10.1.0) Preinstall (IA-64 Linux)
4. Oracle Database 10g R2 (10.2.0) Preinstall (Linux AMD64)
5. Oracle Database 10g R2 (10.2.0) Preinstall (IA-64 Linux)
6. Oracle Database 10g R2 (10.2.0) Preinstall (Linux-x86)
7. Oracle Database 11g R1 (11.1.0) Preinstall (Linux AMD64)
8. Oracle Database 11g R1 (11.1.0) Preinstall (Linux-x86)
9. Oracle Database 11g R2 (11.2.0) Preinstall (Linux-x86)
ID     NAME                 RESULT  VALUE
====== ==================== ======= ==========================================
A00010 OS Certified?        PASSED  Adequate
A00050 Enter ORACLE_HOME    RECORD  /s01/oracle/product/10.2.0/db_1
A00060 ORACLE_HOME Valid?   PASSED  OHexists
A00070 O_H Permissions OK?  PASSED  CorrectPerms
A00080 oraInventory Permiss PASSED  oraInventoryOK
A00090 Got ld,nm,ar,make?   PASSED  ld_nm_ar_make_found
A00100 Umask Set to 022?    PASSED  UmaskOK
A00120 Limit Processes      PASSED  Adequate
A00130 Limit Descriptors    PASSED  Adequate
A00140 LDLIBRARYPATH Unset? PASSED  UnSet
A00180 JAVA_HOME Unset?     PASSED  UnSet
A00190 Enter JDK Home       RECORD
A00200 JDK Version          FAILED  JDK home is missing
A00210 Other O_Hs in PATH?  FAILED  OratabEntryInPath
A00220 Other OUI Up?        PASSED  NoOtherOUI
A00230 /tmp Adequate?       PASSED  TempSpaceOK
A00240 Disk Space OK?       PASSED  DiskSpaceOK
A00250 Swap (in MB)         RECORD  5951
A00260 RAM (in MB)          PASSED  3955
A00270 Swap OK?             PASSED  SwapToRAMOK
A00280 Network              PASSED  Connected
A00290 IP Address           RECORD  192.168.1.191
A00300 Domain Name          RECORD  oracle.com
A00310 DNS Lookup           FAILED  nslookup host.domain
A00320 /etc/hosts Format    FAILED  Missing host.domain
A00330 Kernel Parameters OK PASSED  KernelOK
A00380 Tainted Kernel?      PASSED  NotVerifiable
A00400 ip_local_port_range  PASSED  RangeOK
A00480 EL4 RPMs OK?         SKIPPED NotEL4
A00490 EL5 RPMs OK?         FAILED  [kernel-headers(i386)] not installed ..>
A00530 RHEL4 RPMs OK?       SKIPPED NotRedHat
A00540 RHEL5 RPMs OK?       SKIPPED NotRedHat
A00570 SUSE SLES10 RPMs OK? SKIPPED NotSuSE
A00580 SUSE SLES11 RPMs OK? SKIPPED NotSuSE
Result file: /home/oracle/rda/output/RDA_HCVE_A200DB11R2_lnx_res.htm

 

 

上例对OS做了Oracle Database 11g R2 (11.2.0) Preinstall的预安装检查 ,并给出了检查结果。

 

 

 

还可以使用./rda.sh命令对现有的RDA软件做完整性检测,保证RDA没有被修改过:

 

 

[oracle@vrh8 rda]$ ./rda.sh -cv
Loading the file list ...
Checking the directory '.' ...
Checking the directory 'RDA' ...
Checking the directory 'RDA/Handle' ...
Checking the directory 'RDA/Library' ...
Checking the directory 'RDA/Library/Remote' ...
Checking the directory 'RDA/Local' ...
Checking the directory 'RDA/Object' ...
Checking the directory 'RDA/Operator' ...
Checking the directory 'RDA/Value' ...
Checking the directory 'hcve' ...
Checking the directory 'modules' ...
No issues found
Oracle RDA Remote Diagnostic Agent 使用

(1) 初始化参数设置的建议

(1.1) sec_case_sensitive_loacgon
在12.1.0.1中不建议修改。默认值是true,但是如果设置成false,启动的时候会有提示:ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance。但是设置成false仍然生效,即忽略大小写的密码可以登录。

(1.2) SQLNET.ALLOWED_LOGON_VERSION_SERVER
在12c中默认值是11,所以如10.2.0.5的JDBC连接过来,就会报错ora-28040,虽然可以设置SQLNET.ALLOWED_LOGON_VERSION_SERVER=8来解决这个问题,但是由于今后11.1以下版本的JDBC不再被oracle支持,因此还是建议升级JDBC驱动来实现。
jar file和JDBC驱动之间的关系,参考Doc ID 401934.1。 10.2版本的JDBC,使用ojdbc14.jar;11.2版本的JDBC,使用ojdbc6.jar;12.1.0的JDBC使用ojdbc7.jar。

SQLNET.ALLOWED_LOGON_VERSION_SERVER 的值有{ 8 | 10 | 11 | 12 | 12a },各个值如下含义:
12a for Oracle Database 12c authentication protocols (strongest protection)
12 for the critical patch updates CPUOct2012 and later Oracle Database 11g ,authentication protocols (recommended)
11 for Oracle Database 11g authentication protocols (default)
10 for Oracle Database 10g authentication protocols
8 for Oracle9i authentication protocol
默认值是11,推荐值是12(如果你没有小于10.2.0.5的客户端)

(1.3) AUDIT_TRAIL
取值范围是: { none | os | db [, extended] | xml [, extended] },默认值是db或者none。
和12c的新特性Unified Auditing有关。是否启用unified auditing,可以用select VALUE from V$OPTION where PARAMETER=’Unified Auditing’;检查。

Unified Auditing默认是工作在mixed模式。
建议:
如果你以前没有审计,那么你可以设置成none。
如果以前有审计,建议设置成db。
更多信息,参考 http://tinyurl.com/UnifiedAuditing

(1.4)DEFERRED_SEGMENT_CREATION
从11.2开始,这个值的默认值是true,建议12c中设置成false。

(1.5)JOB_QUEUE_PROCESSES
从11.1开始,这个值是1000,建议设置成和CPU core相等的值。

(1.6)_DATAFILE_WRITE_ERRORS_CRASH_INSTANCE
这个值默认值是true。所有datafile的IO写error,都会导致数据库crash。
在11.2.0.2之前这个值是false,即只是offline datafile(非system),而不crash instance。11.2.0.2之后,是true。
建议:注意这个从11.2.0.2之后的变化。

(1.7) MAX_STRING_SIZE
这是在12c中的新参数。默认值是standard。
这个参数用于控制varchar2,nvarchar2,raw类型的最大值。standard下,行为和12c之前一样,即varchar2和nvarchar2是4000 bytes,raw是2000 bytes,
改成extended之后,启用了32k strings新特性,varchar2、nvarchar2、raw最大长度可以达到32767 bytes。
修改方式:
1. startup upgrade
2. ALTER SYSTEM SET MAX_STRING_SIZE = EXTENDED;
3.运行@?/rdbms/admin/utl32k.sql
但是注意,单向修改,改了之后,就改不回来了。(可以flashback)

注意原生32k strings是以out-of-line的blob方式存储,且还是basic file,而如果是以modify成32k strings的是以in-line的方式行链接存储。
所以转32k strings需要考虑lob效率的问题。

(2)其他在12c中的参数:

(2.1) _OPTIMIZER_AGGR_GROUPBY_ELIM
Values: { TRUE | FALSE } 默认值是true
Recommendation: FALSE – Wrong Results with GROUP BY Clause in Nested Query (Doc ID 19567916.8)
建议值:false

(2.2) INMEMORY_FORCE
Values: { DEFAULT | OFF } 默认值是default
Explanation: In-Memory Optimization
Recommendation: OFF – Unless you have an Oracle In-Memory license
建议值为off,除非你有in-memory的license

(2.3) OPTIMIZER_DYNAMIC_SAMPLING
如果统计信息不存在,进行动态采样的比例。
Values: { 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 } 默认值是2
解释:
a.0: Off
b.2: Check 不多于64个blocks – generate stats during parse
c.11:12c的新增加值,进行动态采样的block数由系统自动决定,采样结果会保留在statistics repository,供下次使用。
建议值:参考在线文档SQL Tuning Guide,最佳实践是在session级设置。

(2.4) AWR Lite Snapshots
参考Doc ID 1993045.1,建议在手工snapshot的时候,用lite模式
–默认值是bestfit
_AWR_SNAPSHOT_LEVEL = BASIC | LITE | TYPICAL | ALL | BESTFIT
–手工snapshot的时候,建议lite
SQL> exec dbms_workload_repository.create_snapshot(‘LITE’);

(2.5) _OPTIMIZER_COST_BASED_TRANSFORMATION
默认值是on,从10.2开始,默认值就是on了,但是在11.2.0.3之前,建议设置off

(2.6) SESSION_CACHED_CURSORS
默认值是50,建议设置成200,然后按照208857.1进行调整。
太大容易有shared pool碎片

(2.7) _MEMORY_IMM_MODE_WITHOUT_AUTOSGA
默认值是true,如果需要禁用偷buffer cache的属性,设置成false

(2.8) OPTIMIZER_USE_PENDING_STATISTICS
默认值是false,可以在session级设置成true后,测试新的但是还没发布的统计信息,对sql的影响。

(2.9)OPTIMIZER_USE_INVISIBLE_INDEXES
是否让优化器看见invisible的索引,默认值是false
ALTER INDEX idx_ename ON emp(ename) INVISIBLE;
ALTER SESSION SET OPTIMIZER_USE_INVISIBLE_INDEXES=TRUE;

(2.10) 其他建议值:
a. _optimizer_adaptive_plans=FALSE (需要评估,Adaptive Query Optimization Doc ID 2031605.1)
b. _optimizer_unnest_scalar_sq=FALSE (Bug 19894622 – ORA-600 [kkqcsfixfro:1 — frooutj] error occur in 12c (Doc ID 19894622.8))
c. _rowsets_enabled=FALSE (Bug 22173980 : WRONG RESULTS WHEN “_ROWSETS_ENABLED” = TRUE)
d. _optimizer_reduce_groupby_key=FALSE (Bug 20634449 – Wrong results from OUTER JOIN with a bind variable and a GROUP BY clause in 12.1.0.2)
e. _kks_obsolete_dump_threshold=0 or 8(Huge Trace Files Created Containing “—– Cursor Obsoletion Dump sql_id=%s —–” (Doc ID 1955319.1) ,该参数取值范围是0~8,默认值是1。设置0表示永远不dump,设置8表示parent cursor obsoleted 8次之后才dump。)

(2)其他在12c中的参数:

(2.1) _OPTIMIZER_AGGR_GROUPBY_ELIM
Values: { TRUE | FALSE } 默认值是true
Recommendation: FALSE – Wrong Results with GROUP BY Clause in Nested Query (Doc ID 19567916.8)
建议值:false

(2.2) INMEMORY_FORCE
Values: { DEFAULT | OFF } 默认值是default
Explanation: In-Memory Optimization
Recommendation: OFF – Unless you have an Oracle In-Memory license
建议值为off,除非你有in-memory的license

(2.3) OPTIMIZER_DYNAMIC_SAMPLING
如果统计信息不存在,进行动态采样的比例。
Values: { 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 } 默认值是2
解释:
a.0: Off
b.2: Check 不多于64个blocks – generate stats during parse
c.11:12c的新增加值,进行动态采样的block数由系统自动决定,采样结果会保留在statistics repository,供下次使用。
建议值:参考在线文档SQL Tuning Guide,最佳实践是在session级设置。

(2.4) AWR Lite Snapshots
参考Doc ID 1993045.1,建议在手工snapshot的时候,用lite模式
–默认值是bestfit
_AWR_SNAPSHOT_LEVEL = BASIC | LITE | TYPICAL | ALL | BESTFIT
–手工snapshot的时候,建议lite
SQL> exec dbms_workload_repository.create_snapshot(‘LITE’);

(2.5) _OPTIMIZER_COST_BASED_TRANSFORMATION
默认值是on,从10.2开始,默认值就是on了,但是在11.2.0.3之前,建议设置off

(2.6) SESSION_CACHED_CURSORS
默认值是50,建议设置成200,然后按照208857.1进行调整。
太大容易有shared pool碎片

(2.7) _MEMORY_IMM_MODE_WITHOUT_AUTOSGA
默认值是true,如果需要禁用偷buffer cache的属性,设置成false

(2.8) OPTIMIZER_USE_PENDING_STATISTICS
默认值是false,可以在session级设置成true后,测试新的但是还没发布的统计信息,对sql的影响。

(2.9)OPTIMIZER_USE_INVISIBLE_INDEXES
是否让优化器看见invisible的索引,默认值是false
ALTER INDEX idx_ename ON emp(ename) INVISIBLE;
ALTER SESSION SET OPTIMIZER_USE_INVISIBLE_INDEXES=TRUE;

(2.10) 其他建议值:
a. _optimizer_adaptive_plans=FALSE (需要评估,Adaptive Query Optimization Doc ID 2031605.1)
b. _optimizer_unnest_scalar_sq=FALSE (Bug 19894622 – ORA-600 [kkqcsfixfro:1 — frooutj] error occur in 12c (Doc ID 19894622.8))
c. _rowsets_enabled=FALSE (Bug 22173980 : WRONG RESULTS WHEN “_ROWSETS_ENABLED” = TRUE)
d. _optimizer_reduce_groupby_key=FALSE (Bug 20634449 – Wrong results from OUTER JOIN with a bind variable and a GROUP BY clause in 12.1.0.2)
e. _kks_obsolete_dump_threshold=0 or 8(Huge Trace Files Created Containing “—– Cursor Obsoletion Dump sql_id=%s —–” (Doc ID 1955319.1) ,该参数取值范围是0~8,默认值是1。设置0表示永远不dump,设置8表示parent cursor obsoleted 8次之后才dump。)

(4) 查找补丁信息:

原来是通过dba_registry_history 查询,现在可以通过下面的方法查询:
SQL> exec dbms_qopatch.get_sqlpatch_status;

下面的语句是用来查询inventory的位置:
SQL> select xmltransform(DBMS_QOPATCH.GET_OPATCH_LSINVENTORY,DBMS_QOPATCH.GET_OPATCH_XSLT) from dual;

查询某个patch是否被安装:
SQL> select xmltransform(DBMS_QOPATCH.IS_PATCH_INSTALLED(‘19303936 ‘),DBMS_QOPATCH.GET_OPATCH_XSLT) from dual;

查询所有的patch的情况:
SQL> select xmltransform(DBMS_QOPATCH.GET_OPATCH_LIST,DBMS_QOPATCH.GET_OPATCH_XSLT) from dual;

(5)升级catalog变化:

RMAN Catalog Upgrade:
– SQL> @$ORACLE_HOME/rdbms/admin/dbmsrmansys.sql <<<<需要先运行这一步(以前没有),再运行upgrade catalog – $ rman CATALOG my_catalog_owner@catdb recovery catalog database Password: RMAN> UPGRADE CATALOG;
RMAN> UPGRADE CATALOG;
RMAN> EXIT;

(6)增量统计信息收集增强(增量统计信息收集和交换分区相结合)

–先设置使用过期比例USE_STALE_PERCENT。定义“变化”的分区不会收集新的统计信息,除非有xx%百分比的变化。
SQL> exec DBMS_STATS.SET_DATABASE_PREFS(‘INCREMENTAL_STALENESS’,’USE_STALE_PERCENT’);
–设置过期比例为12%(默认是10%)
SQL> exec DBMS_STATS.SET_DATABASE_PREFS(‘STALE_PERCENT’,’12’);

(7)统计信息情况查看:

–查看整个库的统计信息情况:
SQL> variable mystatrep2 clob;
SQL> set long 1000000
SQL> begin
2 :mystatrep2 := DBMS_STATS.REPORT_STATS_OPERATIONS(since=>SYSTIMESTAMP-
3 1,until=>SYSTIMESTAMP, detail_level=>’TYPICAL’,format=>’TEXT’);
4 end;
5 /

PL/SQL procedure successfully completed.

SQL>
SQL> set serverout on
SQL> set long 999999999
SQL> set line 10000
SQL> set pages 10000
SQL> col mystatrep2 for a200
SQL> print mystatrep2

MYSTATREP2
——————————————————————————————————————————————————————————————————–
——————————————————————————————————————————————————————————————————-
| Operation Id | Operation | Target | Start Time | End Time | Status | Total Tasks | Successful Tasks | Failed Tasks | Active Tasks |
——————————————————————————————————————————————————————————————————-
| 366 | export_stats_for_dp | TEST | 13-JUL-16 02.12.59.130000 PM +08:00 | 13-JUL-16 02.12.59.203000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 365 | export_stats_for_dp | TEST | 13-JUL-16 02.08.18.857000 PM +08:00 | 13-JUL-16 02.08.18.880000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 364 | export_stats_for_dp | TEST | 13-JUL-16 02.04.13.425000 PM +08:00 | 13-JUL-16 02.04.13.480000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 363 | export_stats_for_dp | TEST | 13-JUL-16 01.57.50.812000 PM +08:00 | 13-JUL-16 01.57.50.846000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 362 | export_stats_for_dp | TEST | 13-JUL-16 01.56.34.637000 PM +08:00 | 13-JUL-16 01.56.34.667000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 361 | import_stats_for_dp | TEST | 13-JUL-16 01.55.50.018000 PM +08:00 | 13-JUL-16 01.55.50.294000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 360 | export_stats_for_dp | TEST | 13-JUL-16 01.53.54.840000 PM +08:00 | 13-JUL-16 01.53.54.879000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 359 | import_stats_for_dp | TEST | 13-JUL-16 01.52.17.822000 PM +08:00 | 13-JUL-16 01.52.18.059000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 358 | import_stats_for_dp | TEST | 13-JUL-16 01.46.44.289000 PM +08:00 | 13-JUL-16 01.46.44.611000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 357 | export_stats_for_dp | TEST | 13-JUL-16 01.43.12.810000 PM +08:00 | 13-JUL-16 01.43.13.543000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 356 | import_stats_for_dp | TEST | 13-JUL-16 01.40.03.349000 PM +08:00 | 13-JUL-16 01.40.03.650000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 355 | import_stats_for_dp | TEST | 13-JUL-16 01.37.36.601000 PM +08:00 | 13-JUL-16 01.37.36.843000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 354 | import_stats_for_dp | TEST | 13-JUL-16 01.36.32.072000 PM +08:00 | 13-JUL-16 01.36.32.321000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 353 | import_stats_for_dp | TEST | 13-JUL-16 01.34.56.514000 PM +08:00 | 13-JUL-16 01.34.56.790000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 352 | import_stats_for_dp | TEST | 13-JUL-16 12.01.25.756000 PM +08:00 | 13-JUL-16 12.01.26.022000 PM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 351 | import_stats_for_dp | TEST | 13-JUL-16 11.45.08.131000 AM +08:00 | 13-JUL-16 11.45.08.703000 AM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-
| 350 | export_stats_for_dp | TEST | 13-JUL-16 11.42.21.767000 AM +08:00 | 13-JUL-16 11.42.24.557000 AM +08:00 | COMPLETED | 0 | 0 | 0 | 0 |
——————————————————————————————————————————————————————————————————-

SQL>
–查看某个schema的统计信息收集情况:
SQL> set serverout on
SQL> set long 999999999
SQL> set line 10000
SQL> set pages 10000
SQL> col my_report for a200
SQL> variable my_report clob;
SQL> BEGIN
2 :my_report := DBMS_STATS.REPORT_GATHER_SCHEMA_STATS(ownname => ‘TEST’,
3 detail_level => ‘TYPICAL’, format => ‘TEXT’);
4 END;
5 /

PL/SQL procedure successfully completed.

SQL>
SQL> print my_report

MY_REPORT
——————————————————————————————————————————————————————————————————–
——————————————————————————————————————————————————————————————————-
| Operation Id | Operation | Target | Start Time | End Time | Status | Total Tasks | Successful Tasks | Failed Tasks | Active Tasks |
——————————————————————————————————————————————————————————————————-
| 368 | gather_schema_stats (reporting mode) | TEST | | | | 1 | | | |
——————————————————————————————————————————————————————————————————-
——————————————————————————————————————————————————————————————————-
| |
| ————————————————————————————————————————————————————————————————— |
| T A S K S |
| ————————————————————————————————————————————————————————————————— |
| ——————————————————————————————————————————————————————————————— |
| | Target | Type | Start Time | End Time | Status | |
| ——————————————————————————————————————————————————————————————— |
| | TEST.T1 | TABLE | | | | |
| ——————————————————————————————————————————————————————————————— |
| |
| |
——————————————————————————————————————————————————————————————————-

(8)DBMS_ROLLING

Data Guard Simple Rolling Upgrade
Semi-automation of Transient Logical Standby Rolling Upgrade
Works with Data Guard Broker
Procedure DBMS_ROLLING

(9) Real-Time ADDM:

– MMON进程负责收集数据, 每隔3秒一次,不会有lock/latch
– MMON的子进程创建report,并保留在AWR中,可以通过查询 DBA_HIST_REPORTS

参考 Mike Dietrich Upgrade, Migrate & Consolidate to Oracle Database 12c/ oracleblog

升级到12c/18c以后的版本需要了解的一些方面参数(参考Upgrade, Migrate & Consolidate to Oracle Database 12c)

跟踪oracle 进程链接建立时候发生的情况

 

本方法主要使用触发器的方式对新建立的进程自动进行10046的trace并进行分析的方式,期间使用到truss,需要掌握truss的使用方法,具体如下:

 

创建用户

create user trace_user identified by trace_user account unlock;
grant create session,dba to trace_user;

创建登陆触发器

create or replace trigger sys.set_trace
after logon on database
when (user = 'trace_user')
declare
lcommand varchar(200);
begin
execute immediate 'alter session set statistics_level=all';
execute immediate 'alter session set max_dump_file_size=unlimited';
execute immediate 'alter session set events ''10046 trace name context forever, level 12''';
end set_trace;
/

 

尝试登陆

sqlplus "trace_user/trace_user" << eof
exit;
eof

这将在$ ORACLE_BASE / admin / <db_name> / udump目录下生成(10046)跟踪文件

然后通过查看“e =”部分查看数据库调用(PARSE,BIND,EXEC,FETCH)是否有大量时间,这意味着数据库调用所消耗的持续时间

通过查看“ela =”部分检查等待事件是否有大量时间,这意味着等待事件消耗的持续时间(可能通过进行系统调用)

PARSING IN CURSOR #5 len=131 dep=1 uid=0 oct=3 lid=0 tim=15687899202263 hv=1389591971 ad='ca9a7948'
select privilege#,nvl(col#,0),max(mod(nvl(option$,0),2))from objauth$ where obj#=:1 and grantee#=:2 group by privilege#,nvl(col#,0)
END OF STMT
EXEC #5:c=0,e=145,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=15687899202260
WAIT #5: nam='db file sequential read' ela= 30005 file#=1 block#=24208 blocks=1 obj#=-1 tim=15687899232346
FETCH #5:c=0,e=30075,p=1,cr=2,cu=0,mis=0,r=0,dep=1,og=4,tim=15687899232396

没有数据库调用占用大量时间

less oracle_ora_1118270.trc | grep -i ",e=" | cut -d , -f2 > karlarao.txt ; sed -n 's/e=/ /p' karlarao.txt | sort -nr | less

 358746
 183162
 61293
 44661
 32580
 30075
 28695
 26950
 25837
 24244
 ...

没有等待事件耗费大量时间

less oracle_ora_1118270.trc | grep -i "ela=" | cut -d " " -f8 | sort -nr | less

30005
28624
13253
11592
9650

没有 “os thread startup”事件!

less oracle_ora_1118270.trc | grep -i "ela=" | cut -d "=" -f2 | uniq

'SQL*Net message to client' ela
'SQL*Net message from client' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'db file sequential read' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'db file sequential read' ela
'SQL*Net message to client' ela
'db file sequential read' ela
'SQL*Net message from client' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'db file sequential read' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela
'SQL*Net message to client' ela
'SQL*Net message from client' ela

下来对系统调用进行检测,这里使用truss工具

这个工具可以让你做一些应用程序跟踪,这里是跟踪SQL * Plus,并显示应用程序对外部库和内核的调用

truss -c sqlplus "/ as sysdba" << EOF
exit;
EOF

truss -d sqlplus "/ as sysdba" << EOF
exit;
EOF

 

“-c”开关计算跟踪的系统调用,故障和信号

“-d”开关显示每行的时间戳(以秒为单位)。跟踪输出的第一行将显示测量各个时间戳的基准时间

这里下面可以发现是DNS服务导致sqlplus“/ as sysdba”操作减慢,并且有“os线程启动”等待,下面的文本是“truss”输出的部分,当在/etc/resolv.conf和/ etc / hosts上读取时,“(sleep……)”事件表示减速。

ENOTTY和ECONNREFUSED是看到的错误,这里此文件/usr/include/sys/errno.h上找到有关错误消息的更多详细信息。以下是它们的解释

 

#define	ENOTTY	25	/* Inappropriate I/O control operation	*/
#define ECONNREFUSED    79      /* Connection refused */

 

根据“truss -d”的记录,可以看到时间信息从2.3379秒(读取/etc/resolv.conf) – > 7.3477秒 – > 17.3489秒 – > 37.3555秒(读数) / etc / hosts) – > 70.3863秒(已连接)

0.3172:        gethostname(0x0FFFFFFFFFFF9920, 256) = 0
0.3175:        _getpid()                        = 1102056
0.3177:        open("/etc/resolv.conf", O_RDONLY) = 8
0.3180:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
0.3182:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
kread(8, " d o m a i n     this is the domain name, i removed it".., 4096)    = 69
kread(8, " d o m a i n     this is the domain name, i removed it".., 4096)    = 0
0.3190:        close(8)                         = 0
0.3194:        socket(2, 2, 0)                  = 8
0.3197:        getsockopt(8, 65535, 4104, 0x0FFFFFFFFFFF70E4, 0x0FFFFFFFFFFF70E0) = 0
0.3199:        connext(8, 0x09001000A0018600, 16) = 0
0.3202:        send(8, 0x0FFFFFFFFFFF7FF0, 41, 0) = 41
0.3205:        _poll(0x0FFFFFFFFFFF7190, 1, 5000) = 1
0.3208:        nrecvfrom(8, 0x0FFFFFFFFFFF9320, 1024, 0, 0x0FFFFFFFFFFF7950, 0x0FFFFFFFFFFF7178) Err#79 ECONNREFUSED
0.3210:        close(8)                         = 0
0.3212:        socket(2, 2, 0)                  = 8
0.3215:        sendto(8, 0x0FFFFFFFFFFF7FF0, 41, 0, 0x09001000A0018610, 16) = 41
0.3217:        _poll(0x0FFFFFFFFFFF7190, 1, 5000) = 1
0.3220:        nrecvfrom(8, 0x0FFFFFFFFFFF9320, 1024, 0, 0x0FFFFFFFFFFF7950, 0x0FFFFFFFFFFF7178) = 108
0.3222:        close(8)                         = 0
0.3224:        socket(2, 2, 0)                  = 8
0.3227:        getsockopt(8, 65535, 4104, 0x0FFFFFFFFFFF70E4, 0x0FFFFFFFFFFF70E0) = 0
0.3229:        connext(8, 0x09001000A0018600, 16) = 0
0.3231:        send(8, 0x0FFFFFFFFFFF7FF0, 28, 0) = 28
0.3233:        _poll(0x0FFFFFFFFFFF7190, 1, 5000) = 1
0.3236:        nrecvfrom(8, 0x0FFFFFFFFFFF9320, 1024, 0, 0x0FFFFFFFFFFF7950, 0x0FFFFFFFFFFF7178) Err#79 ECONNREFUSED
0.3238:        close(8)                         = 0
0.3240:        socket(2, 2, 0)                  = 8
0.3243:        sendto(8, 0x0FFFFFFFFFFF7FF0, 28, 0, 0x09001000A0018610, 16) = 28
0.3245:        _poll(0x0FFFFFFFFFFF7190, 1, 5000) = 1
0.3248:        nrecvfrom(8, 0x0FFFFFFFFFFF9320, 1024, 0, 0x0FFFFFFFFFFF7950, 0x0FFFFFFFFFFF7178) = 28
0.3250:        close(8)                         = 0
0.3252:        socket(2, 2, 0)                  = 8
0.3373:        sendto(8, 0x0FFFFFFFFFFF7FF0, 28, 0, 0x09001000A0018600, 16) = 28
2.3379:        _poll(0x0FFFFFFFFFFF7190, 1, 5000) (sleeping...)
2.3379:        _poll(0x0FFFFFFFFFFF7190, 1, 5000) = 0
5.3468:        close(8)                         = 0
5.3470:        socket(2, 2, 0)                  = 8
5.3472:        sendto(8, 0x0FFFFFFFFFFF7FF0, 28, 0, 0x09001000A0018600, 16) = 28
7.3477:        _poll(0x0FFFFFFFFFFF7190, 1, 10000) (sleeping...)
7.3477:        _poll(0x0FFFFFFFFFFF7190, 1, 10000) = 0
15.3479:        close(8)                        = 0
15.3482:        socket(2, 2, 0)                 = 8
15.3484:        sendto(8, 0x0FFFFFFFFFFF7FF0, 28, 0, 0x09001000A0018600, 16) = 28
17.3489:        _poll(0x0FFFFFFFFFFF7190, 1, 20000) (sleeping...)
17.3489:        _poll(0x0FFFFFFFFFFF7190, 1, 20000) = 0
35.3491:        close(8)                        = 0
35.3495:        getdomainname(0x0FFFFFFFFFFF9480, 256) = 0
35.3497:        open("/etc/hosts", O_RDONLY)    = 8
35.3500:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
35.3502:        kfcntl(8, F_SETFD, 0x0000000000000001) = 0
35.3505:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
kread(8, " #   @ ( # ) 4 7\t 1 . 1".., 4096)    = 3453
kread(8, " #   @ ( # ) 4 7\t 1 . 1".., 4096)    = 0
35.3514:        close(8)                        = 0
kwrite(9, "01 �0603 s".., 432)    = 432
37.3555:        kread(10, "16060280".., 2064) (sleeping...)
kread(10, "06 E06\b".., 2064)   = 1605
70.3762:        open("/oracle/app/product/10.2/db_1/rdbms/mesg/oraus.msb", O_RDONLY) = 8
70.3764:        kfcntl(8, F_SETFD, 0x0000000000000001) = 0
70.3767:        lseek(8, 0, 0)                  = 0
kread(8, "1513 "011303\t\t".., 256)     = 256
70.3772:        lseek(8, 512, 0)                = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
70.3776:        lseek(8, 1024, 0)               = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
70.3781:        lseek(8, 50688, 0)              = 50688
kread(8, "\f05 ] P05 ^".., 512)     = 512
70.3786:        lseek(8, 512, 0)                = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
70.3790:        lseek(8, 1024, 0)               = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
70.3795:        lseek(8, 50688, 0)              = 50688
kread(8, "\f05 ] P05 ^".., 512)     = 512
70.3799:        lseek(8, 512, 0)                = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
70.3804:        lseek(8, 1024, 0)               = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
70.3808:        lseek(8, 50688, 0)              = 50688
kread(8, "\f05 ] P05 ^".., 512)     = 512
70.3813:        lseek(8, 512, 0)                = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
70.3817:        lseek(8, 1024, 0)               = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
70.3822:        lseek(8, 51712, 0)              = 51712
kread(8, "\n0589 D058A".., 512)     = 512
70.3827:        close(8)                        = 0
kwrite(9, " <0611 k".., 60)     = 60
kread(10, " �06\b".., 2064)   = 179
kwrite(9, " U0603 h".., 85)     = 85
kread(10, "1606\b".., 2064)   = 22
kwrite(9, " U0603 h".., 85)     = 85
kread(10, "1606\b".., 2064)   = 22
70.3854:        lseek(4, 512, 0)                = 512
kread(4, "17 �".., 512)     = 512
70.3858:        lseek(4, 1024, 0)               = 1024
kread(4, "16 * R h819E".., 512)     = 512
70.3863:        lseek(4, 4096, 0)               = 4096
kread(4, "\f82 P86".., 512)     = 512

kwrite(1, "\n", 1)                              = 1
Connected to:
kwrite(1, " C o n n e c t e d   t o".., 14)     = 14
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
kwrite(1, " O r a c l e   D a t a b".., 77)     = 77
With the Partitioning, OLAP, Data Mining and Real Application Testing options
kwrite(1, " W i t h   t h e   P a r".., 78)     = 78

kwrite(1, "\n", 1)                              = 1
70.3882:        kfcntl(1, F_GETFL, 0x0000000000000008) = 2
70.3886:        __libc_sbrk(0x0000000000030020) = 0x000000001023C880
70.3892:        access("login.sql", 0)          Err#2  ENOENT
70.3895:        access("/oracle/app/product/10.2/db_1/sqlplus/admin/glogin.sql", 0) = 0
70.3898:        statfs("/oracle/app/product/10.2/db_1/sqlplus/admin/glogin.sql", 0x0FFFFFFFFFFFDA10) = 0

 

事实证明确实是dns出现了问题,在调整后迅速恢复了响应时间

3.0713:        gethostname(0x0FFFFFFFFFFF9900, 256) = 0
3.0716:        _getpid()                        = 2539762
3.0719:        open("/etc/resolv.conf", O_RDONLY) = 8
3.0721:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
3.0724:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
kread(8, " d o m a i n     this is the domain name, i removed it".., 4096)    = 70
kread(8, " d o m a i n     this is the domain name, i removed it".., 4096)    = 0
3.0731:        close(8)                         = 0
3.0735:        socket(2, 2, 0)                  = 8
3.0740:        getsockopt(8, 65535, 4104, 0x0FFFFFFFFFFF70C4, 0x0FFFFFFFFFFF70C0) = 0
3.0742:        connext(8, 0x09001000A0018600, 16) = 0
3.0746:        send(8, 0x0FFFFFFFFFFF7FD0, 41, 0) = 41
3.0750:        _poll(0x0FFFFFFFFFFF7170, 1, 5000) = 1
3.0753:        nrecvfrom(8, 0x0FFFFFFFFFFF9300, 1024, 0, 0x0FFFFFFFFFFF7930, 0x0FFFFFFFFFFF7158) = 108
3.0756:        send(8, 0x0FFFFFFFFFFF7FD0, 28, 0) = 28
3.0758:        _poll(0x0FFFFFFFFFFF7170, 1, 5000) = 1
3.0761:        nrecvfrom(8, 0x0FFFFFFFFFFF9300, 1024, 0, 0x0FFFFFFFFFFF7930, 0x0FFFFFFFFFFF7158) = 28
3.0764:        close(8)                         = 0
3.0767:        getdomainname(0x0FFFFFFFFFFF9460, 256) = 0
3.0769:        open("/etc/hosts", O_RDONLY)     = 8
3.0771:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
3.0774:        kfcntl(8, F_SETFD, 0x0000000000000001) = 0
3.0777:        kioctl(8, 22528, 0x0000000000000000, 0x0000000000000000) Err#25 ENOTTY
kread(8, " #   @ ( # ) 4 7\t 1 . 1".., 4096)    = 3453
kread(8, " #   @ ( # ) 4 7\t 1 . 1".., 4096)    = 0
3.0786:        close(8)                         = 0
kwrite(9, "01 �0603 s".., 432)    = 432
kread(10, "06 H06\b".., 2064)   = 1608
3.0973:        open("/oracle/app/product/10.2/db_1/rdbms/mesg/oraus.msb", O_RDONLY) = 8
3.0975:        kfcntl(8, F_SETFD, 0x0000000000000001) = 0
3.0978:        lseek(8, 0, 0)                   = 0
kread(8, "1513 "011303\t\t".., 256)     = 256
3.0983:        lseek(8, 512, 0)                 = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
3.0988:        lseek(8, 1024, 0)                = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
3.0993:        lseek(8, 50688, 0)               = 50688
kread(8, "\f05 ] P05 ^".., 512)     = 512
3.0997:        lseek(8, 512, 0)                 = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
3.1002:        lseek(8, 1024, 0)                = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
3.1006:        lseek(8, 50688, 0)               = 50688
kread(8, "\f05 ] P05 ^".., 512)     = 512
3.1011:        lseek(8, 512, 0)                 = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
3.1015:        lseek(8, 1024, 0)                = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
3.1021:        lseek(8, 50688, 0)               = 50688
kread(8, "\f05 ] P05 ^".., 512)     = 512
3.1025:        lseek(8, 512, 0)                 = 512
kread(8, "1A Q 5 C [ V u �85 �9480".., 512)     = 512
3.1029:        lseek(8, 1024, 0)                = 1024
kread(8, "18 $ 4 = G S".., 512)     = 512
3.1034:        lseek(8, 51712, 0)               = 51712
kread(8, "\n0589 D058A".., 512)     = 512
3.1038:        close(8)                         = 0
kwrite(9, " <0611 k".., 60)     = 60
kread(10, " �06\b".., 2064)   = 179
kwrite(9, " U0603 h".., 85)     = 85
kread(10, "1606\b".., 2064)   = 22
kwrite(9, " U0603 h".., 85)     = 85
kread(10, "1606\b".., 2064)   = 22
3.1064:        lseek(4, 512, 0)                 = 512
kread(4, "17 �".., 512)     = 512
3.1069:        lseek(4, 1024, 0)                = 1024
kread(4, "16 * R h819E".., 512)     = 512
3.1073:        lseek(4, 4096, 0)                = 4096
kread(4, "\f82 P86".., 512)     = 512

kwrite(1, "\n", 1)                              = 1
Connected to:
kwrite(1, " C o n n e c t e d   t o".., 14)     = 14
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
kwrite(1, " O r a c l e   D a t a b".., 77)     = 77
With the Partitioning, OLAP, Data Mining and Real Application Testing options
kwrite(1, " W i t h   t h e   P a r".., 78)     = 78

kwrite(1, "\n", 1)                              = 1
3.1095:        kfcntl(1, F_GETFL, 0x0000000000000008) = 2
3.1099:        __libc_sbrk(0x0000000000030020)  = 0x000000001023C880
3.1105:        access("login.sql", 0)           Err#2  ENOENT
3.1109:        access("/oracle/app/product/10.2/db_1/sqlplus/admin/glogin.sql", 0) = 0
3.1112:        statfs("/oracle/app/product/10.2/db_1/sqlplus/admin/glogin.sql", 0x0FFFFFFFFFFFD9F0) = 0
跟踪oracle 进程链接建立时候发生的情况

从坏块中恢复未损坏的数据

前面介绍通过skip坏块(event或者dbms包)和构造rowid的方式,以及通过salvage脚本从存在坏块的表中恢复数据,同时也可以通过mdata恢复工具来unload出表中的数据,这里补充一个场景,就是坏块中未损坏的数据的恢复。

从已经损坏的块中尽可能的恢复数据的思路依旧参考的是通过rowid的方式来实现恢复,这里讨论oracle 8i以及8i以上版本的数据库.

 

rowid基本结构这里不做详细解释,前面有介绍过,这下面是官方的介绍。

       OOOOOO = is a base 64 encoding of the 32-bit dataobj# (Data object
                number was introduced in 8.0 to track versions of the same
                segment because certain operations can change the version.
                It is used to discover stale ROWIDs and stale undo records)
          FFF = is a base 64 encoding of the relative file number
       BBBBBB = is a base 64 encoding of the block number
          SSS = is a base 64 encoding of the slot (row) number

   Note that the ROWID contains the relative file number which is distinct from
   the absolute file number and new for Oracle8.  A relative file number is
   relative to the tablespace (meaning a tablespace can have a first, second,
   third file, etc.) and an absolute file number is absolute in the whole
   system.  Two different files may have the same relative number.

   例如 "SELECT ACCT_NO, ROWID from EXAMPLE;" 获得的如下结果:

   ACCT_NO    ROWID
   ---------- ------------------
        12345 AAAAh3AAGAAACJAAAA
        19283 AAAAh3AAGAAACJAAAB
        22345 AAAAh4AAFAAAAADAAA
        60372 AAAAh4AAFAAAAADAAB

     dbms_rowid构造rowid的函数:

              ROWID_CREATE(rowid_type    IN number,
                           object_number IN number,
                           relative_fno  IN number,
                           block_number  IN number,
                           row_number    IN number)
              return ROWID;

     -- rowid_type      - type (restricted=0/extended=1)
     -- object_number   - data object number
     -- relative_fno    - relative file number
     -- block_number    - block number in this file
     -- row_number      - row number in this block



    使用高低位的rowid来跳过坏块使用基于rowid的方式扫描出相关rows,这和上篇介绍的构造的rowid方式是一样的。

     The "LOW_RID" is the lowest rowid INSIDE the corrupt block:

       SELECT dbms_rowid.rowid_create(1,<DATA_OBJECT_ID>,<RFN>,<BL>,0) LOW_RID
	 from DUAL;

     The "HI_RID" is the first rowid AFTER the corrupt block:

       SELECT dbms_rowid.rowid_create(1,<DATA_OBJECT_ID>,<RFN>,<BL>+1,0) HI_RID
	 from DUAL;


	CREATE TABLE salvage_table AS
	 SELECT /*+ ROWID(A) */ * FROM <owner.tablename> A
	  WHERE rowid < '<low_rid>'
	;

	INSERT INTO salvage_table 
	 SELECT /*+ ROWID(A) */ * FROM <owner.tablename> A
	  WHERE rowid >= '<hi_rid>'
	;

    如果是分区表,则通过针对存在坏块的分区的方式即可

	CREATE TABLE salvage_table AS
	 SELECT /*+ ROWID(A) */ * 
	   FROM <owner.tablename> PARTITION (<partition_name>) A
	  WHERE rowid < '<lo_rid>'
	;

	INSERT INTO salvage_table 
	 SELECT /*+ ROWID(A) */ * 
	   FROM <owner.tablename> PARTITION (<partition_name>) A
	  WHERE rowid >= '<hi_rid>'
	;

   如果表中带有long字段需要使用exp/imp的方式来进行相关数据的导入导出,同时要带有where条件来帅选出rowid的范围。
   剩下就是要讨论的从损坏的块中恢复数据,当然如果坏块是段头那么就没必要从段头中恢复rows,可以通过如下的sql判断损坏的块是否表段头。
 
   select file_id,block_id,blocks,extent_id 
   from dba_extents 
   where owner='<owner>' 
     and segment_name='<table_name>' 
     and segment_type='TABLE'
   order by extent_id;

     FILE_ID  BLOCK_ID    BLOCKS EXTENT_ID
   --------- --------- --------- ---------
           8     94854     20780         0 <- EXTENT_ID 为0则代表坏块为段头


  Finding out about data in the Corrupt Block
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  构造rowid的方式根据块号可以构造出坏块里面row地址,前面有说明,如果表中存在索引,则可以尝试通过索引来判断坏块中row的信息,可以结合上面提到的坏块上下块的高低位rowid来扫描出坏块里的rows信息,具体如下:
 
  如果索引所在字段要求为非空,则可以通过以下sql的索引快速全扫描来实现坏块rowid的获取: 
	SELECT /*+ INDEX_FFS(X <index_name>) */ 
		<index_column1>, <index_column2> ...
	  FROM <tablename> X
	 WHERE rowid >= '<low_rid>'
	   AND rowid <  '<hi_rid>'
	;

如果索引所在的列允许null,则无法使用索引快速全扫描并且必须使用范围扫描。这需要知道确保领先索引列的最小可能值,具体sql如下:

	SELECT /*+ INDEX(X <index_name>) */ 
		<index_column1>, <index_column2> ...
	  FROM <tablename> X
	 WHERE rowid >= '<low_rid>'
	   AND rowid <  '<hi_rid>'
	   AND <index_column1> >= <min_col1_value>
	;

 

8i以上版本的恢复案例:

SQL> select * from scott.partitionexample;

	ORA-01578: ORACLE data block corrupted (file # 7, block # 12698)
	ORA-01110: data file 7: '/oracle1/oradata/V816/oradata/V816/users01.dbf'

    >>  <RFN> = 7 , <BL> = 12698 , <AFN> = 7

	SQL> SELECT tablespace_name, segment_type, owner, segment_name
               FROM dba_extents
              WHERE file_id =7
		AND 12698 between block_id AND block_id + blocks - 1 ;

        TABLESPACE_NAME  SEGMENT_TYPE       OWNER   SEGMENT_NAME
        ---------------  ------------       -----   ------------
        USERS            TABLE PARTITION    SCOTT   PARTITIONEXAMPLE

        SQL> SELECT partition_name FROM dba_extents
              WHERE file_id =7
	        AND 12698 between block_id AND block _id + blocks - 1;

	PARTITION_NAME
	------------------------------
	PARTEX2

        SQL> SELECT data_object_id
	       FROM dba_objects
	      WHERE object_name = 'PARTITIONEXAMPLE'  and owner='SCOTT'
	        AND subobject_name= 'PARTEX2';

	DATA_OBJECT_ID
 	---------------
     	88145
       
        找出高低位的rowid并扫描相关数据

	SQL> select dbms_rowid.rowid_create(1, 88145,7,12698,0) from dual;

	DBMS_ROWID.ROWID_C
	------------------
	AAAVhRAAHAAADGaAAA

	SQL>  select dbms_rowid.rowid_create(1, 88145,7,12699,0) from dual;

	DBMS_ROWID.ROWID_C
	------------------
	AAAVhRAAHAAADGbAAA

	SQL> SELECT /*+ ROWID(A) */ * 
	       FROM scott.partitionexample A
     	      WHERE rowid < 'AAAVhRAAHAAADGaAAA';

	COLUMN1    COLUMN2
	---------- ----------
	        15 a
	       ...

	SQL> SELECT /*+ INDEX_FFS(A PARTEXAM) */  column1
	       FROM  scott.partitionexample A
	      WHERE  rowid >= 'AAAVhRAAHAAADGaAAA'
		AND  rowid <  'AAAVhRAAHAAADGbAAA' ;
	
	COLUMN1
	----------
	        25
	...