Professional Documents
Culture Documents
DBA Tasks - Imp-Notes - 2
DBA Tasks - Imp-Notes - 2
Visual
LDAP Storage PL/SQL
Basic
These are my personal Windows Tables OEM
notes that I use as a
quick help in my work. UML Net8 Portal
You are welcome to SQL Server perl Performance OLAP
read them.
Vmware PHP/MySQL User Mgmt
(Disclaimer: I have not fully
checked my notes for errors. More technical pages here
They are meant for personal
reference only).
Top-level
Contents of
home
current page
page
Contents
Misc. tips
In parameter file:
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
log_archive_start = true
log_archive_dest_1 = "location=/u01/oradata/db/arch"
log_archive_format = arch_%t_%s.arc
%s = redo log sequence number %t = thread number
LOG_ARCHIVE_MAX_PROCESSES=3;
Remove archivelog mode in 9i: same as above, but " noarchivelog" and "log_archive_start=false"
alter database noarchivelog;
alter system set log_archive_start = false scope = spfile;
Some commands:
ARCHIVE LOG LIST
SELECT SEQUENCE#, DECODE(STATUS, 'CURRENT', '<--', ' '), STATUS, ARCHIVED,
DECODE(ARCHIVED, 'NO', '<--', ' ')
FROM V$LOG;
ALTER SYSTEM SWITCH LOGFILE; -- Equivalent to the following command
ALTER SYSTEM ARCHIVE LOG CURRENT;
ALTER SYSTEM ARCHIVE LOG STOP; --> stops the ARCH process.
ALTER SYSTEM ARCHIVE LOG START TO 'dest'; -- Redirect archived log files
ALTER SYSTEM ARCHIVE LOG START; -- Restart the archiver after it has failed (for example
after disk full)
SHOW PARAMETER ARCHIVE;
Views
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
select log_mode from v$database;
Database in ARCHIVELOG or NOARCHIVELOG mode.
select archiver from v$instance;
Archiver process has started or not
V$ARCHIVED_LOG
historical archived log information from the control file. If recovery catalog:
RC_ARCHIVED_LOG view.
First change and next change refer to the changes contained inside the archived log.
Completion date indicates date/time of completion of archiving.
Size in Kbytes is (blocks * block_size / 1024)
V$ARCHIVE_DEST
Information on current instance and archive destinations
V$ARCHIVE_PROCESSES
Information about archive processes
V$BACKUP_REDOLOG
Information about backups of archived logs. If recovery catalog: RC_BACKUP_REDOLOG
view.
V$LOG
Information on online redo log groups. Shows which logs have to be archived. Too many
unarchived redo logs indicates a problem with the archiver (or else the database is
in NOARCHIVELOG mode).
V$LOG_HISTORY
Log history information
Backup
Analysis:
Recommendations:
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Communicate my strategy to managers (include signatures) and to collegues
See the golden rule in the miscellaneous section
Physical hot backup (datafile by datafile, but all of a tablespace is in backup mode)
alter tablespace x begin backup;
-- backup associated data files
alter tablespace x end backup;
alter system archive log current;
-- backup archived log files
alter database backup controlfile to 'backup_ctrlfile.ctl' reuse; --binary
alter database backup controlfile to trace; -- SQL file in USER_DUMP_DEST
There is no need to backup on-line redo logs. And it can be dangerous when restoring because the
current on-line redo logs could be over-written.
Restore
Recovery
Recovery situations
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Note that if the database was closed when the redo logs were lost, then there is no
problem. If a redo log was already archived, then there is no problem.
Archived log file
This only affects the ability to restore the database. Do a full backup of the database
as soon as possible.
Password file
Recreate the password file
Init file
Restore init file from a backup.
Table accidentally dropped
Incomplete recovery of the whole database or tablespace point-in-time recovery or
import utility
Recovery
If not system or rollback tablespace, then put the tablespace offline and recover
alter tablespace t offline temporary;
recover tablespace t;
alter tablespace t online;
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Just datafile:
recover datafile 'd';
If incomplete recovery (not all archived logs available and/or on-line redo logs not available), then
alter database open resetlogs; Do a backup asap. All transactions in the missing archived logs and
the redo logs are lost. Open resetlogs is always needed for a database in noarchivelog mode.
If old, backed-up on-line redo logs are used, do "open resetlogs" anyway so that the archived log
time-lines are not duplicated, with possible confusion if another restore is needed.
IMP, EXP
Exports can be done in table, user or full mode. A query mode exists too.
EXP PARFILE=parms_exp.txt
FILE=files\exp_file
LOG=files\exp_log_file
USERID=user@SID (password entered when executing. User SYS for full)
FULL=Y (Either put FULL=Y or put OWNER=..)
OWNER=the_owner (just one schema)
TABLES=(tablename,tablename)
CONSTRAINTS=Y
BUFFER=1000000
CONSISTENT=Y (necessary if there are a lot of updates during export)
FILE=files\exp_file
LOG=files\imp_log_file
USERID=user@new_SID (password entered when executing. User SYS for full)
FULL=Y (Either put FULL=Y or put FROMUSER/TOUSER)
(create database before full import)
FROMUSER=old_user
TOUSER=new_user (generally the same)
TABLES=(tablename,tablename)
GRANTS=Y
INDEXES=Y
ROWS=Y (if N, then no data is imported, but the tables are created)
BUFFER=1000000
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
SHOW=Y (this does NOT import, but just shows what is in the dump file. Be careful because
it says "successfull" but nothing is imported.)
the_param_file
FILE=the_dump_file_name
LOG=the_log_file_name
OWNER=the_owner_of_the_schema
CONSTRAINTS=Y
BUFFER=28000000
consistent=Y
EXP /@the_sid
PARFILE=the_param_file
RMAN
A channel ~ process.
Catalog preferred. But not in target database.
Packages:
DBMS_RCVCAT
DBMS_RCVMAN
Packages for recovery catalog. Created by scripts dbmsrman.sql and prvtrmns.plb.
DBMS_BACKUP_RESTORE
Package for link Oracle-OS. Created by scripts dbmsbkrs.sql and prvtbkrs.plb.
Types of backups
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Incremental backup: needs a full (level 0) backup first
OS backup, separate from RMAN, is necessary for parameter files and password files.
For a database in noarchivelog mode, shutdown and startup mount first.
Commands
CONTROL_FILE_RECORD_KEEP_TIME
Time during which the control files keep the information. Default is 7 (days). Set the
parameter to a value creater than the synchronization period.
RMAN
RMAN TARGET user/pw@db [RCVCAT rman/rman@the_catalog_db ]
Connect to rman for a database in interactive mode. No username is equivalent to sysdba.
The connection to the recovery catalog is optional.
RMAN TARGET ... RCVCAT ... CMDFILE script_file [MSGLOG output_file [APPEND]]
Connection to RMAN for batch.
REGISTER DATABASE;
Target must be mounted or open. Uses DBID as identifier. In case of cloned databases, use
another recovery manager on another schema to manage clones.
RESET DATABASE;
Use this after a point in time recovery (when the database was opened with "resetlogs"). This
creates a new "incarnation" number.
RESET DATABASE TO INCARNATION id;
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Reset database to cancel the effects of "resetlogs". The id is taken from the list (see next
command).
LIST INCARNATION OF DATABASE;
List the incarnations.
RESYNC CATALOG [FROM CONTROLFILECOPY control-file-name];
Resynchronize the catalog with the control files. This is especially needed after a change of
structure of the database (new file, new data file or new rollback segment). Also stores the
redo log changes, the archived logs and the backup history. The resynchronization is
automatic if backups and restores are done with a connection to the recovery catalog.
RESYNC CATALOG FROM BACKUP CONTROLFILE 'control-file-name';
Resynchronize the catalog with a backup control file in case of loss of the catalog.
CATALOG { ARCHIVELOG | DATAFILECOPY | CONTROLFILECOPY }'...' TAG = '...';
Add a tag.
ALLOCATE CHANNEL name { TYPE=DISK | TYPE='type of tape' | NAME='...' } options;
Define a process
ALLOCATE CHANNEL FOR DELETE { TYPE=DISK | TYPE='type of tape' | NAME='...' } options;
Define a process for delete
Some views
v$session_longops
Long operations (not just backups)
v$session_wait
Session locks (not just backups)
v$archived_log
List of archived logs
v$backup_corruption
Corrupted blocs during backup
v$copy_curruption
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Corrupted blocs sur copy
v$backup_datafile
v$backup_redolog
Archived logs in the backup sets
v$backup_set
Created backup sets
v$backup_piece
Backup pieces in the backup sets
v$backup
Tablespaces in hot backup mode: hot backup mode should NOT be active for RMAN.
Allocate a channel
Mount the database, or keep open and put lost datafiles offline
Set new name if necessary:
SET NEWNAME FOR DATAFILE {'old_name' | number } TO 'new_name';
If "newname" was used (or copies), then switch to the new files:
SWITCH DATAFILE number_or_new_name;
Allocate a channel
Mount the database (i.e. shutdown and startup mount)
Note that the control files must be restored too.
RESTORE CONTROLFILE TO 'location';
RESTORE DATABASE;
SQL "ALTER DATABASE OPEN RESETLOGS";
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Restore (point in time)
Allocate a channel
Mount the database
Set the time (assuming NLS_DATE_FORMAT='YYYY-MM-DD:HH24:MI:SS'):
SET UNTIL TIME = 'yyyy-mm-dd:hh:mm:ss';
Open with resetlogs option. Note that this is a new reincarnation. Do a new backup
immediately.
SQL "ALTER DATABASE OPEN RESETLOGS";
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Standby Database
Preparations:
Add an entry for the standby database in the TNSNAMES.ORA (sid=.. or service_name=...) on the
primary site and in the LISTENER.ORA on the standby site.
Note that the DB_NAME must be the same for both the primary and the standby databases.
1. Copy datafiles
alter tablespace ... begin backup;
copy
alter tablespace ... end backup;
2. Create standby controlfile and copy to standby site. See v$controlfile for file locations.
alter database create standby controlfile as '$ORACLE_BASE/standby_<SID>.ctl' reuse;
select 'rcp ',
'$ORACLE_BASE/standby_<SID>.ctl',
' oracle@<remote_server>:' || substr(name, 1, 100)
from v$controlfile;
4. Mount:
STARTUP NOMOUNT;
ALTER DATABASE MOUNT STANDBY DATABASE; -- ALTER DATABASE MOUNT won't work anyway
[ALTER DATABASE RENAME FILE 'old_name' TO 'new_name';] -- if needed (or use conversion
initialization parameters)
RECOVER [AUTOMATIC] [FROM '.../arch'] STANDBY DATABASE; -- This applies archived logs that
were transferred manually
5. Managed recovery mode / open in read-only. Receives the archived logs via Net8. You can go
from open read-only to managed standby (the database is closed) only if there are no connections.
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
ALTER DATABASE OPEN READ ONLY; -- Open in read-only, but does not apply the archved
logs
RECOVER MANAGED STANDBY DATABASE [TIMEOUT integer]; -- Automatically applies archved logs
that are sent
6. Tell main (primary) database where to archive. Remember to modify the init.ora. Note that it
may still be necessary to shutdown/startup for archived logs to be sent automatically.
-- modify init.ora and add log_archive_dest_2 = 'service=... OPTIONAL reopen=60'
ALTER SYSTEM SET log_archive_dest_2 = 'service=... OPTIONAL reopen=60';
ALTER SYSTEM SET log_archive_dest_state_2 = DEFER;
ALTER SYSTEM SET log_archive_dest_state_2 = ENABLE;
If the standby database is stopped, then there is a gap. Copy the files manually, then:
RECOVER STANDBY DATABASE;
RECOVER MANAGED STANDBY DATABASE;
N.B. The backup of a database in managed recovery is not consistent, but the backup of a database
in read-only mode is consistent.
If a no-loggin operation occurred on the master database, then copy the database from the master
to the standby:
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
Start the standby database:
STARTUP NOMOUNT;
ALTER DATABASE MOUNT STANDBY DATABASE;
RECOVER STANDBY DATABASE
startup nomount
alter database mount standby database;
select 'alter database datafile ', file#, ' end backup;' from v$backup where status
= 'ACTIVE';
Last log file that was created (main) or applied (standby). If the sequence number is lower
than the sequence of v$archived_log (see below) on the standby database, then the gap must
be closed.
select max(sequence#) from v$archived_log;
Last log created (on main database); should be the same as the next.
select max(sequence#) from v$archived_log where trim(name)
in (select trim(destination) from v$archive_dest where target = 'STANDBY');
Last log transferred (run on standby); should be the same as the previous. A gap in sequence
numbers indicates that there was a gap in the transmission of the archived logs via sql-net.
select status, sequence# from v$log;
The sequence numbers of the redo logs.
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
(Needs Enterprise Edition) These notes from 9i documentation.
The operating system-dependent (OSD) components contains two primary subcomponents: Cluster
Manager (CM) and Interprocess Communication (IPC) software (UNIX specific; for windows,
comes with Oracle installation).
The control file, server parameter file, and all datafiles are shared; they reside on a shared cluster
file system or on shared disks. Each instance has its own redo log files, with shared access (names
include the instance number: db_redo1_1 db_redo1_2 for instance 1, db_redo2_1 db_redo2_2 for
instance 2). The files must be shared in a cluster file system environment or must be shared raw
devices in UNIX environments, or a shared logical partition in Windows environments.(NMI&U).
Disk setup needs extra care: see Oracle documentation. Installation is done on one node; the OUI
copies to the other nodes. This includes patches, etc.
To create a data with DBCA, use the "Oracle cluster database" option. If nodes are missing in the
list, perform diagnostics.
Use the srvconfig command to import or export the contents of the shared configuration file to or
from a text file. The srvConfig.loc is in /var/opt/oracle directory (HPUX: /etc).
Do not use the default location of the server parameter file because all databases must the same
spfile. Instead, put a pfile ('init$ORACLE_SID.ora' or 'init%ORACLE_SID%.ora')in the default
location with:SPFILE='/dev/vx/rdsk/oracle_dg/db_spfile'
SRVCTL architecture: the console talks to the agent on each node, which talks to the SVRCTL
(server control), which talks to the GSD (Global Services Deamon) not only on the local node but
on all nodes (communication with RMI). The GSD must run at all times (check with gsdctl
$ORACLE_HOME/bin/stat).
TNSNAMES.ORA must have entries for the database and for each instance.
LISTENER.ORA must have a listener defined for each node with the TCP/IP address and entries
for the SIDs in sid_LIST_listener_name
When load balancing is on, the client randomly selects a database to connect to.
Cross-node registration:
This requires configuration of the LOCAL_LISTENER and REMOTE_LISTENER (global list of
listeners) initialization parameters. The LOCAL_LISTENER parameter identifies the local listener
and the REMOTE_LISTENER parameter identifies the global list of listeners of the instance. (The
dispatcher setting can be changed to override the local and remote listener settings.)
The default listener's name has the node name included (in addition to the SID). Do not use the
global_dbname so as to allow failover.
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
See the Net8 page for information about the TNSNAMES.ORA file.
See the V$SESSION view for details on fail overs (specifically columns FAILOVER_TYPE,
FAILOVER_METHOD, and FAILED_OVER ).
Miscellaneous Tips
The data files, control files and on-line redo logs, parameter file, tnsnames.ora, and
listener.ora
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html
The type and number of media management devices
You should also keep the following documentation about the software configuration:
Export / import
dbverify:
dbv datafile
http://www.cthullen.s5.com/miscw/oracle_bkp_restore.html