6_Oracle_Admin_Oracle的诊断文件(根据alert.log创建pfile、调整sql_trace)_Oracle Admin

 

后台的server(数据库,tomcatserver),通常通过文本来记录日志,对于Oracle这样重量级的数据库,日志文件非常详细,当出现了故障需要排查时,就可以分析查看日志文件。Diagnosticfiles的作用就在于此。

6_Oracle_Admin_Oracle的诊断文件(根据alert.log创建pfile、调整sql_trace)_Oracle Admin_02

日志文件分为两类:

1. Alter file

6_Oracle_Admin_Oracle的诊断文件(根据alert.log创建pfile、调整sql_trace)_ LOG_03

 

Trace File (每个进程一个,在该进程生命周期内创建)不同,AlertFile 只有一个,它随着时间的推移体积逐渐增大,它存放的地址可以通过BACKGROUND_DUMP_DESTUSER_DUMP_DEST来确定。它记录了数据库运行中的各种动作和启动参数,因此可以通过复制alertfile中的参数来构建一个pfile

 

 

/*==================演示构建pfile的过程====================*/

 

SQL> showparameter dump

 

NAME                                 TYPE        VALUE

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

background_core_dump                 string      partial

background_dump_dest                 string      /oracle/diag/rdbms/orcl/orcl/trace

core_dump_dest                       string      /oracle/diag/rdbms/orcl/orcl/cdump

max_dump_file_size                   string      unlimited

shadow_core_dump                     string      partial

user_dump_dest                       string      /oracle/diag/rdbms/orcl/orcl/trace

 

 

[oracle@localhost ~]$ cd /oracle/diag/rdbms/orcl/orcl/trace

[oracle@localhost trace]$ ls

alert_orcl.log      orcl_j002_2553.trc  orcl_ora_1708.trc
# alert file
cdmp_20140903174944 orcl_j002_2553.trm  orcl_ora_1708.trm
orcl_cjq0_1743.trc  orcl_j002_27675.trc orcl_ora_1709.trc
orcl_cjq0_1743.trm  orcl_j002_27675.trm orcl_ora_1709.trm
orcl_cjq0_1833.trc  orcl_j002_8505.trc  orcl_ora_1727.trc

 

 

[oracle@localhost trace]$ vim alert_orcl.log

 
Tue Aug 05 18:25:23 2014
Starting ORACLE instance (normal)
...
  control_files            = "/oracle/oradata/orcl/control01.ctl"
  control_files            ="/oracle/flash_recovery_area/orcl/control02.ctl"
  db_block_size            = 8192
  compatible               = "11.2.0.0.0"
 db_recovery_file_dest    ="/oracle/flash_recovery_area"

 

=======alter_orcl.log中的参数复制到一个新文件mickey_orcl.ora=========

 

[oracle@localhost ~]$ cd /oracle/11g/dbs

 

[oracle@localhost dbs]$ vim mickey_orcl.ora

  processes                = 150
  memory_target            = 404M
  control_files            ="/oracle/oradata/orcl/control01.ctl"
  control_files            ="/oracle/flash_recovery_area/orcl/control02.ctl"
  db_block_size            = 8192
  compatible               = "11.2.0.0.0"
 db_recovery_file_dest    ="/oracle/flash_recovery_area"
 db_recovery_file_dest_size= 3852M
  undo_tablespace          = "UNDOTBS1"
 remote_login_passwordfile= "EXCLUSIVE"
  db_domain                = ""
  dispatchers              = "(PROTOCOL=TCP)(SERVICE=orclXDB)"
  audit_file_dest          ="/oracle/admin/orcl/adump"
  audit_trail              = "DB"
  db_name                  = "orcl"
  open_cursors             = 300
  diagnostic_dest          = "/oracle"

 

==========Shut Down数据库,然后用mickey_orcl.ora作为PFILE来启动数据库======

 

SQL> shutdownimmediate

Database closed.
Database dismounted.
ORACLE instance shut down.
--关闭数据库

 

SQL> startuppfile=$ORACLE_HOME/dbs/mickey_orcl.ora

ORACLE instance started.
 
Total System Global Area 422670336 bytes
Fixed Size                 1336960 bytes
Variable Size            260049280 bytes
Database Buffers         155189248 bytes
Redo Buffers               6094848 bytes
Database mounted.
Database opened.
-- 能够用通过alert_orcl.log创建的pfile来正常启动数据库


 

2.Trace file

a)        Backgroun Trace Files

6_Oracle_Admin_Oracle的诊断文件(根据alert.log创建pfile、调整sql_trace)_ LOG_04

b)       User Trace Files

 

6_Oracle_Admin_Oracle的诊断文件(根据alert.log创建pfile、调整sql_trace)_Oracle Admin_05

 

Background Trace File记录的是数据库本身的信息,而UserTrace File记录的则是单个用户操作数据库时发生的事。它不止记录用户会话中发生的错误,也可以主动记录所有操作:

 

6_Oracle_Admin_Oracle的诊断文件(根据alert.log创建pfile、调整sql_trace)_ LOG_06

1.sessionlevel上使用alter命令来记录

2.Instancelevel上设置启动参数,但是不建议这样做,因为数据库连接的用户数量可能是巨大的,每个操作都记录会加重数据库的负担。

 

/*========演示使用alter方式更改sesssion level trace file的记录状况========*/

 

[oracle@localhost dbs]$ ps -ef | grep oracle

oracle   11437     1  001:37 ?        00:00:02/oracle/11g/bin/tnslsnr LISTENER -inherit
root     14314  1372  005:57 ?        00:00:00 sshd: oracle[priv]
oracle   1433214314  0 05:57 ?        00:00:00 sshd: oracle@pts/0
oracle   1436514364  0 05:57 pts/1    00:00:00 -bash
oracle   1492214333  0 06:59 pts/0    00:00:00 sqlplus      
oracle   15498     1  007:46 ?        00:00:00 ora_pmon_orcl
...
oracle   15559 14922 0 07:46 ?        00:00:00oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
# 当前登陆的用户
oracle   1558714365  2 07:47 pts/1    00:00:00 ps -ef
oracle   1558814365  0 07:47 pts/1    00:00:00 grep oracle
# 启动数据库中当前的进程


 

==========再开启一个终端以system用户登陆数据库============

[oracle@localhost ~]$ sqlplus /nolog

 
SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 9 07:49:452014
 
Copyright (c) 1982, 2009, Oracle.  All rights reserved.

 

SQL> conn system

Enter password:
Connected.

 

=======再次查看进程========

 

[oracle@localhost dbs]$ ps -ef | grep oracle

oracle   11437     1  001:37 ?        00:00:02/oracle/11g/bin/tnslsnr LISTENER -inherit
...
oracle   15498     1  007:46 ?        00:00:00 ora_pmon_orcl
oracle   15532     1  007:46 ?        00:00:00 ora_s000_orcl
oracle   1555914922  0 07:46 ?        00:00:00 oracleorcl(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
# 原来登陆的用户
oracle   15561     1  007:46 ?        00:00:00 ora_qmnc_orcl
...
oracle   1560515604  0 07:49 pts/2    00:00:00 -bash
oracle   1563115605  0 07:49 pts/2    00:00:00 sqlplus      
oracle   15805 15803  0 08:08 ?        00:00:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
# 新增的登录用户
oracle   15648     1  007:51 ?        00:00:00 ora_smco_orcl
oracle   1565614365  4 07:52 pts/1    00:00:00 ps -ef
oracle   1565714365  0 07:52 pts/1    00:00:00 grep oracle

 

===========SYS查看当前的sql_trace=============

SQL> showparameter sql_trace

 
NAME                                 TYPE        VALUE
------------------------------------ ----------------------------------
sql_trace                            boolean     FALSE
-- false 说明不记录


 

=========system用户更改sql_trace的参数=============

 

SQL> altersession set sql_trace = true;

Session altered.

 

SQL> showparameter sql_trace;

 

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
sql_trace                            boolean     TRUE

 

========system用户执行一条sql语句=============

 

SQL> select *from dual;

 
D
-
X

 

=========查看进程号为15805trace file ======

 

[oracle@localhost dbs]$ cd /oracle/diag/rdbms/orcl/orcl/trace

[oracle@localhost trace]$ ls

...
orcl_ora_15293.trc orcl_ora_15405.trm  orcl_ora_15805.trc
orcl_ora_15293.trm orcl_ora_15451.trc orcl_ora_15805.trm
orcl_ora_15395.trc orcl_ora_15451.trm orcl_ora_1594.trc
...
orcl_ora_15395.trm orcl_ora_15559.trc  orcl_ora_1594.trm
orcl_ora_15405.trc orcl_ora_15559.trm

 

[oracle@localhost trace]$ tail -f orcl_ora_15805.trc

*** CLIENT ID:() 2014-09-09 08:08:44.925
...
alter session set sql_trace=true
...
select * from dual
# 记录下了system用户执行的查询语句过程
END OF STMT
FETCH #3:c=0,e=3,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=272002086,tim=1410264754691221