How to config (no)archivelog mode and manage archive log files by RMAN (Updated to 10G)

This article describes how to switch archivelog/noarchivelog mode in Oracle,Also
it give a short introduction on how to maintain archivelog files using RMAN.

Note:

In Oracle Enterprise Manager , we can switch to archivelog

mode easily.But, It's still useful to know how to implement

it using SQLPLUS.


Details:
1. Invoke SQLPLUS, issue the following command:

SQL> archive log list

From the output, we can get these information:

. Whether current database is running under archivelog

mode ;

. The store location of archivelog files ;

. The current and next SCN


2. If current database isn't running under archivelog mode,

please finish the following operations to switch to

archivelog mode:

For 9i:

SQL> show parameter spfile;

If the result shows the directory of spfile's location

is not null,which represents current initialization

parameter file is spfile, otherwise is pfile.

SQL> create pfile from spfile;
SQL> shutdown immediate;
SQL> exit

Open the init<sid></sid>.ora from this location:
UNIX: $ORACLE_HOME/dbs
Windows: $ORACLE_HOMEdatabase

Add or edit the following rows, for example:

log_archive_dest_n(n=1,2,3,.....) ='Location=...'
log_archive_start=true

Note:
1. Change the directory to actual direcotry of

your environment;
2. Create the directory first if the directory

doesn't exist.

Invoke sqlplus(use SYS with sysdba privilege or

use OS authentication)

SQL> startup mount pfile='/u01/oracle/10gdb/

orcl/dbs/init<sid></sid>.ora'
SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list (Check the output)
SQL> alter system switch logfile;
(check whether a new archivelog file has been

generated under your appointed dir)
SQL> create spfile from pfile='/u01/oracle/10gdb

/orcl/dbs/init<sid></sid>.ora'
SQL> shutdown immediate;
SQL> exit

Invoke sqlplus again:
SQL> startup (spfile will be used this time)


For 10G:

By default, 10G use spfile. spfile is a binary file so

that we can't modify it. we must use a pfile based

on this spfile and modify this pfile.

SQL> create pfile from spfile;

Open the init<sid></sid>.ora from this location:
UNIX: $ORACLE_HOME/dbs
Windows: $ORACLE_HOMEdatabase

Because the parameter 'log_archive_start' is obsolete,

if we find this parameter from init<sid></sid>.ora, we should delete

it or remark it.

In 10G, You can have two available solutions about how

to store archivelog files:

. Keeping the old store mode (log_archive_dest_n);

. Using flash recovery area instead of defining old

parameters (log_archive_dest_n);

In order to use flash recovery area, You need to

define:

db_recovery_file_dest= ...
db_recovery_file_dest_size=...


Steps:

SQL> alter system set db_recovery_file_dest=

'...' scope=spfile;
SQL> alter system set db_recovery_file_dest_size=2G

scope=spfile;
SQL> create pfile from spfile;
SQL> shutdown immediate;
SQL> exit

Invoke sqlplus again:
SQL> startup mount pfile='xxx'
SQL> alter database archivelog;

the following sql statement is optional:
SQL> alter database flashback on;

Note:
If you also want to enable flashback,pleas add the

following parameter from init<sid></sid>.ora:
db_flashback_retention_target=1440

(1440 means database will save last 24 hours'

operation in order to implement flashback)

SQL> archive log list

SQL> alter system switch logfile;
(check whether a new archive log has been

generated under your appointed dir)
SQL> alter database open;
SQL> create spfile from pfile='xxx'
SQL> shutdown immediate;
SQL> exit

Invoke sqlplus again:
SQL> startup (spfile will be used this time)


3. If current database is running under archivelog mode,

please finish the following operations to switch to

noarchivelog mode (10G)

Steps:
1. Backup all archivelog files first ;

2. Invoke sqlplus:

SQL> create pfile from spfile;
SQL> shutdown immediate;
SQL> exit

Open the init<sid></sid>.ora from this location:
UNIX: $ORACLE_HOME/dbs
Windows: $ORACLE_HOMEdatabase

delete or remark these lines:
log_archive_dest_n=...
db_recovery_file_dest=...
db_recovery_file_dest_size=...
db_flashback_retention_target=...

Invoke sqlplus:

SQL> startup mount pfile='xxx'
# this operation will delete all flashback files
SQL> alter database flashback off
SQL> alter database noarchivelog;
SQL> alter database open;
SQL> create spfile from pfile='xxx'
SQL> shutdown immediate;
SQL> exit

Now, you can delete all archive log files safely.

sometimes, there will be large log or trace files

under $ORACLE_BASE/admin/sid/bdump(udump),
delete them also.

Invoke sqlplus again:
SQL> startup (spfile will be used this time)


4. Using RMAN to manage archivelog files

Usually, the value for parameter 'db_recovery_file_dest_size'

is too small to hold so much archive log files. we must

define a reasonable policy to delete unuseful archive log files.

Please read RMAN related document first.

Refer:
http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10734/toc.htm


Short Introduction:

. Finish at least one full database backup first;

for example: (10G)

run{
allocate channel c1 type disk format 'xxx/full%u_%s_%p.bak'
maxpiecesize 10 M;
allocate channel c2 type disk format 'xxx/full%u_%s_%p.bak'
maxpiecesize 10 M;
allocate channel c3 type disk format 'xxx/full%u_%s_%p.bak'
maxpiecesize 10 M;
delete noprompt obsolete;

# Backup full database
backup filesperset = 20 keep until time 'SYSDATE+30' logs as

BACKUPSET tag 'fullbak' database include current controlfile;
sql'alter system archive log current';
release channel c1;
release channel c2;
release channel c3;
}
allocate channel for maintenance type disk;
delete noprompt obsolete device type disk;
release channel;

# List backup
list backup;

. Write an archivelog rman backup script and run it termly;

for example: (10G)

run{
allocate channel c1 type disk ;
allocate channel c2 type disk ;
allocate channel c3 type disk ;
sql'alter system archive log current';

backup filesperset = 20 as BACKUPSET tag 'archivebak'

archivelog alldelete all input format

'/xxxarch%u_%s_%p.bak';
release channel c1;
release channel c2;
release channel c3;
}

# List backup
list backup of archivelog all;


. Common useful RMAN commands:

Crosscheck ARCHIVELOG xxx

(xxx means rman log sequence)

# Crosscheck backupsets
CROSSCHECK BACKUPSET xxx

(xxx means backupset number)

# crosschecks backup sets and image copies
CROSSCHECK BACKUP;

# Crosscheck all(backupsets and archive log files)
CROSSCHECK BACKUPSET;
CROSSCHECK COPY;


DELETE NOPROMPT ARCHIVELOG xxx

(xxx means rman log number)

Delete noprompt backupset xxx

(xxx means backupset number)

# Batch remove archivelog files
Delete noprompt archivelog until sequence=xxx;

# Job: Delete obsolete
DELETE NOPROMPT OBSOLETE;

# Job: Delete all unavailable backupsets and archivelogs:
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT EXPIRED COPY;

你可能感兴趣的:(update)