• No results found

FILE MGMT IN ORACLE.pdf

N/A
N/A
Protected

Academic year: 2021

Share "FILE MGMT IN ORACLE.pdf"

Copied!
21
0
0

Loading.... (view fulltext now)

Full text

(1)

RELOCATE OR RENAME THE DATAFILES USING RMAN

We can use RMAN to move datafiles from one location to another location with less time. I am going to move two datafiles from one location to another location. Take rman fresh backup.

GETS THE FILE ID , NAME & PATH OF THE FILE

SYS> select file_name, tablespace_name from dba_data_files where tablespace_name='CRMS';

FILE_ID FILE_NAME TABLESPACE_NAME --- --- ---

5 /u01/crms/crms02.dbf CRMS 6 /u01/crms/crms01.dbf CRMS

RMAN> report schema;

Report of database schema for database with db_unique_name CRMS List of Permanent Datafiles

===========================

File Size(MB) Tablespace RB segs Datafile Name

---- --- --- --- --- 1 870 SYSTEM *** /u02/app/oracle/oradata/crms/system01.dbf 2 600 SYSAUX *** /u02/app/oracle/oradata/crms/sysaux01.dbf 3 1730 UNDOTBS1 *** /u02/app/oracle/oradata/crms/undotbs01.dbf 4 487 USERS *** /u02/app/oracle/oradata/crms/users01.dbf 5 20 CRMS *** /u01/crms/crms02.dbf 6 50 CRMS *** /u01/crms/crms01.dbf 7 20 HRMS *** /u01/app/oracle/oradata/crms/hrms02.dbf 8 50 HRMS *** /u02/app/oracle/oradata/crms/hrms01.dbf 9 50 TBS1 *** /u02/app/oracle/oradata/crms/tbs01.dbf 10 500 TBS2 *** /u02/app/oracle/oradata/crms/tbs02.dbf 11 500 TBS3 *** /u02/app/oracle/oradata/crms/tbs03.dbf List of Temporary Files

=======================

File Size(MB) Tablespace Maxsize(MB) Tempfile Name

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

1 20 TEMP 32767 /u02/app/oracle/oradata/crms/temp01.dbf

MAKE THE TABLESPACE TO OFFLINE

RMAN> SQL 'alter tablespace crms offline'; sql statement: alter tablespace crms offline

COPY FILE(S) TO THE NEW LOCATION

RMAN> copy datafile 5 to '/u02/app/oracle/oradata/crms/crms01.dbf'; Starting backup at 20-MAY-15

using channel ORA_DISK_1

(2)

input datafile file number=00005 name=/u01/CRMS/crms02.dbf

output file name=/u02/app/oracle/oradata/crms/crms01.dbf tag=TAG20150520T150020 RECID=243 STAMP=880210820

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 20-MAY-15

RMAN> copy datafile 6 to '/u02/app/oracle/oradata/crms/crms02.dbf'; Starting backup at 20-MAY-15

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00006 name=/u01/CRMS/crms01.dbf

output file name=/u02/app/oracle/oradata/crms/crms02.dbf tag=TAG20150520T150025 RECID=244 STAMP=880210826

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 20-MAY-15

USE RMAN ‘SWITCH’ TO THE NEWLY CREATED DATAFILES

RMAN> switch datafile 5 to copy;

datafile 5 switched to datafile copy "/u02/app/oracle/oradata/crms/crms01.dbf"

RMAN> switch datafile 6 to copy;

datafile 6 switched to datafile copy "/u02/app/oracle/oradata/crms/crms02.dbf"

RECOVER THE TABLESPACE

RMAN> recover tablespace crms; Starting recover at 20-MAY-15 using channel ORA_DISK_1

starting media recovery

media recovery complete, elapsed time: 00:00:00 Finished recover at 20-MAY-15

TURN THE TABLESPACE TO ONLINE

RMAN> SQL 'alter tablespace crms online'; sql statement: alter tablespace crms online RMAN> report schema;

.. ...

SYS> select file_name, file_id, tablespace_name from dba_data_files where tablespace_name='CRMS';

FILE_NAME FILE_ID TABLESPACE_NAME --- --- ---

/u02/app/oracle/oradata/crms/crms01.dbf 5 CRMS /u02/app/oracle/oradata/crms/crms02.dbf 6 CRMS

(3)

RELOCATE A SPECIFIC DATAFILE

SYS> select file_name, file_id, tablespace_name from dba_data_files where tablespace_name='HRMS';

FILE_NAME FILE_ID TABLESPACE_NAME --- --- ---

/u02/app/oracle/oradata/crms/hrms02.dbf 7 HRMS /u01/CRMS/hrms01.dbf 8 HRMS

RMAN> report schema; ...

8 50 HRMS *** /u01/CRMS/hrms01.dbf ...

RMAN> SQL 'alter database datafile 8 offline'; sql statement: alter database datafile 8 offline

RMAN> copy datafile 8 to '/u02/app/oracle/oradata/crms/hrms01.dbf'; Starting backup at 20-MAY-15

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00008 name=/u01/CRMS/hrms01.dbf

output file name=/u02/app/oracle/oradata/crms/hrms01.dbf tag=TAG20150520T163717 RECID=258 STAMP=880216638

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 20-MAY-15

RMAN> switch datafile 8 to copy;

datafile 8 switched to datafile copy "/u02/app/oracle/oradata/crms/hrms01.dbf"

RMAN> recover datafile 8; Starting recover at 20-MAY-15 using channel ORA_DISK_1

starting media recovery

media recovery complete, elapsed time: 00:00:00 Finished recover at 20-MAY-15

RMAN> sql 'alter database datafile 8 online'; sql statement: alter database datafile 8 online

SYS> select file_name, file_id, tablespace_name from dba_data_files where tablespace_name='HRMS';

FILE_NAME FILE_ID TABLESPACE_NAME

--- --- ---

/u02/app/oracle/oradata/crms/hrms02.dbf 7 HRMS /u02/app/oracle/oradata/crms/hrms01.dbf 8 HRMS

(4)

RELOCATE OR RENAME A DATAFILE USING ALTER TABLESPACE

Using alter tablespace command we can rename or relocate a datafile. SYS> select file_id, name, tablespace_name from dba_data_files;

SYS> alter database datafile <file_id> offline; or SYS> alter tablespace <tbs_name> offline;

Linux> $ mv oldpath/ /new path/

SYS> alter tablespace users RENAME DATAFILE '/old path' TO '/new path' SYS> recover datafile <file_id>; or

SYS> alter database datafile <file_id> online;

GETS FILE#, NAME & TABLESPACE_NAME

SYS> select file_id, name, tablespace_name from dba_data_files;

FILE_ID FILE_NAME TABLESPACE_NAME

--- --- --- 4 /u01/crms/datafiles/users01.dbf USERS

.. ...

MAKE THE FILE TO OFFLINE

SYS> alter database datafile 4 offline; Database altered.

COPY THE FILE AT OS LEVEL $ cd /u01/crms/datafiles

$ mv users01.dbf /u02/app/oracle/oradata/crms/users01.dbf INFORM TO THE DATABASE FILE CHANGED LOCATION

SYS> alter tablespace USERS RENAME DATAFILE

'/u01/crms/datafiles/users01.dbf' TO '/u02/app/oracle/oradata/crms/users01.dbf'; Tablespace altered.

RECOVER THE FILE & MAKE IT ONLINE

SYS> recover datafile 4; Media recovery complete.

SYS> alter database datafile 4 online; Database altered.

Using ALTER DATABASE command we can do it.

SYS> select file_id, name, tablespace_name from dba_data_files;

FILE_ID FILE_NAME TABLESPACE_NAME

--- --- --- 9 /u01/crms/datafiles/tbs01.dbf TBS1

(5)

SYS> alter database datafile 9 offline; Database altered.

$ cd /u01/crms/datafiles

$ mv tbs01.dbf /u02/app/oracle/oradata/crms/tbs01.dbf

SYS> alter database rename file

'/u01/crms/datafiles/tbs01.dbf' TO '/u02/app/oracle/oradata/crms/tbs01.dbf'; Tablespace altered.

SYS> recover datafile 9; Media recovery complete.

SYS> alter database datafile 9 online; Database altered.

MULTIPLEXING CONTROL FILES USING SPFILE

SYS> show parameter spfile;

NAME TYPE VALUE

--- --- ---

spfile string /u02/app/oracle/product/11.2.0 /dbhome_1/dbs/spfilecrms.ora

SYS> show parameter control_file;

NAME TYPE VALUE

--- --- ---

control_file_record_keep_time integer 7

control_files string /u02/app/oracle/oradata/crms/c ontrol01.ctl, /u02/app/oracle/

flash_recovery_area/crms/control02.ctl

As you see currently we have only two control files. In order to add a control we need to update

the CONTROL_FILES parameter with the new location using the ALTER SYSTEM SET CONTROL_FILES command. SYS> alter system set control_files='/u02/app/oracle/oradata/crms/ctrl/control01.ctl',

'/u01/app/oracle/flash_recovery_area/mltplx/crms/ctrl/control02.ctl',

'/u03/app/oracle/flash_recovery_area/mltplx/crms/ctrl/control03.ctl' scope=spfile; System altered.

Next we have to shutdown the database and copy one of the existing control files to the newly added location as per above alter system command.

SHUTDOWN YOUR DATABASE

SYS> shut immediate; Database closed.

Database dismounted.

(6)

$ cd /u02/app/oracle/oradata/crms/

$ cp control01.ctl /u02/app/oracle/oradata/crms/ctrl/control01.ctl $ cd /u02/app/oracle/flash_recovery_area/crms/

$ cp control02.ctl /u01/app/oracle/flash_recovery_area/mltplx/ctrl/control02.ctl $ cp control02.ctl /u03/app/oracle/flash_recovery_area/mltplx/ctrl/control03.ctl

BRINGUP THE DATABASE

SYS> startup;

ORACLE instance started.

Total System Global Area 1255473152 bytes Fixed Size 1336232 bytes Variable Size 989858904 bytes Database Buffers 251658240 bytes Redo Buffers 12619776 bytes Database mounted.

Database opened.

SYS> select name from v$controlfile;

NAME

--- /u02/app/oracle/oradata/crms/ctrl/control01.ctl

/u01/app/oracle/flash_recovery_area/mltplx/crms/ctrl/control02.ctl /u03/app/oracle/flash_recovery_area/mltplx/crms/ctrl/control03.ctl

Multiplexing the control files is a simple process that provides great benefits in the case of control file corruption and loss.

MULTIPLEXING CONTROL FILES USING PFILE QUERY TO FIND INITIALIZATION PARAMETER FILE

SYS> show parameter pfile;

NAME TYPE VALUE

--- --- ---

spfile string

SQL> show parameter control_files;

NAME TYPE VALUE

--- --- ---

control_files string /u01/app/oracle/oradata/devdb/control01.ctl

This database is using single control file. Running database with single control file is not a good choice. So I am going to add two control files. Having multiple control files reduces the risk of control file loss due to corruption or removal.

(7)

SHUTDOWN THE DATABASE

SQL> shut immediate; Database closed. Database dismounted.

ORACLE instance shut down.

[oracle@SERVER1 dbs]$ cd $ORACLE_HOME/dbs [oracle@SERVER1 dbs]$ vi initdevdb.ora .. ... control_files=("/u01/app/oracle/oradata/devdb/ctrl/control01.ctl" "/u02/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control02.ctl", "/u03/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control03.ctl") ...

COPY & RENAME COTROLFILES AS PER PFILE

$ cd /u01/app/oracle/oradata/devdb

$ cp control01.ctl /u01/app/oracle/oradata/devdb/ctrl/control01.ctl

$ cp control01.ctl /u02/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control02.ctl $ cp control01.ctl /u03/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control03.ctl

MOUNT THE DATABASE USING PFILE

SQL> startup

ORACLE instance started.

Total System Global Area 901775360 bytes Fixed Size 1276812 bytes Variable Size 226493556 bytes Database Buffers 671088640 bytes Redo Buffers 2916352 bytes Database mounted.

CREATE THE NEW SPFILE

SQL> create spfile from pfile; File created.

SQL> shut immediate;

ORACLE instance shut down. SQL> startup;

ORACLE instance started. ..

...

When an instance is started, memory structure of the instance are established by parameters specified within the initialization parameter file. This parameter file can be either pfile or spfile. But priority always goes to spfile. This is a binary file maintained by the server and it can be backed up by RMAN. RMAN cannot backup pfile because it is text file.

(8)

SQL> show parameter pfile;

NAME TYPE VALUE

--- --- ---

spfile string /u01/app/oracle/product/10.2.0/db_1/dbs/spfiledevdb.ora

SQL> select name from v$controlfile;

NAME

---

/u01/app/oracle/oradata/devdb/ctrl/control01.ctl

/u02/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control02.ctl /u03/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control03.ctl

CONTROL FILE BACKUP

Whenever the database is altered, the control file should be backed up. The primary method of backing up the controlfile is to use a SQL statement to generate a binary file. A binary backup is preferable because it contains additional info such as archived log history , offline tablespaces and backupsets info (for rman backup).

BACKUP CONTROL FILE IN BINARY FORMAT

This command is to create a duplicate copy of the existing control file in a specified location. SQL> alter database backup controlfile to '/home/oracle/ctrl.sql';

BACKUP CONTROL FILE IN READABLE FORMAT

Following command produces the SQL script that we can use to recreate the database controlfile in case all multiplexed binary versions of the controlfiles are lost.

SQL> alter database backup controlfile to trace;

SQL> alter database backup controlfile to trace as '/home/oracle/ctrl.trc';

If you do not mention any location, trace file will be located in UDUMP --> user_dump_dest. To find user_dump_dest location we can use following query in 10g.

SQL> show parameter user_dump_dest;

In 11g, a new parameter called "diagnostic_dest" determines where files will are created. This diagnostic_dest replaces background_dump_dest, user_dump_dest, core_dump_dest.

SQL> show parameter diag;

In certain circumstances, we have to recreate our database controlfile. Let’s see.

All copies of control files are LOST or CORRUPTED.

If we want to change MAX parameter of the database that was set when the database was created. Hard limit parameters are MAXDATAFILES , MAXLOGFILES, MAXLOGHISTORY , etc..

If we move our database to another server which is running the same Operating System but files are present in different location.

(9)

PRESENT LOCATION OF CONTROLFILES

SYS> select name from v$controlfile;

NAME

---

/u01/app/oracle/oradata/devdb/ctrl/control01.ctl

/u02/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control02.ctl /u03/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control03.ctl

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled

Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 6

Next log sequence to archive 8 Current log sequence 8

SQL> column member format a40;

SQL> select a.group#, a.member,b.status from v$logfile a, v$log b where a.group#=b.group#;

GROUP# MEMBER STATUS

--- --- --- 3 /u01/app/oracle/oradata/devdb/redo03.log ACTIVE

2 /u01/app/oracle/oradata/devdb/redo02.log CURRENT 1 /u01/app/oracle/oradata/devdb/redo01.log ACTIVE

CREATE CONTROL FILE BACKUP USING ANYONE METHOD

File will be created under $ORACLE_HOME/dbs location.

SQL> alter database backup controlfile to trace as 'ctrl.txt';

File will be created specified location.

SQL> alter database backup controlfile to traces as '/home/oracle/ctrl.sql' Database altered.

Edit the trace file just given below. Do not leave any line empty in control file script

otherwise it will throw error. Remove all #commented lines. File should looks like given below.

CREATE CONTROLFILE REUSE DATABASE "DEVDB" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE

GROUP 1 '/u01/app/oracle/oradata/devdb/redo01.log' SIZE 50M, GROUP 2 '/u01/app/oracle/oradata/devdb/redo02.log' SIZE 50M, GROUP 3 '/u01/app/oracle/oradata/devdb/redo03.log' SIZE 50M

(10)

DATAFILE '/u01/app/oracle/oradata/devdb/system01.dbf', '/u01/app/oracle/oradata/devdb/undotbs01.dbf', '/u01/app/oracle/oradata/devdb/sysaux01.dbf', '/u01/app/oracle/oradata/devdb/users01.dbf', '/u01/app/oracle/oradata/devdb/example01.dbf' CHARACTER SET WE8ISO8859P1

;

RENAMED CONTROL FILE NAMES AT OS LEVEL

$ cd /u01/app/oracle/oradata/devdb/ctrl $ mv control01.ctl control01.ctl.bkp $ cd /u02/app/oracle/fash_recovery_area/mltplx/devdb/ctrl $ mv control02.ctl control02.ctl.bkp $ cd /u03/app/oracle/fash_recovery_area/mltplx/devdb/ctrl $ mv control03.ctl control03.ctl.bkp

I have renamed all control files name with .bkp extension. Generally, whatever you are doing at operating system level such as (removing database file(s), renaming database files) database cannot understand. Now we don’t have any control files. Let’s us connect to the database.

SQL> disc

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> conn / as sysdba

Connected.

SQL> archive log list;

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u01/app/oracle/oradata/devdb/ctrl/control01.ctl' ORA-27041: unable to open file

Linux Error: 2: No such file or directory Additional information: 3

SHUT THE DATABASE & STARTUP

SQL> shut abort;

ORACLE instance shut down. SQL> startup;

ORACLE instance started.

Total System Global Area 901775360 bytes Fixed Size 1276812 bytes Variable Size 226493556 bytes Database Buffers 671088640 bytes Redo Buffers 2916352 bytes

(11)

Now we have the only one option need to recreate control files from the ctrl.sql file. Let’s try. SQL> select status from v$instance;

STATUS

--- STARTED

SQL> @/home/oracle/ctrl.sql; Control file created.

SQL> select status from v$instance;

STATUS

--- MOUNTED

SQL> select open_resetlogs from v$database;

OPEN_RESETL

--- REQUIRED

SQL> alter database open resetlogs; alter database open resetlogs

*

ERROR at line 1:

ORA-01194: file 1 needs more recovery to be consistent

ORA-01110: data file 1: '/u01/app/oracle/oradata/devdb/system01.dbf'

SQL> recover database using backup controlfile until cancel;

ORA-00279: change 418149 generated at 05/21/2015 20:29:18 needed for thread 1 ORA-00289: suggestion :

/u01/app/oracle/flash_recovery_area/DEVDB/archivelog/2015_05_21/o1_mf_1_8_%u_.arc ORA-00280: change 418149 for thread 1 is in sequence #8

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

auto

ORA-00308: cannot open archived log

'/u01/app/oracle/flash_recovery_area/DEVDB/archivelog/2015_05_21/o1_mf_1_8_%u_.arc' ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory Additional information: 3

ORA-00308: cannot open archived log

'/u01/app/oracle/flash_recovery_area/DEVDB/archivelog/2015_05_21/o1_mf_1_8_%u_.arc' ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory Additional information: 3

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below ORA-01194: file 1 needs more recovery to be consistent

(12)

SQL> select a.group#,a.member,b.status from v$logfile a, v$log b where a.group#=b.group#;

GROUP# MEMBER STATUS

--- --- ---

1 /u01/app/oracle/oradata/devdb/redo01.log ACTIVE 2 /u01/app/oracle/oradata/devdb/redo02.log ACTIVE 3 /u01/app/oracle/oradata/devdb/redo03.log CURRENT

SQL> recover database using backup controlfile until cancel;

ORA-00279: change 418149 generated at 05/21/2015 20:29:18 needed for thread 1 ORA-00289: suggestion :

/u01/app/oracle/flash_recovery_area/DEVDB/archivelog/2015_05_21/o1_mf_1_8_%u_.arc ORA-00280: change 418149 for thread 1 is in sequence #8

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

/u01/app/oracle/oradata/devdb/redo03.log

ORA-00310: archived log contains sequence 6; sequence 8 required ORA-00334: archived log: '/u01/app/oracle/oradata/devdb/redo03.log'

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below ORA-01194: file 1 needs more recovery to be consistent

ORA-01110: data file 1: '/u01/app/oracle/oradata/devdb/system01.dbf' SQL> recover database using backup controlfile until cancel;

ORA-00279: change 418149 generated at 05/21/2015 20:29:18 needed for thread 1 ORA-00289: suggestion :

/u01/app/oracle/flash_recovery_area/DEVDB/archivelog/2015_05_21/o1_mf_1_8_%u_.arc ORA-00280: change 418149 for thread 1 is in sequence #8

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

/u01/app/oracle/oradata/devdb/redo02.log Log applied.

Media recovery complete.

SQL> alter database open resetlogs; Database altered.

SQL> archive log list;

Database log mode Archive Mode Automatic archival Enabled

Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 1

Next log sequence to archive 1 Current log sequence 1 SQL> select name from v$controlfile;

NAME

--- /u01/app/oracle/oradata/devdb/ctrl/control01.ctl

/u02/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control02.ctl /u03/app/oracle/flash_recovery_area/mltplx/devdb/ctrl/control03.ctl

(13)

RESETLOGS

SQL> alter database open resetlogs;

This statement determines the database resets the current redolog sequence number to 1.

Whenever you perform incomplete media recovery (can’t use current redolog) or media recovery using a backup controlfile, above SQL statement is really required. Online redologs sequence will be 1.

OPEN RESETLOGS operation creates a new incarnation because the database requires a new incarnation to avoid confusion when two different redo streams have the same SCNs , occurred in different time.

RESETLOGS DOES

Archives the current online redo logs (if they are accessible).

Erases the contents of the online redologs and resets the log sequence number to 1.

If the current online redo logs are sequence 1000 and 1001, when you open with RESETLOGS, then the database archives the sequence 1000 and 1001 then resets online redologs to sequence to 1 and 2. Creates the online redo log files if they are NOT exist.

Resets the controlfile metadata about online redologs and redo threads.

Updates all datafiles, online redo log files and all sub sequent archived redo logs with a new RESETLOGS SCN and TIMESTAMP.

RMAN> list incarnation;

Whenever you open the database with RESETLOGS option, a database incarnation is created. All previous backups became invalid, so it is important to take a full backup of the database.

An incarnation helps to identify redo streams which have the same SCN, but occurred at different points in time. This prevents applying the wrong archive log file from a previous incarnation.

Incarnation 1 of the database starts at SCN 1, and continues through SCN 1000 to SCN 2000. At SCN 2000 in incarnation 1, you perform a point-in-time recovery back to SCN 1000, and open the datbase with a RESETLOGS operation. This creates incarnation 2, which begins at SCN 1000 and contines to SCN 3000. At SCN 3000 in incarnation 2, you perform another point-in-time recovery and RESETLOGS operation. This creates incarnation 3, starting at SCN 2000.

(14)

Oracle uses NORESTLOGS when doing complete recovery (entire redo stream was applied). Oracle can use existing log files. The NORESETLOGS option does not clear the redo log files during startup and the online redo logs to be used for recovery if .

ARCHIVELOG | NOARCHIVELOG

If you Specify ARCHIVRLOG, Oracle archives the contents of redolog files instead of overwritten. Archive mode helps to recover all committed transactions in the event of system or disk failure. IT is not recommended to run the database in noarchivelog mode, you are disabling archiving of redo logs. It cannot help from the media failure.

Once you omit both clause (Archive & Noarchive) by default oracle chooses noarchivelog mode.

REUSE | SET

SET: Use SET DATABASE clause to change name of the database. If you do NOT want to rename the

database, you should NOT use the ‘SET DATABASE’ clause in the controlfile statement.

REUSE: Specify REUSE to indicate existing controlfile(s) can be reused and overwrite if file(s)

contain any information. If you omit this clause you will get error following below. ORA-00202: control file: '/u01/app/oracle/oradata/devdb/control01.ctl'

ORA-27038: created file already exists

SAMPLE CREATE CONTROL FILE SCRIPT

REDOLOG FILES MANAGEMENT

The MAXLOGFILES parameter determines the maximum number of groups of redo log files. The MAXLOGMEMBERS parameter determines the maximum number of members for each group. The max and default value for MAXLOGMEMBERS, MAXLOGFILES is dependent on operating system.

When compatibility is set to 10.2.0 or later, you can exceed the limit and the control files expand as needed. Suppose compatibility level is set earlier than 10.2.0 the only way to override the upper limit is recreate the database or it’s control file.

(15)

The Oracle database requires a minimum of two redo log files to guarantee, one is available for writing the other is being archived. LGWR writes to redo log files in circular fashion.

When the current redo log file fills, LGWR begins writing to the next available redolog file. When the last available redolog file is filled, LGWR returns to the first redolog file & writes on it.

MULTIPLEXING REDOLOG FILES

LOGFILE

GROUP 1 '/u01/app/oracle/oradata/devdb/A_LOG1.log' SIZE 50M, GROUP 1 '/u02/app/oracle/devdb/redolog/B_LOG1.log' SIZE 50M, GROUP 2 '/u01/app/oracle/oradata/devdb/A_LOG2.log' SIZE 50M, GROUP 2 '/u02/app/oracle/devdb/redolog/B_LOG2.log' SIZE 50M;

A_LOG1 & B_LOG1 are both members of Group 1, A_LOG2, B_LOG2 are both members of Group 2. Each

member in a group must be exactly the same size. Each member of a log file group is concurrently active i.e. concurrently written by LGWR - as indicated by the identical log sequence numbers assigned by LGWR.

At first LGWR writes concurrently to both A_LOG1 & B_LOG1. Then it writes concurrently to both

A_LOG2 and B_LOG2, and so on. LGWR never writes concurrently to members of different groups.

(For ex, A_LOG1 and B_LOG2.

TO CREATE A NEW REDO LOG - GROUP

SQL> alter database add logfile group 1 '/u01/app/oracle/oradata/devdb/redo1a.log' size 50m; Database altered.

SQL> alter database add logfile group 2 '/u01/app/oracle/oradata/devdb/redo2a.log' size 50m; Database altered.

SQL> alter database add logfile group 3 '/u01/app/oracle/oradata/devdb/redo3a.log' size 50m; Database altered.

SQL> select member from v$logfile;

MEMBER

---

/u01/app/oracle/oradata/devdb/redo1a.log /u01/app/oracle/oradata/devdb/redo2a.log /u01/app/oracle/oradata/devdb/redo3a.log

(16)

ADDING A MEMBER IN THE EXISTING GROUP

SQL> alter database add logfile member

'/u02/app/oracle/oradata/redolog/devdb/redo1b.log' to group 1; Database altered.

SQL> alter database add logfile member

'/u03/app/oracle/oradata/redolog/devdb/redo1c.log' to group 1; Database altered.

SQL> alter database add logfile member

'/u02/app/oracle/oradata/redolog/devdb/redo2b.log' to group 2; Database altered.

SQL> alter database add logfile member

'/u03/app/oracle/oradata/redolog/devdb/redo2c.log' to group 2; Database altered.

SQL> alter database add logfile member

'/u02/app/oracle/oradata/redolog/devdb/redo3b.log' to group 3; Database altered.

SQL> alter database add logfile member

'/u03/app/oracle/oradata/redolog/devdb/redo3c.log' to group 3; Database altered.

CREATE REDOLOG GROUP WITH MULTIPLE MEMBERS

SQL> alter database add logfile group 4

('/u01/app/oracle/oradata/devdb/redo4a.log',

'/u02/app/oracle/oradata/redolog/devdb/redo4b.log',

'/u03/app/oracle/oradata/redolog/devdb/redo4c.log') size 50m; Database altered.

DROP A MEMBER FROM A REDOLOG GROUP

SQL> alter database drop logfile member '/u03/app/oracle/oradata/redolog/devdb/redo4c.log'; Database altered.

SQL> alter database drop logfile member '/u02/app/oracle/oradata/redolog/devdb/redo4b.log'; Database altered.

SQL> alter database drop logfile member '/u02/app/oracle/oradata/redolog/devdb/redo4a.log'; alter database drop logfile member '/u03/app/oracle/oradata/redolog/devdb/redo4c.log'

*

ERROR at line 1:

ORA-00361: cannot remove last log member

/u03/app/oracle/oradata/redolog/devdb/redo4c.log for group 4

(17)

DROP A REDOLOG GROUP

SQL> alter database drop logfile group 4; Database altered.

RECREATE DROPPED ONLINE REDOLOG GROUP

Now let’s take a look to recreate online redolog groups. If a group contains only one logfile then you cannot drop that member.

Once we drop redolog group/member, the operating system file is NOT deleted from disk. In this case I have already deleted group 4, but files are existing at Operating System level. So I am using reuse clause here.

SQL> alter database add logfile group 4 ('/u01/app/oracle/oradata/devdb/log4a.log',

'/u02/app/oracle/oradata/redolog/devdb/redo4b.log',

'/u03/app/oracle/oradata/redolog/devdb/redo4c.log') size 50m reuse; Database altered.

You cannot drop a log group with CURRENT status. We can use ALTER SYSTEM command to make other group to current status. Check these parameters (group#, members, status from v$log) view.

SQL> alter system switch logfile;

You cannot drop a log group with ACTIVE status. We can use ALTER SYSTEM command to resolve it. SQL> alter system checkpoint.

RESIZE THE REDOLOG FILES

We cannot resize the redolog files. We must drop the redolog file and recreate them and also cannot drop the redolog file if its status is current or active. We have to change the status to inactive then only we can drop it.

SQL> select group#, status from v$log;

GROUP# STATUS --- --- 1 INACTIVE 2 INACTIVE 3 INACTIVE 4 CURRENT

SQL> alter database drop logfile group 4; alter database drop logfile group 4

*

ERROR at line 1:

ORA-01623: log 4 is current log for instance devdb (thread 1) - cannot drop ORA-00312: online log 4 thread 1: '/u01/app/oracle/oradata/devdb/log4a.log'

(18)

ORA-00312: online log 4 thread 1:

'/u02/app/oracle/oradata/redolog/devdb/redo4b.log' ORA-00312: online log 4 thread 1:

'/u03/app/oracle/oradata/redolog/devdb/redo4c.log'

SQL> alter system switch logfile; System altered.

SQL> select group#, status from v$log;

GROUP# STATUS --- --- 1 INACTIVE 2 INACTIVE 3 CURRENT 4 INACTIVE

SQL> alter database drop logfile group 4; Database altered.

If you do not want to delete the files at operating system level, you will get an error when creating the logfiles with an old name.

SQL> alter database add logfile group 4 ('/u01/app/oracle/oradata/devdb/log4a.log',

'/u02/app/oracle/oradata/redolog/devdb/log4b.log',

'/u03/app/oracle/oradata/redolog/devdb/log4c.log') size 100m; Database altered.

STATUS FROM V$LOG

A log group can be in one of four status.

CURRENT Current redo log, the redo log is active.

ACTIVE Log is active, but it is NOT current log. Required for instance recovery. INACTIVE Log is no longer needed for instance recovery and can be overwritten. UNUSED Redo log just added or just after a RESETLOGS.

STATUS FROM V$LOGFILE

A log file can be in One of four status.

INVALID File is corrupt or missing. - (inaccessible)

STALE File is never been used.

DELETED File is no longer used.

VIEWS FOR REDOLOG

V$LOG Displays the redo file info from the control file

V$LOGFILE Identifies redo log groups and members and member status. V$LOG_HISTORY Contains log history information.

(19)

RELOCATING OR RENAMAMING REDOLOG FILES

You can use operating system commands to relocate redo logs. I am using 11g database environment to relocate redolog files. Let’s start the process.

SQL> select group#, member from v$logfile;

GROUP# MEMBER

--- --- 3 /u02/app/oracle/oradata/crms/redo03.log

2 /u02/app/oracle/oradata/crms/redo02.log 1 /u02/app/oracle/oradata/crms/redo01.log

The redo logs cannot be moved/renamed while the database is online. The database must be in a mount state to move/rename the online redo logs. First shutdown the database and move online redolog files to their new location.

SQL> shut immediate; Database closed. Database dismounted.

ORACLE instance shut down.

$ cd /u02/app/oracle/oradata/crms

$ mv redo01.log /u01/app/oracle/oradata/redolog/crms/redo01.log $ mv redo02.log /u02/app/oracle/oradata/redolog/crms/redo02.log $ mv redo03.log /u03/app/oracle/oradata/redolog/crms/redo03.log

Next we bring up the database into mount mode and issue ALTER DATABASE RENAME FILE statements to update the data dictionary and control files.

SYS> startup mount;

ORACLE instance started. ..

...

Database mounted.

SYS> alter database rename file

'/u02/app/oracle/oradata/crms/redo01.log' to

'/u01/app/oracle/oradata/redolog/crms/redo01.log'; Database altered.

SYS> alter database rename file

'/u02/app/oracle/oradata/crms/redo02.log' to

'/u02/app/oracle/oradata/redolog/crms/redo02.log'; Database altered.

SYS> alter database rename file

'/u02/app/oracle/oradata/crms/redo03.log' to

'/u02/app/oracle/oradata/redolog/crms/redo03.log'; Database altered.

(20)

SYS> alter database open resetlogs; Database altered.

SYS>select group#, member from v$logfile;

GROUP# MEMBER --- --- 3 /u03/app/oracle/oradata/redolog/crms/redo03.log 2 /u02/app/oracle/oradata/redolog/crms/redo02.log 1 /u01/app/oracle/oradata/redolog/crms/redo01.log REDOLOGS RECOVERY

LOSING ONE MEMBER OF AN ONLINE REDOLOG GROUP

SQL> select member from v$logfile where group#=4;

MEMBER --- /u01/app/oracle/oradata/devdb/log4a.log /u02/app/oracle/oradata/redolog/devdb/log4b.log /u03/app/oracle/oradata/redolog/devdb/log4c.log SQL>! mv /u03/app/oracle/oradata/redolog/devdb/log4c.log /u03/app/oracle/oradata/redolog/devdb/log4c.log.bkp

SQL> alter system switch logfile; System altered.

Error message messages appeared in the alert log.

$ tail -f /u01/app/oracle/admin/devdb/bdump/alert_devdb.log

Errors in file /u01/app/oracle/admin/devdb/bdump/devdb_lgwr_20362.trc: ORA-00313: open failed for members of log group 4 of thread 1

ORA-00312: online log 4 thread 1: '/u03/app/oracle/oradata/redolog/devdb/log4c.log' ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory ..

...

ORA-00321: log 4 of thread 1, cannot update log file header

SQL> select group#, member, status from v$logfile where group#=4 order by 1,2;

GROUP# MEMBER STATUS --- --- ---

4 /u01/app/oracle/oradata/devdb/log4a.log

4 /u02/app/oracle/oradata/redolog/devdb/log4b.log

4 /u03/app/oracle/oradata/redolog/devdb/log4c.log INVALID

(21)

SQL> alter database drop logfile member '/u03/app/oracle/oradata/redolog/devdb/log4c.log '; Database altered.

Add a new member to the group.

SQL> alter database add logfile member

'/u03/app/oracle/oradata/redolog/devdb/log4c.log' to group 4; Database altered.

TRIM LISTENER LOG (KEEP LAST 3 MONTHS)

In 10g, the listener.log is $ORACLE_HOME/network/log/listener.log.

In 11g, the default location for the listener log file is the "diag" directory,$ORACLE_HOME/diag. Oracle 11g listener has two log files -- one as an XML file and one as a plain-text file (as was in earlier versions) in the trace directory (it was the log directory in earlier versions).

PROCEDURES AND COMMAND

LSNRCTL> set log_status off

$ cd /u01/app/oracle/diag/tnslsnr/SERVER1/listener/trace/

$ cp listener.log listener_061212.log (according to current date) $ tail -1000 listener.log > new_listener.log

$ mv new_listener.log listener.log

LSNRCTL> set log_status on

TRIM ALERT LOG (KEEP LAST 3 MONTHS)

$ mv alert.log alert_061212.log (according to current date) $ cp alert.log alert_061212.log

In 11g, the "adrci" tool to purge files from the diag dest - (trace files, core dump etc).

REMOVE OLD TRACE FILES IN 10G

SQL> show parameter background_dump_dest; SQL> show parameter core_dump_dest;

SQL> show parameter user_dump_dest; I am removing files 30 days older. $ cd '/location of bdump/’

$ find . -name '*.trc' -mtime +30 -print -exec rm {} \; $ cd '/location of cdump/’

$ find . -name '*.trc' -mtime +30 -print -exec rm {} \; $ cd '/location of udump/’

References

Related documents

For details on the expansion of the rail system in Illinois and its importance to the growth of Chicago, see Paul Wallace Gates, The Illinois Central Railroad and Its

Our examination of the records shows that while the prosecution established through the testimony of SPO2 Sanchez that the sale of the prohibited drug by the accused-appellant

The Lyons High School – Colorado State University Concurrent Enrollment Program is an opportunity to complete challenging college courses while you are still in high school, which

• Compare the test print with the Printech offset printout or known good Printech digital master. Reject if any

Study Study N Patient Follow- Treatment Adherence Mean Definition Adherent Predictors Definition Virologic design characteristics up regimen assessment adherence good/perfect

Partners from North East of Gothenburg: the Community Center Hammarkullen, the Folk High School in Angered, the Library and Citizens’ Advice Bureau operated by the City District of

This problem is solved by determining which data is used by more than one person and storing it on a network server – a central computer that provides a storage device and

societal  levels  with  which  to  analyze  people’s  economic  cost‐benefit  analysis  on  Turkey’s  potential  EU  accession.  Table  3,  taken  from