10g utilities:How to use LogMiner I

对数据库做不完全恢复的时候,如果我们能够精确的定位到出错的时间点的话,那么,我们可以在很大的程度上一次性地保证不完全恢复成功。所以,问题也就是我们应该怎么能够准确定位这个人为错误(如误删除表,错误的提交DML)发生的时间?接下来,要跟大家分享一下关于10g里LogMiner这个“日志挖掘器”的用法,也就是,在Oracle 10g版本的数据库,应该怎么使用LogMiner: 首先:简单介绍一下LogMiner工具。LogMiner 是Oracle公司从产品8i以后提供的一个非常有实用价值的分析工具,使用该工具可以轻松获得Oracle Online redo logs或者Archived logs日志文件中的具体内容。日志文件中记录了所有对数据库的数据块儿进行过改变的操作,而Logminer正是可以挖掘日志文件的利器。 其次:该如何使用Logminer?在早期的数据库版本里,LogMiner在默认情况下,并没有安装,需要手工的以SYSDBA身份去执行$ORACLE_HOME/rdbms/admin/dbmslm.sql以及$ORACLE_HOME/rdbms/admin/dbmslmd.sql这两个脚本。前者是创建DBMS_LOGMNR package,后者用于创建DBMS_LOGMNR_D这个包。在10g版本的数据库,这两个PL/SQL 包默认已经创建,我们就无须再去执行那两个脚本,可以直接对其调用。 然后:需要说明的一点,在Oracle 10g数据库版本里面,默认情况下,联机日志文件记录的内容并非提供任何的Supplemental logging,也就是说默认情况下使用LogMiner只能看到DDL操作。要想看到DML操作的话,在DML操作产生新的日志记录之前我们要启用最低的Supplemental logging,而启用这一特性又分为在数据库级别以及表级别,以下简单演示在全库级别启用最低Supplemental logging: 确认当前数据库Supplemental logging:

SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
NO

启用Supplemental logging,以便可以通过LogMiner看到日志文件中记录的关于DML操作的相关信息:

SQL> alter database add supplemental log data;
Database altered.
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES

日志“挖掘"结束,可以禁用Supplemental logging:

SQL> alter database drop supplemental log data;
Database altered.

接下来:该说说具体使用LogMiner的方法了: 使用方法1: 1.1确认数据库当前的日志文件信息:

SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
         1          1          5   52428800          1 YES INACTIVE                674382 16-MAY-10
         2          1          4   52428800          1 YES INACTIVE                660045 15-MAY-10
         3          1          6   52428800          1 NO  CURRENT                 691344 20-MAY-10
SQL> select * from v$logfile;
    GROUP# STATUS  TYPE    MEMBER                                   IS_
---------- ------- ------- ---------------------------------------- ---
         3         ONLINE  /u01/app/oradata/helen/redo03.log        NO
         2         ONLINE  /u01/app/oradata/helen/redo02.log        NO
         1         ONLINE  /u01/app/oradata/helen/redo01.log        NO

1.2从上面的结果可以确定当前数据库使用的是第3组日志,其对应的日志文件成员为/u01/app/oradata/helen/redo03.log ,也就是说,当前情况下,所有接下来对数据库的操作都将记录在第3个日志组所对应文件成员中,直到该日志组被写满为止。把该组的日志成员添加到LogMiner的"挖掘"范围之内:

SQL> exec dbms_logmnr.add_logfile
(logfilename=>'/u01/app/oradata/helen/redo03.log',
options=>dbms_logmnr.new);
PL/SQL procedure successfully completed.

可以通过v$logmnr_logs数据字典表验证:

SQL> select filename from v$logmnr_logs;
FILENAME
----------------------------------------
/u01/app/oradata/helen/redo03.log

想继续添加其他日志文件成员进来,只需重新执行上述PL/SQL package,把对应的参数修改为新的日志文件成员名称,并且把new以addfile取代。删除对某个日志文件成员的挖掘,只需以removefile取代new之。 1.3执行LogMiner:

SQL> exec dbms_logmnr.start_logmnr
(options=>dbms_logmnr.dict_from_online_catalog);
PL/SQL procedure successfully completed.

1.4开启另外一个会话,而且一定是新开第二个会话,不能跟刚才执行的调用Logminer在同一个会话,并且执行DML操作:

SQL> conn hr/hr;
Connected.
SQL> insert into test values(20);
1 row created.
SQL> insert into test values(21);
1 row created.
SQL> delete from test where id=21;
1 row deleted.
SQL>

1.5这时HR执行的操作已经被记录到日志文件里了,再切回到第一个会话,执行下述操作:

 SQL> select timestamp,table_name,sql_redo,sql_undo,operation
  2  from v$logmnr_contents
  3  where username='HR'

TIMESTAMP           TABLE SQL_REDO                                      SQL_UNDO                                 OPERATIO
------------------- ----- --------------------------------------------- ---------------------------------------- --------
2010/05/20 01:56:33       set transaction read write;                                                            START
2010/05/20 01:56:33 TEST  insert into "HR"."TEST"("ID") values ('20');  delete from "HR"."TEST" where "ID" = '20 INSERT
                                                                        ' and ROWID = 'AAAM39AAEAAAAGNAAA';

2010/05/20 01:56:36 TEST  insert into "HR"."TEST"("ID") values ('21');  delete from "HR"."TEST" where "ID" = '21 INSERT
                                                                        ' and ROWID = 'AAAM39AAEAAAAGNAAB';

2010/05/20 01:56:42 TEST  delete from "HR"."TEST" where "ID" = '21' and insert into "HR"."TEST"("ID") values ('2 DELETE
                           ROWID = 'AAAM39AAEAAAAGNAAB';                1');

1.6显然,我们可以看到准确的有用信息,当然V$logmnr_contents字典表中还可能有我们更为关心的字段,我们可以根据需要自行选取查看。挖掘完成之后,可以显示停止对Logminer工具的调用,也可以断开当前会话隐式停止对Logminer工具的使用,因为V$logmnr_contents表里的内容是存放在当前会话PGA里的。这也是为什么在调用Logminer的时候,其他会话是看不到v$logmnr_contents表里的内容,也解释了在第4步骤中为什么必须新开一个会话的原因。

SQL> exec dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed.
SQL> select filename from v$logmnr_logs;
no rows selected

关于LogMiner使用的另外一种方法,将在另外一篇日志里同大家齐分享!

oracle 10g SYSAUX tablespace

        The SYSAUX(System Auxiliary) tablespace is a new feature of Oracle 10g database,before 10g release,there wasn't this tablespace.After you created your database via DBCA(Database Configuration Assistant) tool,the SYSAUX tablespace was created for you automatically.

       But what's the mainly function of that tablespace? Why Oracle present the SYSAUX tablespace? Does it bring some benefit for the database or the DBA?

       Yep,the answer is ture.The SYSAUX tablespace is an auxiliary tablespace of the SYSTEM tablespace.In the earlier release before 10g,there is only way to store the components and other metadata in the SYSTEM tablespace.But now,with the SYSAUX tablespace,Oracle separate some components from SYSTEM tablespace,bring 'sth' from the SYSTEM tablespace to SYSAUX tablespace.By that,the workload of SYSTEM tablespace becomes light,decreases the space fragment in the SYSTEM tablespace,and it becomes  easy to manage the SYSTEM tablespace for DBAs.

       In addition,if the status of SYSAUX tablespace becomes offline(in fact we can bring it offline explicitly) or invalid,the Oracle database can works normally still.

       Now,let's find out which components were stored in the SYSTEM tablespace logically.First,we should be familar with the V$SYSAUX_OCCUPANTS dictionary table. V$SYSAUX_OCCUPANTS displays SYSAUX tablespace occupant information.

       So,we  need to do is only to issue a query against of the V$SYSAUX_OCCUPANTS view.

111

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0      Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

SQL> select occupant_name,schema_name,move_procedure,space_usage_kbytes from v$sysaux_occupants;

OCCUPANT_NAME                  SCHEMA_NAME          MOVE_PROCEDURE                      SPACE_USAGE_KBYTES
------------------------------ -------------------- ----------------------------------- ------------------
LOGMNR                         SYSTEM               SYS.DBMS_LOGMNR_D.SET_TABLESPACE                  6144
LOGSTDBY                       SYSTEM               SYS.DBMS_LOGSTDBY.SET_TABLESPACE                   896
STREAMS                        SYS                                                                     512
XDB                            XDB                  XDB.DBMS_XDB.MOVEXDB_TABLESPACE                  49216
AO                             SYS                  DBMS_AW.MOVE_AWMETA                                768
XSOQHIST                       SYS                  DBMS_XSOQ.OlapiMoveProc                            768
XSAMD                          OLAPSYS              DBMS_AMD.Move_OLAP_Catalog                           0
SM/AWR                         SYS                                                                  250496
SM/ADVISOR                     SYS                                                                  176384
SM/OPTSTAT                     SYS                                                                  289216
SM/OTHER                       SYS                                                                   23424

OCCUPANT_NAME                  SCHEMA_NAME          MOVE_PROCEDURE                      SPACE_USAGE_KBYTES
------------------------------ -------------------- ----------------------------------- ------------------
STATSPACK                      PERFSTAT                                                                  0
ODM                            DMSYS                MOVE_ODM                                             0
SDO                            MDSYS                MDSYS.MOVE_SDO                                   22400
WM                             WMSYS                DBMS_WM.move_proc                                 7296
ORDIM                          ORDSYS                                                                  512
ORDIM/PLUGINS                  ORDPLUGINS                                                                0
ORDIM/SQLMM                    SI_INFORMTN_SCHEMA                                                        0
EM                             SYSMAN               emd_maintenance.move_em_tblspc                  164800
TEXT                           CTXSYS               DRI_MOVE_CTXSYS                                      0
ULTRASEARCH                    WKSYS                MOVE_WK                                              0
ULTRASEARCH_DEMO_USER          WK_TEST              MOVE_WK                                              0

OCCUPANT_NAME                  SCHEMA_NAME          MOVE_PROCEDURE                      SPACE_USAGE_KBYTES
------------------------------ -------------------- ----------------------------------- ------------------
EXPRESSION_FILTER              EXFSYS                                                                 3712
EM_MONITORING_USER             DBSNMP                                                                 1856
TSM                            TSMSYS                                                                    0
JOB_SCHEDULER                  SYS                                                                    1024

26 rows selected.

SQL> 

 

222   For a test purpose,we can bring the LogMiner component to the EXAMPLES tablespace.

 SQL> exec dbms_logmnr_d.set_tablespace('example');

PL/SQL procedure successfully completed.

SQL>

and then we issue a  query against the V$SYSAUX_OCCUPANTS to obtain the effect:

SQL> select occupant_name,schema_name,move_procedure,space_usage_kbytes

  2  from v$sysaux_occupants

  3  where occupant_name like 'LOGMNR%'

  4  ;

OCCUPANT_NAME                  SCHEMA_NAME          MOVE_PROCEDURE                      SPACE_USAGE_KBYTES

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

LOGMNR                         SYSTEM               SYS.DBMS_LOGMNR_D.SET_TABLESPACE                     0

SQL> 

333 ok,the SPACE_USAGE_KBYTES value of the LOGMNR   is 0,instead of  the original value of 6144.

and then,let's bring it back to the SYSAUX tablespace.

SQL> exec dbms_logmnr_d.set_tablespace('SYSAUX');

PL/SQL procedure successfully completed.

SQL> select occupant_name,schema_name,move_procedure,space_usage_kbytes
  2  from v$sysaux_occupants
  3  where occupant_name like 'LOGMNR%'
  4  ;

OCCUPANT_NAME                  SCHEMA_NAME          MOVE_PROCEDURE                      SPACE_USAGE_KBYTES
------------------------------ -------------------- ----------------------------------- ------------------
LOGMNR                         SYSTEM               SYS.DBMS_LOGMNR_D.SET_TABLESPACE                  6144

SQL> 
444 Furthermore,we can do some more experiences on the SYSAUX tablespce.
SQL> drop tablespace sysaux;
drop tablespace sysaux
*
ERROR at line 1:
ORA-13501: Cannot drop SYSAUX tablespace


SQL> 

555 we can't drop the SYSAUX tablespace.

SQL> alter tablespace sysaux offline;

Tablespace altered.

SQL> alter tablespace sysaux online;

Tablespace altered.

SQL> 

666 we can  switch the status(online to offline or else.) of the SYSAUX tablespace manually.

SQL> alter tablespace sysaux read only;
alter tablespace sysaux read only
*
ERROR at line 1:
ORA-13505: SYSAUX tablespace can not be made read only


SQL> 

777 we can not alter the SYSAUX tablespace to read only status.

SQL> alter tablespace sysaux rename to new_sys;
alter tablespace sysaux rename to new_sys
*
ERROR at line 1:
ORA-13502: Cannot rename SYSAUX tablespace


SQL> 

888  Also,we can not rename the SYSAUX tablespace.

 

———————————-The End—————————–

revoke sysdba from user_name

把sysdba权限授予给user1之后,orapwSID文件中记录了user1的信息,但是将sysdba权限从user1收回之后,orapwSID文件中依然有user1用户。这是为什么呢???
可是联机文档上明明说:
A user’s name remains in the password file only as long as that user has at least one of these two privileges. If you revoke both of these privileges, Oracle Database removes the user from the password file.

以下是我的实验步骤:
1看到字典里面记录的只有SYS用户拥有SYSDBA和SYSOPER系统权限:
SQL> select * from v$pwfile_users;

USERNAME                       SYSDB SYSOP
—————————— —– —–
SYS                            TRUE  TRUE

2给普通用户user1授予sysdba的权限:
SQL> grant sysdba to user1;

Grant succeeded.

3再次查看字典验证,看到授权成功,user1也拥有了sysdba权限:
SQL> select * from v$pwfile_users;

USERNAME                       SYSDB SYSOP
—————————— —– —–
SYS                            TRUE  TRUE
USER1                          TRUE  FALSE

4并且user1也记录到了orapwSID文件(我的ORACLE_SID=asher)
SQL> !strings $ORACLE_HOME/dbs/orapwasher
]\[Z
ORACLE Remote Password file
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A
USER1
BBE7786A584F9103


5并且user1也可以以sysdba登录:
SQL> conn user1/user1 as sysdba;
Connected.
SQL> show user;
USER is “SYS”
SQL> conn sys/oracle as sysdba;
Connected.

6收回权限:
SQL> revoke sysdba from user1;

Revoke succeeded.
7接着查看字典,发现user1已经没了sysdba的权限:
SQL> select * from v$pwfile_users;

USERNAME                       SYSDB SYSOP
—————————— —– —–
SYS                            TRUE  TRUE

8可是user1依然在orapwSID文件中存在:
SQL> !strings $ORACLE_HOME/dbs/orapwasher
]\[Z
ORACLE Remote Password file
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A
USER1
BBE7786A584F9103

9重启数据再次查看:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> statup;
SP2-0042: unknown command “statup” – rest of line ignored.
SQL> startup;
ORACLE instance started.

Total System Global Area  293601280 bytes
Fixed Size                  1219016 bytes
Variable Size              75499064 bytes
Database Buffers          209715200 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.

10查看字典:
SQL> select * from v$pwfile_users;

USERNAME                       SYSDB SYSOP
—————————— —– —–
SYS                            TRUE  TRUE
11orapwSID文件依然存在:
SQL> !strings $ORACLE_HOME/dbs/orapwasher
]\[Z
ORACLE Remote Password file
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A
USER1
BBE7786A584F9103

SQL>

以上所有实验环境:
SQL> !uname -a
Linux RHEL4 2.6.9-89.ELsmp #1 SMP Mon Apr 20 10:34:33 EDT 2009 i686 i686 i386 GNU/Linux

SQL> select * from v$version;

BANNER
—————————————————————-
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Prod
PL/SQL Release 10.2.0.1.0 – Production
CORE    10.2.0.1.0      Production
TNS for Linux: Version 10.2.0.1.0 – Production
NLSRTL Version 10.2.0.1.0 – Production

请各位看官指点迷津!谢谢!此环境下,我的数据库没有屏蔽操作系统认证(不知道跟这个有没有关系?)!实验的结果跟联机文档上说的出现冲突,我就很是纳闷???user1根本没有赋予sysoper的权限,所以我就没有revoke sysoper from user1,我想跟这个也没有关系吧?再次谢过!希望这个问题能得到高手的解决~~~

ORA-03113: end-of-file on communication channel

Tonight,after I did some changes on the parameter(processes,changed it from 150 default to 2),I issued the commands below:

SQL> alter system set processes=2 scope=spfile;

System altered.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup;

ORA-03113: end-of-file on communication channel

SQL> !oerr ora 03113

03113, 00000, “end-of-file on communication channel”

// *Cause: The connection between Client and Server process was broken.

// *Action: There was a communication error that requires further investigation.

//          First, check for network problems and review the SQL*Net setup.

//          Also, look in the alert.log file for any errors. Finally, test to

//          see whether the server process is dead and whether a trace file

//          was generated at failure time.

So,I got the error  ORA-03113,now I know the reason for this is that i changed the ‘process’ parameter to a too small.But I didn’t know the truly fact.

After that,i had to connect again,and startup the database using a pfile,and recreate a new spfile from the pfile.


SQL> alter system set processes=2 scope=spfile;
System altered.

Multiplexing Oracle Control File

1 Multiplexing the control file when using SPFILE Firstly, Obtain the information of your control file SQL> select * from v$controlfile;

STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS
  /u01/oradata/helen/control01.ctl NO 16384 430
  /u01/oradata/helen/control02.ctl NO 16384 430

also you can issue this command show parameter control_files to get the information of your control file. Secondly, Make sure that your server is using the SPFILE SQL> show parameter spfile; Aafter this command is executed,we should get some value like this

NAME TYPE VALUE
spfile string /u01/app/oracle/dbs/spfilehelen.ora

if there is no result returned (a truly result for the VALUE column in the above table),it means that your server is now using a PFILE. 😆  How to Multiplexing Control File when using PFILE ? We will describe it soon . Now,we will multiplex the Control File: ① Alter the SPFILE

SQL> alter system set control_files= '/u01/oradata/helen/control01.ctl','/u01/oradata/helen/control02.ctl','/u01/oradata/control03.ctl' scope=spfile;

SQL> alter system set control_files='/u01/oradata/helen/control01.ctl', '/u01/oradata/helen/control02.ctl', '/u01/oradata/control03.ctl' scope=spfile; System altered. ②  Shutdown the database SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. ③  Create the additional Control File [oracle@Linux10g ~]$ cp /u01/oradata/helen/control01.ctl /u01/oradata/control03.ctl ④  Startup the database SQL> startup; ORACLE instance started. Total System Global Area  343932928 bytes Fixed Size                  1219328 bytes Variable Size              79693056 bytes Database Buffers          260046848 bytes Redo Buffers                2973696 bytes Database mounted. Database opened. ⑤ Identifying our Control File again SQL> select * from v$controlfile;

STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS
  /u01/oradata/helen/control01.ctl NO 16384 430
  /u01/oradata/helen/control02.ctl NO 16384 430
  /u01/oradata/control03.ctl NO 16384 430

NOw,we have multiplexed the Control File When using SPFILE. 2 Multiplexing the control file when using PFILE First of all, you should to know if your server is now using a PFILE ?

SQL> show parameter spfile; At here,we can get the conclusion that the server is now using a PFILE,cause the result of the value column is null.
NAME TYPE VALUE
spfile string  
 
Maybe you are confused about the result of the above SQL command,but in fact it's true.Next,
①  Shutdown the database.
②  Create Control Files at the target directory where you want multiplex and give the corrent names.
[oracle@Linux10g ~]$ cp /u01/oradata/helen/control03.ctl /u01/oradata/control04.ctl
③  Modify the PFILE ,to make it includes the Control Files which we have created just now.
Before we change the PFILE,it maybe looks like:
……
*.control_files='/u01/oradata/helen/control01.ctl','/u01/oradata/helen/control02.ctl','/u01/o
radata/control03.ctl'
……
But after we've modified the file,it as :
……
*.control_files='/u01/oradata/helen/control01.ctl','/u01/oradata/helen/control02.ctl','/u01/o
radata/control03.ctl','/u01/oradata/control04.ctl'
……
④   startup the database
SQL> startup pfile='/u01/app/oracle/dbs/pfilehelen.ora';
⑤ Identifying our Control File again,to see if  it works correctly. SQL> select * from v$controlfile;

STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS
  /u01/oradata/helen/control01.ctl NO 16384 430
  /u01/oradata/helen/control02.ctl NO 16384 430
  /u01/oradata/control03.ctl NO 16384 430
  /u01/oradata/control04.ctl NO 16384 430
 
Yep,It's great.We can multiplex Oracle Control File weather the server is used a SPFILE or a PFILE.