7 maintaining redo log files. 7-2 objectives explaining the use of online redo log files obtaining...

32
7 7 Maintaining Redo Log Files

Upload: julius-hill

Post on 23-Dec-2015

231 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

77

Maintaining Redo Log FilesMaintaining Redo Log Files

Page 2: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-22

ObjectivesObjectives

• Explaining the use of online redo log files

• Obtaining log and archive information

• Controlling log switches and checkpoints

• Multiplexing and maintaining online redo log files

• Planning online redo log files

• Troubleshooting common redo log file problems

• Explaining the use of online redo log files

• Obtaining log and archive information

• Controlling log switches and checkpoints

• Multiplexing and maintaining online redo log files

• Planning online redo log files

• Troubleshooting common redo log file problems

Page 3: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-33

Using Redo Log FilesUsing Redo Log Files

Redo logfiles

Database

Controlfiles

Data files

• Record allRecord all

changes madechanges made

to the databaseto the database

• Used only forUsed only for

recoveryrecovery

Page 4: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-44

Introduction to Online Redo Log Files

Introduction to Online Redo Log Files

Components:•Redo log group•Online redo log file or member•Archived redo log file•ARCn

Page 5: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-55

Introduction to Online Redo Log Files

Introduction to Online Redo Log Files

Components:•Redo log buffer•LGWR•CKPT

Page 6: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-66

Introduction to Online Redo Log Files

Introduction to Online Redo Log Files

File 1 is written to File A by the ARCn process after the log switch is complete

Page 7: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-77

Introduction to Online Redo Log Files

Introduction to Online Redo Log Files

File 1 and File 3 are written to by the LGWR process simultaneouslyuntil both are full

Page 8: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-88

Redo Log Groups and MembersRedo Log Groups and Members

Group 2Group 2 Group 3Group 3Group 1Group 1

MemberMember

MemberMember

Disk 1Disk 1

Disk 2Disk 2MemberMember

MemberMember MemberMember

MemberMember

Min. 2 groupsMin. 2 groups

Min. 1 and up to 5 members/groupMin. 1 and up to 5 members/group

Page 9: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-99

Redo Log Groups and Members Redo Log Groups and Members

•LGWR concurrently writes to all members of a group

•Log Sequence numbers are written to the group

•Log Sequence number is assigned to a group by Oracle each time: unique id

•Current log number is stored in control file

•LGWR concurrently writes to all members of a group

•Log Sequence numbers are written to the group

•Log Sequence number is assigned to a group by Oracle each time: unique id

•Current log number is stored in control file

Page 10: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1010

Oracle Architecture Oracle Architecture

Database

InstanceSGA

CKPT LGWR DBWR

Database buffercache

Control files

Data files Redo logfiles

Redo logbuffer

ARCH

Parameterfile

Password file

Archived log files

Page 11: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1111

LGWR, Log Switches and Checkpoints LGWR, Log Switches and Checkpoints

LGWR writes from buffer to file when:

•A transaction commits

•Redo buffer is one-third full

•>1MB of changed records

•Timeout occurs (every 3 secs)

•Before DBWR writes buffer to data files

LGWR writes from buffer to file when:

•A transaction commits

•Redo buffer is one-third full

•>1MB of changed records

•Timeout occurs (every 3 secs)

•Before DBWR writes buffer to data files

Page 12: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1212

LGWR, Log Switches and Checkpoints LGWR, Log Switches and Checkpoints

•Log switch: event when LGWR switches to a new group; Oracle then assigns a new sequence number

•DBA can force a switch

Checkpoint:

•Dirty DB buffers written to data files

•Updates headers of data and control files

•Occurs when• Every log switch

• Instance shuts down

• Manually by DBA

•Log switch: event when LGWR switches to a new group; Oracle then assigns a new sequence number

•DBA can force a switch

Checkpoint:

•Dirty DB buffers written to data files

•Updates headers of data and control files

•Occurs when• Every log switch

• Instance shuts down

• Manually by DBA

Page 13: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1313

Without Archiving Without Archiving

BackupBackup Disk failureDisk failure

100 101

t1t1 t2t2

Data files Control files

50 51

Page 14: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1414

50

With ArchivingWith Archiving

BackupBackup

Disk failureDisk failureData files Control

files

50 51100 101

ArchivedArchivedredo logsredo logs

t1t1 t2t2

99

Page 15: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1515

To Archive Or Not? To Archive Or Not?

Oracle can be configured to operate in:

• ARCHIVELOG or NOARCHIVELOG mode

Two ways to archive redo log files:

• Manually or Automatically

LOG_ARCHIVE_START parameter indicates if manual or automatic

Oracle can be configured to operate in:

• ARCHIVELOG or NOARCHIVELOG mode

Two ways to archive redo log files:

• Manually or Automatically

LOG_ARCHIVE_START parameter indicates if manual or automatic

Page 16: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1616

• Server Manager command:

• V$DATABASE:– NAME (select name, log_mode from v$databse)

– LOG_MODE

• V$INSTANCE– ARCHIVER(select archiver from v$instance)

• Server Manager command:

• V$DATABASE:– NAME (select name, log_mode from v$databse)

– LOG_MODE

• V$INSTANCE– ARCHIVER(select archiver from v$instance)

Obtaining Information About Archiving

Obtaining Information About Archiving

SQL>ARCHIVE LOG LIST;SQL>ARCHIVE LOG LIST;

Page 17: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1717

Obtaining Information About Groups

Obtaining Information About Groups

V$THREAD:

• GROUPS

• CURRENT_GROUP#

• SEQUENCE#select groups, current_group#, sequence#

from v$thread;

V$THREAD:

• GROUPS

• CURRENT_GROUP#

• SEQUENCE#select groups, current_group#, sequence#

from v$thread;

Page 18: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1818

Obtaining Information About Groups and Members

Obtaining Information About Groups and Members

V$LOG:

• GROUP#

• MEMBERS

• STATUS

• SEQUENCE#

• BYTESselect group#, sequence#, bytes, members, status

from v$log;

Page 19: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-1919

Obtaining Information About Groups and Members

Obtaining Information About Groups and Members

V$LOGFILE:

• GROUP#

• STATUS

• MEMBERselect * from v$logfile;

STATUS for groups(G) and members (M):

UNUSED(G): never been written to

CURRENT(G): current group

ACTIVE(G): active but not current; needed for recovery

INACTIVE(G): no longer needed for recovery

INVALID(M): file is inaccessible

BLANK(M): file is in use

Page 20: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2020

• Force log switches with the command:

• Control checkpoints with the initialization parameters:

– LOG_CHECKPOINT_INTERVAL

– LOG_CHECKPOINT_TIMEOUTSQL> ALTER SYSTEM CHECKPOINT

• Force log switches with the command:

• Control checkpoints with the initialization parameters:

– LOG_CHECKPOINT_INTERVAL

– LOG_CHECKPOINT_TIMEOUTSQL> ALTER SYSTEM CHECKPOINT

Log Switches and CheckpointsLog Switches and Checkpoints

SQL> ALTER SYSTEM SWITCH LOGFILE;SQL> ALTER SYSTEM SWITCH LOGFILE;

Page 21: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2121

log3a.rdo

Adding Online Redo Log GroupsAdding Online Redo Log Groups

Group 1Group 1 Group 2Group 2 Group 3Group 3

ALTER DATABASE ADD LOGFILE

(‘/DISK3/log3a.rdo’,

‘/DISK4/log3b.rdo’) size 1M;

ALTER DATABASE ADD LOGFILE

(‘/DISK3/log3a.rdo’,

‘/DISK4/log3b.rdo’) size 1M;

log3b.rdolog1a.rdo

log1b.rdo log2b.rdo

Page 22: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2222

Adding Online Redo Log Members

Adding Online Redo Log Members

Group 2Group 2Group 1Group 1

ALTER DATABASE ADD LOGFILE MEMBER

‘/DISK4/log1b.rdo’ TO GROUP 1,

‘/DISK4/log2b.rdo’ TO GROUP 2;

ALTER DATABASE ADD LOGFILE MEMBER

‘/DISK4/log1b.rdo’ TO GROUP 1,

‘/DISK4/log2b.rdo’ TO GROUP 2;

log2b.rdolog2a.rdolog1b.rdolog1a.rdo

Page 23: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2323

How to RelocateOnline Redo Log Files

How to RelocateOnline Redo Log Files

1. Shut down the database.

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

3. Mount the database.

4. Execute the ALTER DATABASE RENAME FILE command.

ALTER DATBASE RENAME FILE ‘fname’ TO ‘fname’

5. Open the database.

1. Shut down the database.

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

3. Mount the database.

4. Execute the ALTER DATABASE RENAME FILE command.

ALTER DATBASE RENAME FILE ‘fname’ TO ‘fname’

5. Open the database.

Page 24: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2424

Dropping Online Redo Log Groups

Dropping Online Redo Log Groups

Group 1Group 1 Group 2Group 2 Group 3Group 3

ALTER DATABASE DROP LOGFILE

GROUP 3;

ALTER DATABASE DROP LOGFILE

GROUP 3;

log1a.rdo log2a.rdolog3b.rdo

log3a.rdo

log1b.rdo log2b.rdo

Page 25: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2525

Dropping Online Redo Log Members

Dropping Online Redo Log Members

Group 2Group 2Group 1Group 1

ALTER DATABASE DROP LOGFILE MEMBER

‘/DISK4/log2b.dbf’;

ALTER DATABASE DROP LOGFILE MEMBER

‘/DISK4/log2b.dbf’;

log1a.rdo

log2b.rdolog1b.rdo log2a.rdo

Page 26: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2626

Clearing Online Redo Log FilesClearing Online Redo Log Files

ALTER DATABASE CLEAR LOGFILE

‘/DISK3/log2a.rdo’;

ALTER DATABASE CLEAR LOGFILE

‘/DISK3/log2a.rdo’;

If it gets corrupted. If it gets corrupted.

ExampleExample

Page 27: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2727

Online Redo Log ConfigurationOnline Redo Log Configuration

Group 1Group 1 Group 2Group 2 Group 3Group 3

MemberMember

MemberMember

Disk 3Disk 3Disk 2Disk 2Disk 1Disk 1

MemberMember

MemberMember

MemberMember

Page 28: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2828

Possible LGWR ErrorsPossible LGWR Errors

• One member of a group of two or more is not available.

• All members of the next group are not available.

• All members of the current group are not available.

• One member of a group of two or more is not available.

• All members of the next group are not available.

• All members of the current group are not available.

Page 29: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-2929

OMF and Log FilesOMF and Log Files

•You can create as many redo log groups as you need, bounded by MAXLOGFILES setting (when database was created).

•You can multiplex each of those groups with up to five additional OMF members (bounded by the MAXLOGMEMBERS). D

•Different redo log group members are created in different locations, as defined by parameters such as db_create_online_log_dest_n

•You can create as many redo log groups as you need, bounded by MAXLOGFILES setting (when database was created).

•You can multiplex each of those groups with up to five additional OMF members (bounded by the MAXLOGMEMBERS). D

•Different redo log group members are created in different locations, as defined by parameters such as db_create_online_log_dest_n

Page 30: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-3030

OMF and Log Files (cont.)OMF and Log Files (cont.)Examples

•ALTER DATABASE ADD LOGFILE; or

•ALTER DATABASE ADD LOGFILE GROUP 3 SIZE 300M; - to add a log group

•ALTER DATABASE DROP LOGFILE GROUP 1; - to drop a log group (may not be current log group)

•Not possible to add an additional log group member that is an OMF

•Can drop an OMF redo log member:ALTER DATABASE DROP LOGFILE MEMBER.... Oracle will remove the dropped redo log member.

Examples

•ALTER DATABASE ADD LOGFILE; or

•ALTER DATABASE ADD LOGFILE GROUP 3 SIZE 300M; - to add a log group

•ALTER DATABASE DROP LOGFILE GROUP 1; - to drop a log group (may not be current log group)

•Not possible to add an additional log group member that is an OMF

•Can drop an OMF redo log member:ALTER DATABASE DROP LOGFILE MEMBER.... Oracle will remove the dropped redo log member.

Page 31: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-3131

OMF and Log Files (cont.)OMF and Log Files (cont.)

Example Create Database Command:CREATE DATABASE mydb DATAFILE SIZE 500M LOGFILE

GROUP 1 SIZE 10M , GROUP 2 SIZE 10M DEFAULT TEMPORARY TABLESPACE temp

TEMPFILE SIZE 100M UNDO TABLESPACE undotbs1 DATAFILE SIZE 50M MAXLOGFILES = 5 MAXLOGMEMBERS = 5 MAXDATAFILES = 600 NOARCHIVELOG;

Example Create Database Command:CREATE DATABASE mydb DATAFILE SIZE 500M LOGFILE

GROUP 1 SIZE 10M , GROUP 2 SIZE 10M DEFAULT TEMPORARY TABLESPACE temp

TEMPFILE SIZE 100M UNDO TABLESPACE undotbs1 DATAFILE SIZE 50M MAXLOGFILES = 5 MAXLOGMEMBERS = 5 MAXDATAFILES = 600 NOARCHIVELOG;

Page 32: 7 Maintaining Redo Log Files. 7-2 Objectives Explaining the use of online redo log files Obtaining log and archive information Controlling log switches

7-7-3232

SummarySummary

• Controlling log switches and checkpoints

• Administering online redo log files

• Controlling log switches and checkpoints

• Administering online redo log files