|
|
|
Oracle Database Administration
Oracle Database Information Page
Oracle Database Recovery
Implementing a Restored and Recovery Strategy
Phase I - Steps for Diagnosing a Problem
- Determine if the database instance is available and the database is open.
- Attempt to start the instance and open the database.
- Shut down the instance if problems occur while starting it or
opening the database.
- Check the trace files for possible problems.
- Check the alert_SID.log file for the possible problems.
- Determine the appropriate recovery method by asking the following
questions for each scenario:
- Which recovery operations are available?
- Complete Recovery
Closed Database Recovery
Open Database, Offline Tablespace Recovery
Open Database, Offline Tablespace, Individual Datafile Recovery
- Incomplete Media Recovery
Cancel Based Recovery
Time Based Recovery
Change Based Recovery
- Which recovery operations are appropriate for the particular problem?
- Are disaster recovery procedures in place?
- What need to be restored to proceed with recovery?
Phase II - Restore Appropriate Files
- Determine which file(s) to restore
- Determine what state the instance and database must be in to perform
the recovery.
Phase III - Recover Database
- Perform the appropriate method of recovery
Phase IV - Backup Database
- Determine if another full offline backup is required.
Time Based Recovery
This is used to recover the database up to a specific point in time:
- When data is lost; check the alert file for the approximate time of the error.
- When part of a non-mirrored online redo log becomes corrupt and
the approximate time of the corruption is known
- Shutdown the listener.
- Shutdown the database.
- Restored all datafiles from last night backup(except the control files and redo log files).
- Goto svrmgrl
- svrmgrl> connect internal
- svrmgrl> startup mount
- svrmgrl> recover database until time 'YYYY-MM-DD:24:MM:SS'
- svrmgrl> alter database open resetlogs;
- svrmgrl> shutdown
- svrmgrl> startup
- Do an offline backup
Recently, I had to recover a database using time based recovery but due to some corrupted nightly backup files, I was not able to do a normal recovery.
The error message was:
SVRMGR> recover database until time 1998-06-03:10:18:00
ORA-00283: recovery session canceled due to errors
ORA-01122: database file 3 failed verification check
ORA-01110: data file 3: '/dbase/u04/oradata/PRD/temp01PRD.dbf'
ORA-01203: wrong incarnation of this file - wrong creation SCN
The way to get around this is:
- Shutdown the listener.
- Shutdown the database.
- Restored all datafiles from last night backup
(except the control files and redo log files).
- Goto svrmgrl
- svrmgrl> connect internal
- svrmgrl> startup mount
- svrmgrl> select * from v$recover_file:
it displayed 3 datafile that are not recoverable:
- /dbase/u04/oradata/PRD/temp01PRD.dbf
- /dbase/u04/oradata/PRD/ndx01BUD.dbf
- /dbase/u04/oradata/PRD/ndx01HLP.dbf
- svrmgrl> alter database datafile '/dbase/u04/oradata/PRD/temp01PRD.dbf' offline drop;
repeat for the other 2 files.
- svrmgrl> recover database until time 'YYYY-MM-DD:24:MM:SS'
- svrmgrl> alter database open resetlogs;
- svrmgrl> drop tablespace TEMP including contents;
svrmgrl> drop tablespace BUD_NDX including contents cascade contraints;
- Create new tablespaces.
- Create new indexes.
- Shutdown the database.
- Startup the database.
- Do an offline backup.
Oracle Database Migration
Two ways to move a database:
- For a small database.
- Do an Export.
- Create a new empty database.
- Do an Import.
- For a large database (in the old system):
- svrmgrl>alter database backup controlfile to trace.
- Take a Cold Backup.
For a large database (in the new system):
- Restore on the new system (all the datafiles and redo log files).
Modified file name if necessary.
- Create New initSID file.
- Modify the trace file from step 1 to reflect changes in file names
and change the database name if desired.
- Set the ORACLE_SID to the new SID.
- Run the sql from step 1
- Open the database.
Oracle Database Backup
3 ways of doing database backup:
- Full Offline(Cold) Backup
- Full Online(Hot) Backup - archiving must be on
- Export Utility Backup
Oracle Database Archiving
To Turn Archive Log On
- Modified the initSID.ora file to uncomment these 3 lines:
log_archive_start = true
log_archive_dest = disk$rdbms:[oracle.archive]
log_archive_format = "%S.arc"
- Goto svrmgrl
svrmgrl> connect internal
svrmgrl> startup mount pfile=initSID.ora
svrmgrl> alter database archivelog;
svrmgrl> alter database open
Oracle Stored Procedure
To Create a Procedure
in sqlplus
sql> create procedure scott.sal_incr
sql> (v_empno IN NUMBER,
sql> v_incr IN NUMBER)
sql> as begin
sql> update scott.emp
sql> set sal = sal + v_incr
sql> where empno = v_empno;
sql> end;
To Execute a Procedure
in sqlplus
sql> exec sal_incr(v_empno, v_incr);
To look for User Procedure
in sqlplus
sql> select * from user_objects where object_type = 'PROCEDURE';
To look at Procedure Code
in sqlplus
sql> select text from user_source where name = 'PROCEDURE_NAME';
Oracle Database Monitoring Scripts
Check for overextended tables or indexes
select substr(owner,1,10) "Owner",
substr(segment_name,1,10) "SegName",
segment_type "SegType",
substr(tablespace_name,1,10) "Tablespace",
substr(extents,1,4) "#Ext",
max_extents "Max",
initial_extent "InitExt",
next_extent "NextExt"
from sys.dba_segments
where extents > 5
and (segment_type = 'TABLE'
or segment_type = 'ROLLBACK'
or segment_type = 'INDEX')
and owner like '%DBA'
order by owner, extents desc, segment_name;
Check for full tablespace
select substr(owner,1,10) "Owner",
substr(segment_name,1,14) "SegName",
next_extent "NextExt",
substr(tablespace_name,1,14) "Tablespace"
from dba_segments ds
where next_extent >
(select max(bytes)
from dba_free_space
where tablespace_name=ds.tablespace_name);
Check for tablespace fragmentation
select TABLESPACE_NAME,
count(*) FREE_SEGMENTS
from dba_free_space
group by TABLESPACE_NAME
having count(*) > 10;
Check for free space by tablespace monitoring
select substr(b.file_id,1,3) "FID",
substr(b.file_name,23,16) "Filename",
substr(b.tablespace_name,1,10) "Tablespace",
b.bytes "# Bytes",
(b.bytes - sum(nvl(a.bytes,0))) "# Used",
sum(nvl(a.bytes,0)) "# Free",
(sum(nvl(a.bytes,0))/(b.bytes)) * 100 "% Free"
from sys.dba_free_space a, sys.dba_data_files b
where a.file_id(+) = b.file_id
group by b.tablespace_name, b.file_id, b.file_name, b.bytes
order by b.tablespace_name;
Tablespace Disk Usages
select tablespace_name,
sum(bytes) "Bytes Consumed",
count(*) "Number of Objects"
from dba_segments
group by tablespace_name;
select tablespace_name,
sum(bytes) "Bytes Alloc"
from dba_data_files
group by tablespace_name;
Check for redo log contention
select name,
gets,
misses,
sleeps,
immediate_gets,
immediate_misses
from v$latch
where name in ('redo allocation', 'redo copy');
Check for rollback segments contention
select substr(r.name,1,10) "Rollback",
s.gets,
s.waits,
round (100 * s.waits/s.gets) "%Cont"
from v$rollstat s, v$rollname r
where s.usn = r.usn
and round (100 * s.waits/s.gets) > 1;
Check for rollback segments monitoring
select substr(name,1,10) "Rollback",
optsize,
shrinks,
aveshrink,
wraps,
extends,
rssize,
writes
from v$rollstat s, v$rollname r
where s.usn = r.usn;
select substr(segment_name,1,14),
substr(name,1,36),
substr(file_id,1,6),
bytes,
substr(tablespace_name,1,10)
from dba_rollback_segs,
v$datafile
where v$datafile.file# = dba_rollback_segs.file_id;
Check for transaction per rollback segments monitoring
select r.name rr,
nvl(s.username,'no transaction') us,
s.osuser os,
s.terminal ts
from V$LOCK l, V$SESSION s, V$ROLLNAME r
where l.sid =s.sid(+)
and trunc(l.ID1/65536) = r.usn
and l.type = 'TX'
and l.lmode = 6
order by r.name;
Check for user that use SYSTEM tablespace for work area
select substr(username,1,14) "User",
user_id "User ID",
substr(default_tablespace,1,14) "Default TSpace",
substr(temporary_tablespace,1,14) "Temp TSpace"
from dba_users
where temporary_tablespace = 'SYSTEM';
Check user privileges
select *
from sys.dba_role_privs
where GRANTEE like '%';
select * from sys.dba_sys_privs
where GRANTEE like '%';
select * from sys.dba_tab_privs
where GRANTEE like '%';
select username,
program,
sid,
serial#
from v$session;
User Disk Usages
select owner,
sum(bytes) "Bytes Consumed",
count(*) "Number of Objects"
from dba_segments
group by owner;
Check for tablespace coalesce
select tablespace_name, percent_blocks_coalesced
from dba_free_space_coalesced
order by percent_blocks_coalesced;
alter tablespace XXX coalesce;
select * from dba_free_space
where tablespace_name = 'XXX';
Check for db_buffer
select name,
value
from v$sysstat
where name in ('consistent gets', 'db block gets', 'physical reads');
select * from dba_ts_quotas
where BYTES = MAX_BYTES;
Check for Freelist
select * from v$waitstat;
Check for segments running out of extents
select a.owner,
table_name "table",
a.tablespace_name "tablespace",
'T' "T/I",
a.max_extents max_exts,
b.extents curr_exts
from sys.dba_tables a,
sys.dba_segments b
where table_name = segment_name
and a.max_extents - b.extents <= 10
union
select a.owner,
index_name "index",
a.tablespace_name "tablespace",
'I' "T/I",
a.max_extents max_exts,
b.extents curr_exts
from sys.dba_indexes a,
sys.dba_segments b
where index_name = segment_name
and a.max_extents - b.extents <= 10;
Resize datafiles
alter database datafile 'XXX' resize 30M;
Collect session statstics
select username,
to_char(sysdate - (HSECS - s.value)/(3600*100*24),
'DD-MM-YYYY HH24:MI:SS')
from v$sesstst S,
v$session SE,
v$timer
where SE.SID = S.SID
and statistic#=14
and username is not null;
Shared Pool Information
select sum(pins) pins,
sum(reloads) reloads
from v$librarycache;
select sum(gets) gets,
sum(getmisses) getmisses
from v$rowcache;
Oracle Database Other Issues
Connection
To restrict other users to the database.
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM DISABLE RESTRICTED SESSION;
|