redo log 相关操作学习

1.Creating Redo Log Groups and Members

1.1.Creating Redo Log Groups

ALTER DATABASE 
  ADD LOGFILE GROUP 10 ('/oracle/dbs/log1c.rdo', '/oracle/dbs/log2c.rdo')
      SIZE 500K;

1.2.Creating Redo Log Members

ALTER DATABASE ADD LOGFILE MEMBER '/oracle/dbs/log2b.rdo' TO GROUP 2;

2.Relocating and Renaming Redo Log Members

2.1.Steps for Renaming Redo Log Members 

  1. Shut down the database.

    SHUTDOWN
  2. Copy the redo log files to the new location.

    The following example uses operating system commands (UNIX) to move the redo log members to a new location:

    mv /diska/logs/log1a.rdo /diskc/logs/log1c.rdo
    mv /diska/logs/log2a.rdo /diskc/logs/log2c.rdo
  3. Startup the database, mount, but do not open it.

    CONNECT / as SYSDBA
    STARTUP MOUNT
  4. Rename the redo log members.

    Use the ALTER DATABASE statement with the RENAME FILE clause to rename the database redo log files.

    ALTER DATABASE 
      RENAME FILE '/diska/logs/log1a.rdo', '/diska/logs/log2a.rdo' 
               TO '/diskc/logs/log1c.rdo', '/diskc/logs/log2c.rdo';
  5. Open the database for normal operation.

    The redo log alterations take effect when the database is opened.

    ALTER DATABASE OPEN; 

3.Dropping Redo Log Groups and Members

3.1.Dropping Log Groups

To drop a redo log group, you must have the ALTER DATABASE system privilege. Before dropping a redo log group, consider the following restrictions and precautions:

  • An instance requires at least two groups of redo log files, regardless of the number of members in the groups. (A group comprises one or more members.)

  • You can drop a redo log group only if it is inactive. If you need to drop the current group, first force a log switch to occur.

  • Make sure a redo log group is archived (if archiving is enabled) before dropping it. To see whether this has happened, use the V$LOG view.

    SELECT GROUP#, ARCHIVED, STATUS FROM V$LOG;
    
       GROUP# ARC STATUS
    --------- --- ----------------
            1 YES ACTIVE
            2 NO  CURRENT
            3 YES INACTIVE
            4 YES INACTIVE

Drop a redo log group with the SQL statement ALTER DATABASE with the DROP LOGFILE clause.

The following statement drops redo log group number 3:

   

  ALTER DATABASE DROP LOGFILE GROUP 3;

3.2.Dropping Redo Log Members

ALTER DATABASE DROP LOGFILE MEMBER '/oracle/dbs/log3c.rdo';


4.Forcing Log Switches

To force a log switch, you must have the ALTER SYSTEM privilege. Use the ALTER SYSTEM statement with the SWITCH LOGFILE clause.

The following statement forces a log switch:

ALTER SYSTEM SWITCH LOGFILE; 

5.Verifying Blocks in Redo Log Files

If you set the initialization parameter DB_BLOCK_CHECKSUM to TRUE, the database computes a checksum for each database block when it is written to disk, including each redo log block as it is being written to the current log. The checksum is stored the header of the block.

6.Clearing a Redo Log File

A redo log file might become corrupted while the database is open, and ultimately stop database activity because archiving cannot continue. In this situation the ALTER DATABASE CLEAR LOGFILE statement can be used to reinitialize the file without shutting down the database.

The following statement clears the log files in redo log group number 3:

ALTER DATABASE CLEAR LOGFILE GROUP 3;

This statement overcomes two situations where dropping redo logs is not possible:

  • If there are only two log groups

  • The corrupt redo log file belongs to the current group

If the corrupt redo log file has not been archived, use the UNARCHIVED keyword in the statement.

ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 3;

This statement clears the corrupted redo logs and avoids archiving them. The cleared redo logs are available for use even though they were not archived.

If you clear a log file that is needed for recovery of a backup, then you can no longer recover from that backup. The database writes a message in the alert log describing the backups from which you cannot recover.

If you want to clear an unarchived redo log that is needed to bring an offline tablespace online, use the UNRECOVERABLE DATAFILE clause in the ALTER DATABASE CLEAR LOGFILE statement.

If you clear a redo log needed to bring an offline tablespace online, you will not be able to bring the tablespace online again. You will have to drop the tablespace or perform an incomplete recovery. Note that tablespaces taken offline normal do not require recovery.

 

你可能感兴趣的:(oracle,sql,unix)