My OracleInstall N Config v01
My OracleInstall N Config v01
1. Install Oracle 11gR2 Server (11.2.0.1.2) 2. Install Oracle 11gR2 Client (11.2.0.2.0) 3. Create an Oracle 11 Database 3.1Create Standard Tablespace 3.2Create Standard Database Users and roles 3.3Additional Setup for Stream 3.4Database Networking Setup 4. Install Oracle 10gR2 Server and Database 4.1Install Oracle 10gR2 Server 4.2Install Oracle Patchset 10.2.0.4 5. Install Oracle 10gR2 Database
Solaris groupadd oinstall groupadd dba useradd -c "Oracle Software Owner" -d /export/home/oracle \ -g oinstall -G dba -s /bin/sh oracle passwd oracle mkdir -p /export/home/oracle chown oracle:oinstall /export/home/oracle Note: You may assign system resource to Oracle user or, application to perform business by either updating the /etc/system file or, creating a project, but either cases you will require to reboot (# init 6) the system for changes to take an effect. Ref: Oracle Database Preinstallation Requirements Option #1 Update the system file (Recommended for Oracle 10g): # cat /etc/system noexec_user_stack semsys:seminfo_semmni semsys:seminfo_semmns semsys:seminfo_semmsl semsys:seminfo_semvmx shmsys:shminfo_shmmax shmsys:shminfo_shmmni 1 100 1024 256 32767 4294967295 100
Option #2 Adding a project (Recommended for Oracle 11g): # projadd -U oracle -K "project.max-shm-memory=(priv,4096MB,deny)" user.oracle Note: adjust the parameter/s above (Opt 1 or 2) according to your system configuration.
AIX
mkgroup oinstall mkgroup dba mkuser oracle chuser cpu=-1 data=-1 fsize=-1 groups=dba home=/home/oracle \ nofiles=-1 nproc=-1 pgrp=oinstall shell=/bin/ksh stack=-1 threads=-1 oracle Create the ORACLE_BASE Directory # # Warning: ORACLE_BASE cannot be the HOME directory of the Oracle User #
mkdir -p /u01/app/oracle chown -R oracle:oinstall /u01/app mkdir /db1 chown oracle:dba /db1
Note:
You may desire to separate the flash_recovery_area and archivelog from datefile directory You may create /db2 for flash-recovery_area and archivelog mkdir /db2 chown oracle:dba /db2
1.2
Create the .profile # Step 1 su - oracle # Step 2 ver=11.2.0.1.2 if [[ $(uname -s) == AIX ]] then ver=11.2.0.2.0 fi cat >$HOME/.profile <<EOF # # Set Oracle environment variables.
# export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=\$ORACLE_BASE/product/$ver/server64_1 export TNS_ADMIN=\$ORACLE_BASE/admin/network/admin export ORACLE_SID=<??> export ORACLE_UNQNAME=<??> export PATH=/usr/bin:/etc:/usr/sbin:/usr/ccs/bin:\$ORACLE_HOME/bin:\ $ORACLE_HOME/OPatch:~/bin export EDITOR=vi # # set ulimit # ulimit -S -f unlimited if tty -s then set -o vi stty erase ^H export HOSTNAME=$(hostname) export PS1='\${HOSTNAME} \${LOGNAME} \${ORACLE_SID} \${PWD##*/}: ' fi EOF
# Step 5 for i in adump logbook do mkdir -p $ORACLE_BASE/$ORACLE_SID/$i done mkdir mkdir mkdir mkdir -p -p -p -p install /db1/oradata /db1/flash_recovery_area /db1/archivelog
Needs Review Are all of the above directory creations necessary BEFORE installing binaries. Only directories needed by Binaries and/or Patch installation should be created at this point. I believe only the "~/install" directory is needed BEFORE installing the binaries. For all but the ~/install directory creation see: Create+an+Oracle+11+Database There is an error in the path for adump logbook subdirectories. See following correction. flash_recovery_area and archivelog subdirectories should be created on separate file system /db2. See following correction. for i in adump logbook do mkdir -p $ORACLE_BASE/admin/$ORACLE_SID/$i done mkdir -p install mkdir -p /db1/oradata mkdir -p /db2/flash_recovery_area mkdir -p /db2/archivelog
1.3
For Solaris Sparc64 and Solaris x86-64, obtain the following packages from Oracle Technology Network (http://www.oracle.com/technetwork/index.html ) and store them in directory ~/install. Oracle Database 11g Release 2 (11.2.0.1.0) for Solaris Operating System (SPARC) (64-bit) solaris.sparc64_11gR2_database_1of2.zip solaris.sparc64_11gR2_database_2of2.zip Oracle Database 11g Release 2 (11.2.0.1.0) for Solaris Operating System (x86-64) solaris.x64_11gR2_database_1of2.zip solaris.x64_11gR2_database_2of2.zip
For AIX, obtain the following patchset files from https://support.oracle.com and store them in directory ~/install: 10098816 11.2.0.2.0 PATCH SET FOR ORACLE DATABASE SERVER 11.2.0.2.0 IBM AIX on POWER Systems (64-bit) p10098816_112020_AIX64-5L_1of7.zip p10098816_112020_AIX64-5L_2of7.zip
For Solaris, obtain the following patchset files from https://support.oracle.com and store them in directory ~/install: Solaris Sparc64 p6880880_112000_SOLARIS64.zip p9654983_112010_SOLARIS64.zip Solaris x86-64 p6880880_112000_Solaris86-64.zip p9654983_112010_Solaris86-64.zip
1.4
Install Server Software cd ~/install mkdir -p 1120_server64 for i in $( ls *database*.zip *1of7.zip *2of7.zip 2>/dev/null ) do unzip -n -q $i -d 1120_server64 done # # If AIX then run rootpre.sh otherwise skip to the next command. # (cd 1120_server64; su -c './rootpre.sh') # # Create the installation response file. # sed \ -e "s~^\(UNIX_GROUP_NAME=\).*$~\1oinstall~" \ -e "s~^\(INVENTORY_LOCATION=\).*$~\1/u01/app/oraInventory~" \ -e "s~^\(SELECTED_LANGUAGES=\).*$~\1\en~" \ -e "s~^\(ORACLE_HOME=\).*$~\1${ORACLE_HOME}~" \ -e "s~^\(ORACLE_BASE=\).*$~\1${ORACLE_BASE}~" \ -e "s~^\(oracle.install.option=\).*$~\1INSTALL_DB_SWONLY~" \ -e "s~^\(oracle.install.db.InstallEdition=\).*$~\1EE~" \ -e "s~^\(oracle.install.db.DBA_GROUP=\).*$~\1dba~" \ -e "s~^\(oracle.install.db.OPER_GROUP=\).*$~\1dba~" \ -e "s~^\(DECLINE_SECURITY_UPDATES=\).*$~\1true~" \ 1120_server64/*/response/db_install.rsp \ > 1120_server64.rsp echo "SECURITY_UPDATES_VIA_MYORACLESUPPORT=false" >> 1120_server64.rsp # # Install the software # 1120_server64/*/runInstaller \ -responseFile $PWD/1120_server64.rsp \ -waitforcompletion \ -ignorePrereq \ -silent # # Run the root.sh script(s) as directed in the install messages. #
1.5
Install Server Patchset Software on Solaris Systems mv $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch_$(date '+%Y%m%d_%H%M%S') unzip -n -q p6880880_*.zip -d $ORACLE_HOME # # Install PSU 11.2.0.1.2 # unzip -n -q p9654983*.zip cd 9654983 # # OPatch will ask questions. Respond as indicated as long as other messages do not indicate a serious problem: # 'Email address/User Name:' - Response: <enter> # 'Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]:': - Response: y<enter> # 'Is the local system ready for patching? [y|n]'- Response: y<enter> # $ORACLE_HOME/OPatch/opatch apply
1.6 1.7
Ad Ad
RedHat Linux
groupadd oinstall groupadd dba mkdir -p /export/home
passwd oracle
Solaris
groupadd oinstall groupadd dba
useradd -c "Oracle Software Owner" -d /export/home/oracle \ -g oinstall -G dba -s /bin/ksh oracle passwd oracle
mkdir -p /export/home/oracle chown oracle:oinstall /export/home/oracle AIX mkgroup oinstall mkgroup dba mkuser oracle
chuser cpu=-1 data=-1 fsize=-1 groups=dba home=/home/oracle \ nofiles=-1 nproc=-1 pgrp=oinstall shell=/bin/ksh stack=-1 threads=-1 oracle
2.2
asd
3 asd
4
1.2. Create Directories (perform as oracle)
Create Directories su - oracle mkdir -p $ORACLE_HOME mkdir -p install
# Warning: ORACLE_BASE cannot be the HOME directory of the Oracle User # ORACLE_BASE=/u01/app/oracle ORACLE_HOME=$ORACLE_BASE/product/11.2.0.2.0/client${CLIENT_ARCH}_1 mkdir -p $ORACLE_BASE mkdir -p $ORACLE_HOME INV_LOC=$(cd $ORACLE_BASE/..;pwd)/oraInventory # # Create the installation response file. # sed \ $UNZIP_DIR/*/response/client_install.rsp \ -e "s~^\(UNIX_GROUP_NAME=\).*$~\1${install_group}~" \ -e "s~^\(INVENTORY_LOCATION=\).*$~\1$INV_LOC~" \ -e "s~^\(SELECTED_LANGUAGES=\).*$~\1\en~" \ -e "s~^\(ORACLE_HOME=\).*$~\1${ORACLE_HOME}~" \ -e "s~^\(ORACLE_BASE=\).*$~\1${ORACLE_BASE}~" \ -e "s~^\(oracle.install.client.installType=\).*$~\1Administrator~" \ -e "s~^\(DECLINE_SECURITY_UPDATES=\).*$~\1true~" \ $UNZIP_DIR/*/response/client_install.rsp \ > $UNZIP_DIR.rsp # # Install the software # $UNZIP_DIR/*/runInstaller \ -responseFile $PWD/$UNZIP_DIR.rsp \ -waitforcompletion \ -silent \ -ignorePrereq # # Run the root.sh script(s) as directed in the install messages. #
3.
# # Do not perform the following commands for a second database. # mkdir -p $ARCHIVE_LOC/archivelog
Create the Parameter File - <RUSS> Database cat >$ORACLE_HOME/dbs/init$ORACLE_SID.ora <<EOF audit_file_dest='${ORACLE_BASE}/admin/<orcl_01>/adump' audit_trail='db' compatible='11.2.0' control_file_record_keep_time=31 db_block_checking='MEDIUM' db_block_size=16384 db_create_file_dest='${DB_LOC}/oradata' db_files=300 db_name='$ORACLE_SID' db_recovery_file_dest='${ARCHIVE_LOC}/flash_recovery_area' db_recovery_file_dest_size=50g dispatchers='(PROTOCOL=TCP) (SERVICE=${ORACLE_SID}XDB)' global_names=TRUE job_queue_processes=10 log_archive_dest_10='LOCATION=USE_DB_RECOVERY_FILE_DEST MANDATORY' log_archive_dest_1='LOCATION=${ARCHIVE_LOC}/archivelog/${ORACLE_SID} MANDATORY' log_archive_dest_state_10='enable' log_archive_dest_state_1='defer' log_archive_format='${UPPERCASE_SID}_%T_%S_%r.arc' max_dump_file_size='10000000' memory_target='2g' nls_date_format='yyyy-mm-dd hh24:mi:ss' nls_timestamp_format='yyyy-mm-dd hh24:mi:ss.ff6' nls_timestamp_tz_format='yyyy-mm-dd hh24:mi:ss.ff6 tzh:tzm' open_cursors=300 optimizer_index_caching=75 optimizer_index_cost_adj=10 recyclebin='OFF'
Create the Database Instance sqlplus /nolog connect / as sysdba create spfile from pfile; startup nomount create database <orcl_01> user sys identified by remote_dba user system identified by remote_dba character set AL32UTF8 national character set AL16UTF16 datafile size 400m autoextend on next 16m maxsize unlimited extent management local logfile group 1 size 500m ,group 2 size 500m ,group 3 size 500m ,group 4 size 500m ,group 5 size 500m ,group 6 size 500m maxdatafiles 300 maxinstances 1 maxlogfiles 128 maxlogmembers 5
default temporary tablespace temp1 tempfile size 1g autoextend on next 32m maxsize 8g extent management local undo tablespace undo1 datafile size 1g autoextend on next 128m maxsize 12g /
Warning There can be numerous warnings and errors. Normally all such warning and errors can be ignored. Consult an Oracle DBA if in doubt. Create the Data Dictionary @?/rdbms/admin/catalog.sql @?/rdbms/admin/catproc.sql @?/rdbms/admin/catmwin.sql @?/rdbms/admin/catblock.sql @?/rdbms/admin/catio.sql @?/rdbms/admin/catoctk.sql @?/rdbms/admin/catqueue.sql @?/rdbms/admin/dbmspool.sql @?/rdbms/admin/utltkprf.sql
exit Generic Database creation is completed for $ORACLE_SID=<orcl_01>|<orcl_n>. Proceed with DB Setup to add Customer Required Elements to these generic database instances
# # If you need to rerun emca, run as follows: # emca -config dbcontrol db -repos recreate
# # Optional: stop the Enterprise Manager if you do not plan to use it. # You can start it later by running: 'emctl start dbconsole' # emctl stop dbconsole
vappl_procs number := nvl(vappl_procs_supplied, 300); vcpu_count number; vjobq_procs number; vparallel_procs number; vplatform_name v$database.platform_name%type; vproc number; stmt varchar2(200); str_aix varchar2(3) := 'aix'; str_linux_x86 varchar2(9) := 'linux x86'; begin dbms_output.put_line('Supplied value of application_processes: ''' || vappl_procs_supplied || ''''); dbms_output.put_line('Supplied value of processes: ''' || vproc || ''''); if vproc is null then select to_number(p.value) into vcpu_count from v$parameter p where p.name in ('cpu_count'); select value into vjobq_procs from v$parameter where name='job_queue_processes'; select platform_name into vplatform_name from v$database; vparallel_procs := vcpu_count * 10; if lower(substr(vplatform_name,1,length(str_aix))) = str_aix or lower(substr(vplatform_name,1,length(str_linux_x86))) = str_linux_x86 then -- AIX and Linux computation is an educated guess based on -- in-house server testing. vparallel_procs := vparallel_procs * 4; end if; vproc := vparallel_procs + vjobq_procs + vappl_procs; dbms_output.put_line('Computation of processes:'); dbms_output.put_line('... platform_name: ''' || vplatform_name || ''''); dbms_output.put_line('... cpu_count: ''' || vcpu_count || ''''); dbms_output.put_line('... job_queue_processes: ''' || vjobq_procs || ''''); dbms_output.put_line('... parallel processes (computed): ''' || vparallel_procs || ''''); dbms_output.put_line('... application processes (' || (case when vappl_procs_supplied is null then 'default' else 'supplied' end) || '): ''' || vappl_procs || ''''); dbms_output.put_line('... processes (computed): ''' || vproc || ''''); vproc := ceil(vproc * 1.2); dbms_output.put_line('... processes (1.2 * computed): ''' || vproc || ''''); end if; stmt := 'alter system set processes=' || vproc || ' scope=spfile'; dbms_output.put_line(stmt); execute immediate stmt; end;
3.1
3.2
/ --- User <usr2> owns objects needed by <app_proj2> -create user <usr2> identified by <password>; alter user <usr2> default tablespace <app_proj>; alter user <usr2> temporary tablespace temp1; grant alter session ,create procedure ,create sequence ,create session ,create synonym ,create table ,create type ,create trigger ,create view ,select any dictionary ,unlimited tablespace to <usr2> / --- User <usr3> is the user that all <usr1> users use to carry out their -- tasks. -create user <usr3> identified by <password>; alter user <usr3> default tablespace work1; alter user <usr3> temporary tablespace temp1; grant alter session ,create session ,create synonym ,select any dictionary to <usr3> / grant execute on dbms_aqin to <usr3> / --- User <usr4> is the user that -- contains the views used by <usr3> -create user <usr4> identified by <password>; alter user <usr4> default tablespace work1; alter user <usr4> temporary tablespace temp1; grant alter session ,create session ,create synonym ,create view ,select any dictionary to <usr4> / --- Role <usr1>_user generally read/write privileges. -create role <usr1>_user; --
-- Role <usr1>_readonly allows select -- privileges only on non-temporary tables. -create role <usr1>_readonly; --- Grant roles to <usr4>. -grant <usr1>_user to <usr4>; grant <usr1>_readonly to <usr4>; grant <usr1>_readonly to <usr3>; grant <usr1>_readonly to <usr2>; --- Make <usr1>_user the default role. -alter user <usr4> default role <usr1>_user; alter user <usr2> default role none; alter user <usr3> default role none;
3.4
The following section describes how to setup Oracle Networking: Perform the following steps as the Oracle user: 1 cd $ORACLE_BASE/admin/network/admin 2 Create the listener.ora file changing 'myhostname' to the name of your host. cat >listener.ora <<EOF LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = <SID_01>)) (ADDRESS = (PROTOCOL = TCP)(HOST = <myhostname>)(PORT = 1521)) ) ) EOF 3 Create the tnsnames.ora file changing 'myhostname' to the name of your host. cat >tnsnames.ora <<EOF <ORCL_01> = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = <myhostname>)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = <orcl_01>) ) ) EOF 4 Start the listener lsnrctl start
Run the following command to assign system resource to Oracle # projadd -U oracle -K "project.max-shm-memory=(priv,4096MB,deny)" user.oracle
Create directories for oracle user and database files (perform as root)
# mkdir -p /u01/app/oracle # mkdir -p /db1 # chown oracle:oinstall /u01/app/oracle # chown oracle:dba /db1
# su - oracle % cat <<EOF >.profile # # Set ulimit # ulimit -S -f unlimited # # Set the database environment. # export PATH=/usr/bin:/etc:/usr/sbin:/usr/ccs/bin:~/bin:. # # Set Oracle environment variables. # export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/oracle_homes/10.2.0/db_1 export ORACLE_SID=<sid_01> export export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch export LD_LIBRARY_PATH=/lib/64:/usr/lib/64:/lib:/usr/lib:/usr/dt/lib:$ORACLE_HOME/lib: $ORACLE_HOME/LIB32:/usr/openwin/lib: export export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch export LD_LIBRARY_PATH=/lib/64:/usr/lib/64:/lib:/usr/lib:/usr/dt/lib: $ORACLE_HOME/lib:/usr/openwin/lib: export TNS_ADMIN=$ORACLE_BASE/admin/network/admin export HOSTNAME=$(hostname) tty -s istty=$? if [[ $istty -eq 0 ]] then stty istrip stty erase ^H export PS1='${HOSTNAME} ${LOGNAME} ${ORACLE_SID} ${PWD##*/}: ' fi EOF
\. ~/.profile
Create directories for the Oracle server install and the database (perform as oracle)
$ mkdir ~/install $ mkdir -p $ORACLE_HOME $ mkdir -p /db1/oradata $ mkdir -p /db1/flash_recovery_area $ mkdir -p /db1/archivelog $ mkdir -p $ORACLE_BASE/admin/<sid_01>/adump $ mkdir -p $ORACLE_BASE/admin/<sid_01>/bdump $ mkdir -p $ORACLE_BASE/admin/<sid_01>/cdump $ mkdir -p $ORACLE_BASE/admin/<sid_01>/udump $ mkdir -p $ORACLE_BASE/admin/network/admin
Download the files needed for the Oracle server install (perform as oracle)
FTP or, SSH Oracle CPIO.GZ file under ~/install directory to your DB Server. e.g. $ cd ~/install $ ftp <Zip file host> ftp> user <oracle> enter password ftp> cd <path> ftp> bin ftp> get 10201_10gr2_db_sol.cpio.gz ftp> get 10204_p6810189_10204_Solaris-64.zip ftp> get OPatch_p6880880_102000_Solaris64_10.2.0.4.9.zip ftp> get 1020404_p9352164_10204_Solaris-64.zip ftp> get <russ_t102.dbt> ftp> cd response ftp> get <russ_10201_enterprise.rsp> ftp> get <russ_10204_patchset.rsp> ftp> quit
When the installer completes, it will instruct you to run a script as root. Run the listed script.
Install OPatch
$ cd ~/install $ unzip -q OPatch_p6880880_102000_Solaris64_10.2.0.4.9.zip $ rm -r -f $ORACLE_HOME/OPatch $ mv OPatch $ORACLE_HOME
5.
For the following replace the values you find with values appropriate to your installation. 'db_recovery_dest_size' is the size of the database plus accumulated archive logs. The rule of thumb for setting its value is 1.5 times the expected size of the database. 'sga_target' is the amount of shared memory the database instance will use. For a standalone DS, feel free to use up to 1/2 the memory. alter system set db_recovery_file_dest_size=6g scope=spfile; alter system set sga_target=2g scope=spfile; The database global name should be set to the value of ORACLE_SID.hostname. Only the characters A-Z0-9._ are valid for the global name. For example, on <server>, the global name could be set to '<sid>.<server>'. Replace the string '&global_name' with the value of the global name. alter database rename global_name to &global_name;
6. Database Backup
Database Backups
Overview
From Oracle Database 2 Day DBA, 11g Release 2 (11.2), Part Number E10897-02 9 Performing Backup and Recovery Database Backup and Recovery Concepts To back up your database means to make copies of your data files, control file, and archived redo log files (if your database runs in ARCHIVELOG mode). Restoring a database means copying the physical files that comprise the database from a backup medium, typically disk or tape, to their original or to new locations. Database recovery is the process of updating database files restored from a backup with the changes made to the database after the backup, typically using online redo log files. Consistent and Inconsistent Backups A backup is either consistent or inconsistent. To make a consistent backup, your database must have been shut down cleanly and remain closed for the duration of the backup. All committed changes in the online redo log files are written to the data files during the shut down process, so the data files are in a transaction-consistent state. When you restore your data files from a consistent backup, you can open the database immediately. If the database is in ARCHIVELOG mode, then you can make inconsistent backups that are recoverable using archived redo log files. Open database backups are inconsistent because the online redo log files contain changes not yet applied to the data files. The online redo log files must be archived and then backed up with the data files to ensure recoverability. Despite the name, an inconsistent backup is as robust a form of backup as a consistent backup. The advantage of making inconsistent backups is that you can back up your database while the database is open for updates. Fast Recovery Area To simplify the management of backup and recovery files, you can create a fast recovery area for your database. The fast recovery area is an Oracle-managed directory, file system, or Oracle Automatic Storage Management disk group that provides a centralized disk location for backup and recovery files. Oracle creates archived logs and flashback logs in the fast recovery area. RMAN can store its backup sets and image copies in the fast recovery area, and it uses it when restoring files during media recovery. The fast recovery area also acts as a disk cache for tape. Oracle Database automatically manages this storage, deleting files that are no longer needed. Periodically copying backups to tape frees space in the fast recovery area for other files. Oracle recommends that you enable a recovery area to simplify backup management. Configuring Your Database for Basic Backup and Recovery To take maximum advantage of Oracle Database features that automatically manage backup and recovery files and operations, configure your database as follows: Use a fast recovery area, which automates storage management for most backup-related files, and specify it as an archived redo log file destination.
Run the database in ARCHIVELOG mode so you can perform online backups and have data recovery options such as complete and point-in-time media recovery. Planning Space Usage and Location for the Fast Recovery Area You should place the fast recovery area on a separate disk from the working set of database files. Otherwise, the disk becomes a single point of failure for your database. The amount of disk space to allocate for the fast recovery area depends on the size and activity levels of your database, which determine the size of your data files and online redo log files in addition to your recovery objectives. Your objectives dictate what kinds of backups you use, when you make them, and how long to keep them. About the Backup Retention Policy and the Fast Recovery Area Space management in the fast recovery area is governed by a backup retention policy. A retention policy determines when files are obsolete, meaning that they are no longer needed to meet your data recovery objectives. Retention policies can be based on redundancy of backups or on a recovery window (period of time). When using a policy based on redundancy, the fast recovery area considers a backup of a file obsolete only when the RMAN repository has records of a specified number of more recent backups of that file. When using a recovery policy based on a period of time (or window), you specify a time interval in days. Files are obsolete only when they are no longer needed for complete recovery or point-in-time recovery to a system change number (SCN) within the window. Therefore, a recovery retention policy based on a window is recommended. Even after files in the fast recovery area are obsolete, they are typically not deleted until space is needed for new files. If space permits, files recently moved to tape remain on disk to avoid restoring them from tape for a recovery. The automatic deletion of obsolete files and files moved to tape from the fast recovery area makes it a convenient archiving destination. Other destinations require manual deletion of logs. About the Fast Recovery Area Size Oracle Database Backup and Recovery User's Guide explains how to size the fast recovery area. As a general rule, the larger the fast recovery area, the more useful it is. Ideally, the fast recovery area should be large enough for copies of the data files, control files, online redo log files, and archived redo log files needed to recover the database, and also the copies of these backup files that are kept based on the retention policy. If your backup strategy includes incremental backups, which are described in "Incremental Backups of Data Files", then add enough space to the fast recovery area for these files. If you can move some backups to tape, then you can reduce the size of the fast recovery area. Note that retrieving files from tape causes longer database restore operations and recovery times.
Resources
Oracle Database 2 Day DBA, 11g Release 2 (11.2), Part Number E10897-02, Chapter 9 - Performing Backup and Recovery Oracle Database Backup and Recovery User's Guide, 11g Release 2 (11.2), Part Number E10642-01 Oracle Database Backup and Recovery Reference, 11g Release 2 (11.2), Part Number E10643-01
Files
Type
Multiplexed copies of the current control file Online redo log files
Permanen The instance fails if the database cannot write to a multiplexed t copy of the control file stored in the fast recovery area. Failure occurs even if accessible multiplexed copies are located outside the recovery area. Permanen Instance availability is not affected if a mirrored copy of the online t redo log exists in an accessible location outside the fast recovery area. Otherwise, the instance fails.
Archived redo Transient Instance availability is not affected if the log is archived to an log files accessible location outside the fast recovery area. Otherwise, the database eventually halts because it cannot archive the online redo logs. Foreign Transient Instance availability is not affected.Note: Foreign archived redo archived redo logs are received by a logical standby database for a LogMiner log files session. Unlike a normal archived log, a foreign archived redo log has a different DBID. For this reason, it cannot be backed up or restored on a logical standby database. Image copies Transient Instance availability is not affected. of datafiles and control files Backup pieces Flashback logs Transient Instance availability is not affected.
Transient Instance availability is not affected if guaranteed restore points are not defined. In this case, the database automatically disables Flashback Database, writes a message to the alert log, and continues with database processing. If guaranteed restore points are configured, the instance fails because of interdependencies on the flashback logs. The Oracle Flashback Database feature, which provides a convenient alternative to database point-in-time recovery (DBPITR), generates flashback logs. These logs are transient files and must be stored in the fast recovery area. Unlike other transient files, flashback logs cannot be backed up to other media. If the fast recovery area has insufficient space to store flashback logs and meet other backup retention requirements, then the recovery area may delete flashback logs.
How Oracle Manages Disk Space in the Fast Recovery Area Space in the fast recovery area is balanced among backups and archived logs that must be kept according to the retention policy, and other files which may be subject to deletion. Oracle Database does not delete eligible files from the fast recovery area until the space must be reclaimed for some other purpose. Thus, files recently moved to tape are often still available on disk for use in recovery. The recovery area can thus serve as a cache for tape. When the fast recovery area is full, Oracle Database automatically deletes eligible files to reclaim space in the recovery area as needed.
db_recovery_file_dest Specifies the default location for the fast recovery area. db_recovery_file_dest Specifies the hard limit on the total space to be used by the database _size recovery files created in the fast recovery area.
DELETE EXPIRED commands. ************************************************************************ The following SQL query produces a summary of the flash recovery area usage: select d.space_limit / (1024*1024*1024) space_limit ,u.percent_space_used * 100 percent_space_used ,d.space_limit * u.percent_space_used / (1024*1024*1024) space_occupied ,u.percent_space_reclaimable * 100 percent_space_reclaimable ,(d.space_limit - (d.space_limit * u.percent_space_used) + (d.space_limit * u.percent_space_reclaimable) ) / (1024*1024*1024) space_available from v$recovery_file_dest d cross join ( select sum(percent_space_used)/100 percent_space_used ,sum(percent_space_reclaimable)/100 percent_space_reclaimable from v$flash_recovery_area_usage ) u / SPACE_LIMIT PERCENT_SPACE_USED SPACE_OCCUPIED PERCENT_SPACE_RECLAIMABLE SPACE_AVAILABLE ----------- ------------------ -------------- ------------------------- --------------18 26.72 4.8096 .22 13.23
The <RUSS> Dbserver software package schedules a program ($ADA_HOME/Db/bin/backup_db) which produces a report (see the following sample output) on the status of the flash recovery area at the time of its running. /ada/Db/bin/backup_db -log_dir /ada/log/backup_db -log_retention 14 -log_file_prefix <sid>_flash_usage_ -oracle_home /ada/Db/oracle/ora11server64 -oracle_sid <sid> / flash_usage /ada/Db/bin/backup_db started at 2010-12-01 11:37:33 Program arguments: '/ada/Db/bin/backup_db -log_dir /ada/log/backup_db -log_retention 14 -log_file_prefix <sid>_flash_usage_ -oracle_home /ada/Db/oracle/ora11server64 -oracle_sid <sid> / flash_usage' Logging results to file '/ada/log/backup_db/<sid>_flash_usage_20101201_113733.log' Flash Recovery Area Definition NAME SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES
SPACE_LIMIT
-------------------------------------------------- --------------------------------------- -------------------- --------------/ada/db1/flash_recovery_area 19,327,352,832 5,163,826,688 43,450,368 43 Flash Recovery Area Usage By File Type SPACE(GB) PERCENT SPACE(GB) PERCENT SPACE SPACE(GB) NUMBER FILE_TYPE LIMIT SPACE USED OCCUPIED RECLAIMABLE RECLAIMABLE FILES -------------------- ----------- ---------- ----------- ------------- ---------------------CONTROL FILE 18.00 0.05 0.01 0.00 0.00 1 REDO LOG 18.00 16.28 2.93 0.00 0.00 6 ARCHIVED LOG 18.00 0.50 0.09 0.00 0.00 4 BACKUP PIECE 18.00 0.30 0.05 0.20 0.04 6 IMAGE COPY 18.00 9.59 1.73 0.02 0.00 26 FLASHBACK LOG 18.00 0.00 0.00 0.00 0.00 0 FOREIGN ARCHIVED LOG 18.00 0.00 0.00 0.00 0.00 0 ---------- ----------- ------------- ---------------------sum 26.72 4.81 0.22 0.04 43 Flash Recovery Area Usage Summary SPACE(GB) PERCENT SPACE(GB) PERCENT SPACE SPACE LIMIT SPACE USED OCCUPIED RECLAIMABLE AVAILABLE ----------- ---------- ----------- ------------- ----------18.00 26.72 4.81 0.22 13.23 /ada/Db/bin/backup_db completed at 2010-12-01 11:37:33 Results logged to '/ada/log/backup_db/<sid>_flash_usage_20101201_113733.log'.
OF
The size of the flash recovery area can be adjusted by the database administrator by setting the value of database parameter db_recovery_file_dest_size (syntax: db_recovery_file_dest_size = integer [ K | M | G ]). For example, the following commands will list the current value of db_recovery_file_dest_size and then immediately change its value: ORACLE_SID=dbsid sqlplus /nolog connect / as sysdba show parameter db_recovery_file_dest_size alter system set db_recovery_file_dest_size=54g; exit
"OBJECT_NAME" VARCHAR2(30 BYTE) NOT NULL ENABLE, "PARTITION_NAME" VARCHAR2(30 BYTE) NOT NULL ENABLE, "SUBPARTITION_NAME" VARCHAR2(30 BYTE) NOT NULL ENABLE, "LAST_ANALYZED" DATE, "NUM_ROWS" NUMBER(*,0), "SAMPLE_SIZE" NUMBER(*,0), "GATHER_STATS_LOG_ID" NUMBER(10,0) NOT NULL ENABLE, CONSTRAINT "GATHER_STATS_OBJECT_LOG_PK" PRIMARY KEY ("GATHER_STATS_LOG_ID", "OBJECT_OWNER", "OBJECT_TYPE", "OBJECT_NAME", "PARTITION_NAME", "SUBPARTITION_NAME") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 163840 NEXT 163840 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "WORK1" ENABLE, CONSTRAINT "GSL_FK_GATHER_STATS_LOG" FOREIGN KEY ("GATHER_STATS_LOG_ID") REFERENCES "<user1>"."GATHER_STATS_LOG" ("ID") ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 163840 NEXT 163840 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "WORK1" ; Use the following code as a basis for a gather_dbstats package: declare tab dbms_stats.objecttab; elem dbms_stats.objectelem; session_ts timestamp(6) with time zone := current_timestamp; begin for i in (select 'GATHER STALE' option from dual union all select 'GATHER EMPTY' option from dual) loop dbms_stats.gather_schema_stats( ownname=>null ,estimate_percent=>10 ,block_sample=>true ,method_opt=>'for all columns size 1' ,degree=>dbms_stats.default_degree ,granularity=>all ,cascade=>true ,options=>i.option ,no_invalidate=>false ,objlist=>tab ); if tab.count = 0 then select username into user_name from user_users; insert into gather_stats_log( stat_option, session_start, owner) values( i.option, session_ts, user_name) ; else
for j in tab.first .. tab.last loop elem := tab(j); Make the following select a package routine returning a row. select * into ttab from object_stats where owner=elem.ownname and object_type=elem.objtype and object_name=elem.objname and (partition_name=elem.partition_name or elem.partition_name is null) and (subpartition_name=elem.subpartition_name or elem.subpartition_name is null) ; insert into gather_stats_log( stat_option, session_start, owner, object_type, object_name ,partition_name, subpartition_name, last_analyzed ,num_rows, sample_size ) values( i.option, session_ts, elem.ownname, elem.objtype, elem.objname ,elem.partname, elem.subpartname, ttab.last_analyzed ,ttab.num_rows, ttab.sample_size) ; end loop; end loop; delete from gather_stats_log where session_start < session_start to_dsinterval('P60D') and owner=user_name ; dbms_scheduler.schedule to control when statistics jobs are submitted: #include "sql.h" #if defined(SCHEDULE) && defined(CREATE) -- @(#) $Id: //capmgr/1.1.0/<Oracle_SID>/rdbms/tables/sched_refresh_mvnecomps.dsql#1 $ $DateTime: 2010/09/27 01:56:41 $ ---- Description: -- Schedule for gathering schema stats. --- Change Activity: --- Reference When Who What -- ---------- ---------- ------------- --------------------------------- -#endif #if defined(SCHEDULE) SCHEDULE_PROMPT(sched_base_schema_stats) SCHEDULE_START(sched_base_schema_stats)
1. if defined(CREATE) declare name user_scheduler_schedules.schedule_name%type := 'sched_base_schema_stats'; begin db_change.create_schedule( schedule_name=>name ,start_date=>trunc(sysdate-1) ,repeat_interval=>'FREQ=MINUTELY;BYHOUR=2,6,10,14,18,22' ,comments=>'Schedule for collecting base schema statistics' ); end; / 2. endif #endif dbms_scheduler.job to run the statistics gathering #include "sql.h" #if defined(JOB) && defined(CREATE) @(#) $Id: //capmgr/1.1.0/<SID>/rdbms/tables/job_refresh_mvnecomps.dsql#1 $ $DateTime: 2010/09/27 01:56:41 $ - Copyright 2010 -- Product/Subsystem: <>/Database -- Description: Job to gather schema stats. -- Change Activity: -- Reference When Who What ---------- ---------- ------------- --------------------------------- -#endif #if defined(JOB) JOB_PROMPT(sched_base_schema_stats) JOB_START(sched_base_schema_stats) 1. if defined(CREATE) declare name user_scheduler_jobs.job_name%type := 'job_gather_schema_stats'; begin db_change.create_job( job_name=>name ,program_name=>'pgm_gather_schema_stats'
,schedule_name=>'sched_gather_schema_stats' ,enabled=>true ,auto_drop=>false ,comments=>'Job to collect schema statistics' ); end; / 2. endif #endif Add a maintenance window, if we have the privilege, within which the job needs to be finished.
Pre-Upgrade Steps
Description
The following pre-upgrade steps are performed while the database is up and running in Oracle 10. All application activity must be stopped. There must be a current database backup. The following application cron jobs must be completed and prevented from running: db_partition, db_stats. The results of all the commands below should be logged. Suggest /ada/log/db_upgrade/1020_to_1120/preupgrade.log.
Steps
1. 2. 3. 4. 5. 6. 7. 8. Disable database jobs. Run Pre-Upgrade Information Tool (utlu112i.sql). See /thirdparty/oracle/11.2.0/install/solaris_sparc/utlu112i.sql. Gather statistics for schemas. Purge the recyclebin. Compile all invalid objects. Save the database parameter file, password file. Create the database pfile to be used as the source for the Oracle 11 spfile. Verify that the database filesystem(s) have sufficient space for the upgrade.
Commands
sqlplus /nolog <<EOF >$preupgrade_logfile 2>&1 connect / as sysdba prompt List of Supplied database jobs ... select job_name, state, enabled from dba_scheduler_jobs where (owner='SYS' and job_name like '<>%') or (owner='<>') / prompt Disable Supplied database jobs ... declare vjob_name varchar2(128); begin for i in (select owner, job_name from dba_scheduler_jobs where (owner='SYS' and job_name like '<>%')
or owner='<>' ) loop vjob_name := i.owner || '.' || i.job_name; dbms_output.put_line('Disabling job ' || vjob_name); dbms_scheduler.disable(name=>vjob_name, force=>true); end loop; end; / prompt Wait for <> jobs to complete ... declare ct number := 1; begin while ct > 0 loop dbms_lock.sleep(5); select count(*) into ct from dba_scheduler_jobs where ((owner='SYS' and job_name like '<>%') or owner='<>') and state='RUNNING'; end loop; end; / spool $preupgrade_info_tool_logfile @utlu112i spool off prompt Gathering statistics for non-<> schemas ... begin dbms_stats.gather_dictionary_stats; for i in (select username from dba_users where username not in ( '<>', '<>USER', '<>SECURE', '<>')) loop dbms_stats.gather_schema_stats(i.username, cascade=>true); end loop; end; / prompt Purging the recyclebin ... purge dba_recyclebin; prompt Compiling invalid objects ... @?/rdbms/admin/utlrp.sql exit # Save the spfile and orapw files. cd $ORACLE_HOME/dbs
cp spfile${ORACLE_SID}.ora orapw${ORACLE_SID} $save_directory # Create the source database pfile create_pfile -p RDC pfile $ORACLE_SID spf= pf=$save_directory/init$ {ORACLE_SID}_1020.ora # Run the following query and store its value in $mem_target. # Note the '\' were put in to escape shell variable replacement. # Can create a variation of queryDB that can 'connect / as sysdba' to do this. select to_number(vs.value) + greatest(to_number(vp.value), vps.value) memory_target from v\$parameter vs cross join v\$parameter vp cross join v\$pgastat vps where vs.name='sga_target' and vp.name='pga_aggregate_target' and vps.name='maximum PGA allocated' / # Amend the source database pfile in preparation for Oracle 11 sed \ -e "/^\*\.background_dump_dest=/d" \ -e "/^\*\.user_dump_dest=/d" \ -e "/^\*\.core_dump_dest=/d" \ -e "/^\*\.compatible=/d" \ -e "/^\*\.sga_target=/d" \ -e "/^\*\.pga_aggregate_target=/d" \ -e "/^\*\.java_pool_size=/d" \ -e "/^\*\.large_pool_size=/d" \ $save_directory/init${ORACLE_SID}_1020.ora > $save_directory/init${ORACLE_SID}_1120.ora echo "*.memory_target=$mem_target" >> $save_directory/init${ORACLE_SID}_1120.ora echo "*.compatible='11.2.0.1'" >> $save_directory/init${ORACLE_SID}_1120.ora # Verify there is enough file system space to perform the database upgrade. Below assumes a single file # system. The grep will return the amount of space needed in MB for each tablespace that will need extra space # I have done this for 4 databases. Different growth amounts produced for each one. # No apparent rhyme or reason - empty pats database needed more space than a # long existing <server> <Project> database. # 750m should be sufficient if you want to wing it. grep "^.... AUTOEXTEND" $preupgrade_info_tool_logfile | cut -f6 -d ' ' | ... yada yada # Shutdown the database
Upgrade Steps
Steps
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Copy the saved orapw and init*.ora files to the Oracle 11 $ORACLE_HOME/dbs directory. Create the Oracle 11 spfile. Startup the database in upgrade mode. Run the catupgrd.sql script. Startup the database. Run the Post-Upgrade Tool (utlu112s.sql) and log its output Run upgrade actions not requiring the database to be in upgrade mode (catuppst.sql). Recompile stored procedures. Upgrade the database time zone file. Backup the database.
Commands
# Set the environment to the Oracle 11 Home. # Copy saved pw and init files to new ORACLE_HOME/dbs directory cp $save_directory/orapw${ORACLE_SID} $ORACLE_HOME/dbs cp $save_directory/init${ORACLE_SID}.ora $ORACLE_HOME/dbs sqlplus /nolog <<EOF >$upgrade_logfile 2>&1 connect / as sysdba -- Create the Oracle 11 spfile. create spfile from pfile; startup upgrade; -- Run the upgrade. spool $ADA_HOME/<>db/admin/<SID>/logbook/upg_10_11.log @?/rdbms/admin/catupgrd spool off -- Restart the database
connect / as sysdba startup -- Run the Post-Upgrade Status Tool @?/rdbms/admin/utlu112s -- Run upgrade steps not required to be in upgrade mode: @?/rdbms/admin/catuppst -- Recompile objects @?/rdbms/admin/utlrp -- Update the DST version SELECT PROPERTY_NAME, SUBSTR(property_value, 1, 30) value FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME LIKE 'DST_%' ORDER BY PROPERTY_NAME; shutdown immediate startup upgrade set serveroutput on purge dba_recyclebin; TRUNCATE TABLE SYS.DST$TRIGGER_TABLE; TRUNCATE TABLE sys.dst$affected_tables; TRUNCATE TABLE sys.dst$error_table; EXEC DBMS_DST.BEGIN_UPGRADE(11); SELECT PROPERTY_NAME, SUBSTR(property_value, 1, 30) value FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME LIKE 'DST_%' ORDER BY PROPERTY_NAME; shutdown immediate startup VAR numfail number BEGIN DBMS_DST.UPGRADE_DATABASE(:numfail, parallel => TRUE, log_errors => TRUE, log_errors_table => 'SYS.DST$ERROR_TABLE', log_triggers_table => 'SYS.DST$TRIGGER_TABLE',
error_on_overlap_time => FALSE, error_on_nonexisting_time => FALSE); DBMS_OUTPUT.PUT_LINE('Failures:'|| :numfail); END; / VAR fail number BEGIN DBMS_DST.END_UPGRADE(:fail); DBMS_OUTPUT.PUT_LINE('Failures:'|| :fail); END; / SELECT PROPERTY_NAME, SUBSTR(property_value, 1, 30) value FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME LIKE 'DST_%' ORDER BY PROPERTY_NAME; prompt Enable Supplied database jobs ... declare vjob_name varchar2(128); begin for i in (select owner, job_name from dba_scheduler_jobs where (owner='SYS' and job_name like '<>%') or owner='<SID>' ) loop vjob_name := i.owner || '.' || i.job_name; dbms_output.put_line('Enabling job ' || vjob_name); dbms_scheduler.enable(name=>vjob_name); end loop; end; / exit
$${ORACLE_HOME}/bin:$${ORACLE_CRS_HOME}/bin:$${PATH}
/u01/app/oracle/crs/bin/srvctl /u01/app/oracle/crs/bin/crs_stat RAC Daemon processes (sprung): > ps -ef | grep init.d root 18241 14363 0 09:21:19 ? 0:00 /bin/sh /etc/init.d/init.evmd run root 18791 18243 0 09:21:35 ? 0:00 /bin/sh /etc/init.d/init.cssd daemon root 18728 18243 0 09:21:34 ? 0:00 /bin/sh /etc/init.d/init.cssd oprocd root 18248 14363 0 09:21:19 ? 0:00 /bin/sh /etc/init.d/init.crsd run root 18243 14363 1 09:21:19 ? 1:10 /bin/sh /etc/init.d/init.cssd fatal root 18757 18243 0 09:21:34 ? 0:00 /bin/sh /etc/init.d/init.cssd oclsomon Node status: > crs_stat -t Name Type Target State Host -----------------------------------------------------------ora....SM1.asm application ONLINE ONLINE sonic ora....IC.lsnr application ONLINE OFFLINE ora.sonic.gsd application ONLINE ONLINE sonic
ora.sonic.ons application ONLINE ONLINE sonic ora.sonic.vip application ONLINE OFFLINE ora....SM2.asm application ONLINE ONLINE sprung ora....NG.lsnr application ONLINE OFFLINE ora.sprung.gsd application ONLINE ONLINE sprung ora.sprung.ons application ONLINE ONLINE sprung ora.sprung.vip application ONLINE OFFLINE ora....SM3.asm application ONLINE ONLINE sudeki ora....KI.lsnr application ONLINE OFFLINE ora.sudeki.gsd application ONLINE ONLINE sudeki ora.sudeki.ons application ONLINE ONLINE sudeki ora.sudeki.vip application ONLINE OFFLINE ora.<sid>.db application ONLINE ONLINE sudeki ora....e1.inst application ONLINE ONLINE sonic ora....e2.inst application ONLINE OFFLINE ora....e3.inst application ONLINE OFFLINE > crs_stat NAME=ora.sonic.ASM1.asm TYPE=application TARGET=ONLINE STATE=ONLINE on sonic NAME=ora.sonic.LISTENER_SONIC.lsnr TYPE=application TARGET=ONLINE STATE=OFFLINE NAME=ora.sonic.gsd TYPE=application TARGET=ONLINE STATE=ONLINE on sonic NAME=ora.sonic.ons TYPE=application TARGET=ONLINE STATE=ONLINE on sonic NAME=ora.sonic.vip TYPE=application TARGET=ONLINE STATE=OFFLINE NAME=ora.sprung.ASM2.asm TYPE=application TARGET=ONLINE STATE=ONLINE on sprung NAME=ora.sprung.LISTENER_SPRUNG.lsnr TYPE=application TARGET=ONLINE STATE=OFFLINE
NAME=ora.sprung.gsd TYPE=application TARGET=ONLINE STATE=ONLINE on sprung NAME=ora.sprung.ons TYPE=application TARGET=ONLINE STATE=ONLINE on sprung NAME=ora.sprung.vip TYPE=application TARGET=ONLINE STATE=OFFLINE NAME=ora.sudeki.ASM3.asm TYPE=application TARGET=ONLINE STATE=ONLINE on sudeki NAME=ora.sudeki.LISTENER_SUDEKI.lsnr TYPE=application TARGET=ONLINE STATE=OFFLINE NAME=ora.sudeki.gsd TYPE=application TARGET=ONLINE STATE=ONLINE on sudeki NAME=ora.sudeki.ons TYPE=application TARGET=ONLINE STATE=ONLINE on sudeki NAME=ora.sudeki.vip TYPE=application TARGET=ONLINE STATE=OFFLINE NAME=ora.<sid>.db TYPE=application TARGET=ONLINE STATE=ONLINE on sudeki NAME=ora.<sid>.<sid>1.inst TYPE=application TARGET=ONLINE STATE=ONLINE on sonic NAME=ora.<sid>.<sid>2.inst TYPE=application TARGET=ONLINE STATE=OFFLINE
NAME=ora.<sid>.<sid>3.inst TYPE=application TARGET=ONLINE STATE=OFFLINE On-line reference: http://www.databasejournal.com/features/oracle/article.php/3613116/Oracle-RACAdministration---Part-2-CRS-commands.htm > srvctl status database -d <SID> Instance <sid>1 is running on node sonic Additional Notes: 1. 2. 3. ons = notification services vip = virtual IP (needed for High Availability not currently configured on sims) asm = automatic storage management
Example commands: > srvctl start instance d <sid> I <sid>3 > srvctl stop instance d <sid> I <sid>2 > srvctl Usage: srvctl <command> <object> [<options>] command: enable|disable|start|stop|relocate|status|add|remove|modify|getenv|setenv|unsetenv|config objects: database|instance|service|nodeapps|asm|listener For detailed help on each command and object and its options use: srvctl <command> <object> -h Shared Storage: (Three options) 1. 2. 3. RAW management difficulty clustered file system (Solaris has the Sun Cluster Package) and there is also VxFS (preferred) RAW Device with ASM (installed and configured on sims)
> ps -ef | grep smon oracle 20128 14323 0 09:22:16 ? 0:01 asm_smon_+ASM2 SQLplus for ASM: > setenv ORACLE_SID +ASM2 Connect to the ASM via sqlplus: SQL> conn +asm2 as sysdba Enter password: asm2 Connected. ASM Disk: SQL> desc v$asm_disk;
Name Null? Type ----------------------------------------- -------- ---------------------------GROUP_NUMBER NUMBER DISK_NUMBER NUMBER COMPOUND_INDEX NUMBER INCARNATION NUMBER MOUNT_STATUS VARCHAR2(7) HEADER_STATUS VARCHAR2(12) MODE_STATUS VARCHAR2(7) STATE VARCHAR2(8) REDUNDANCY VARCHAR2(7) LIBRARY VARCHAR2(64) TOTAL_MB NUMBER FREE_MB NUMBER NAME VARCHAR2(30) FAILGROUP VARCHAR2(30) LABEL VARCHAR2(31) PATH VARCHAR2(256) UDID VARCHAR2(64) PRODUCT VARCHAR2(32) CREATE_DATE DATE MOUNT_DATE DATE REPAIR_TIMER NUMBER READS NUMBER WRITES NUMBER READ_ERRS NUMBER WRITE_ERRS NUMBER READ_TIME NUMBER WRITE_TIME NUMBER BYTES_READ NUMBER BYTES_WRITTEN NUMBER SQL> select distinct path from v$asm_disk; PATH -------------------------------------------------------------------------------/dev/rdsk/c0t6d0s5 /dev/rdsk/c0t6d0s6 /dev/rdsk/c0t6d0s7 /dev/rdsk/c0t7d0s0 SQL> !ls -l /dev/rdsk total 0 crw-r-r- 1 oracle oinstall 32, 64 Oct 25 18:22 c0t6d0s0 crw-r----- 1 root oinstall 32, 67 Nov 8 09:18 c0t6d0s3 crw-r----- 1 root oinstall 32, 68 Nov 8 09:18 c0t6d0s4 crw-r-r- 1 oracle oinstall 32, 69 Nov 8 16:23 c0t6d0s5 crw-r-r- 1 oracle oinstall 32, 70 Nov 8 16:23 c0t6d0s6 crw-r-r- 1 oracle oinstall 32, 71 Nov 8 16:23 c0t6d0s7 crw-r-r- 1 oracle oinstall 32, 0 Nov 8 09:22 c0t7d0s0
SQL> desc v$asm_diskgroup; Name Null? Type ----------------------------------------- -------- ---------------------------GROUP_NUMBER NUMBER NAME VARCHAR2(30) SECTOR_SIZE NUMBER BLOCK_SIZE NUMBER ALLOCATION_UNIT_SIZE NUMBER STATE VARCHAR2(11) TYPE VARCHAR2(6) TOTAL_MB NUMBER FREE_MB NUMBER REQUIRED_MIRROR_FREE_MB NUMBER USABLE_FILE_MB NUMBER OFFLINE_DISKS NUMBER UNBALANCED VARCHAR2(1) COMPATIBILITY VARCHAR2(60) DATABASE_COMPATIBILITY VARCHAR2(60) Home PM Database: > setenv ORACLE_SID <sid>1 > sqlplus SQL*Plus: Release 10.2.0.4.0 - Production on Mon Nov 8 16:33:15 2010 Copyright (c) 1982, 2007, Oracle. All Rights Reserved. Enter user-name: <user1> Enter password: <password1> Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options SQL> desc dba_data_files; Name Null? Type ----------------------------------------- -------- ---------------------------FILE_NAME VARCHAR2(513) FILE_ID NUMBER TABLESPACE_NAME VARCHAR2(30) BYTES NUMBER BLOCKS NUMBER STATUS VARCHAR2(9) RELATIVE_FNO NUMBER AUTOEXTENSIBLE VARCHAR2(3) MAXBYTES NUMBER MAXBLOCKS NUMBER INCREMENT_BY NUMBER USER_BYTES NUMBER
USER_BLOCKS NUMBER ONLINE_STATUS VARCHAR2(7) SQL> select file_name from dba_data_files; FILE_NAME -------------------------------------------------------------------------------+DATA/<sid>/datafile/users.266.733910449 +DATA/<sid>/datafile/sysaux.263.733903147 +DATA/<sid>/datafile/undotbs1.267.733903149 +DATA/<sid>/datafile/system.270.733903141 +DATA/<sid>/datafile/undotbs2.265.733903295 +DATA/<sid>/datafile/undotbs3.264.733903295 +DATA/<sid>/datafile/comp_d.272.733910265 +DATA/<sid>/datafile/comp_i.273.733910265 +DATA/<sid>/datafile/exc_d.274.733910267 +DATA/<sid>/datafile/exc_i.275.733910267 +DATA/<sid>/datafile/log_d.276.733910267 +DATA/<sid>/datafile/log_i.277.733910269 +DATA/<sid>/datafile/mmt_d.278.733910269 +DATA/<sid>/datafile/mmt_i.279.733910269 +DATA/<sid>/datafile/mst_d.280.733910271 +DATA/<sid>/datafile/mst_i.281.733910271 +DATA/<sid>/datafile/sta_d.282.733910271 +DATA/<sid>/datafile/sta_i.283.733910273 +DATA/<sid>/datafile/stm_d.284.733910273 +DATA/<sid>/datafile/stm_i.285.733910273 +DATA/<sid>/datafile/stu_d.286.733910275 +DATA/<sid>/datafile/stu_i.287.733910275 +DATA/<sid>/datafile/test_d.288.733910275 +DATA/<sid>/datafile/test_i.289.733910275 +DATA/<sid>/datafile/tme_d.290.733910277 +DATA/<sid>/datafile/tme_i.291.733910277 +DATA/<sid>/datafile/ntcemsts.292.733910277 +DATA/<sid>/datafile/work1.293.733910279 +DATA/msmt_2010_11_05.dbf +DATA/msmt_2010_11_06.dbf +DATA/msmt_2010_11_07.dbf +DATA/msmt_2010_11_08.dbf +DATA/msmt_2010_11_09.dbf +DATA/msmt_2010_11_10.dbf SQL> show parameter create NAME TYPE VALUE ------------------------------------ ----------- -----------------------------create_bitmap_area_size integer 8388608 create_stored_outlines string db_create_file_dest string +DATA db_create_online_log_dest_1 string db_create_online_log_dest_2 string
db_create_online_log_dest_3 string db_create_online_log_dest_4 string db_create_online_log_dest_5 string SQL> desc v$instance; Name Null? Type ----------------------------------------- -------- ---------------------------INSTANCE_NUMBER NUMBER INSTANCE_NAME VARCHAR2(16) HOST_NAME VARCHAR2(64) VERSION VARCHAR2(17) STARTUP_TIME DATE STATUS VARCHAR2(12) PARALLEL VARCHAR2(3) THREAD# NUMBER ARCHIVER VARCHAR2(7) LOG_SWITCH_WAIT VARCHAR2(15) LOGINS VARCHAR2(10) SHUTDOWN_PENDING VARCHAR2(3) DATABASE_STATUS VARCHAR2(17) INSTANCE_ROLE VARCHAR2(18) ACTIVE_STATE VARCHAR2(9) BLOCKED VARCHAR2(3) SQL> select instance_name from v$instance; INSTANCE_NAME ---------------<sid>1 // Global instance SQL> desc gv$instance; Name Null? Type ----------------------------------------- -------- ---------------------------INST_ID NUMBER INSTANCE_NUMBER NUMBER INSTANCE_NAME VARCHAR2(16) HOST_NAME VARCHAR2(64) VERSION VARCHAR2(17) STARTUP_TIME DATE STATUS VARCHAR2(12) PARALLEL VARCHAR2(3) THREAD# NUMBER ARCHIVER VARCHAR2(7) LOG_SWITCH_WAIT VARCHAR2(15) LOGINS VARCHAR2(10) SHUTDOWN_PENDING VARCHAR2(3) DATABASE_STATUS VARCHAR2(17) INSTANCE_ROLE VARCHAR2(18)
ACTIVE_STATE VARCHAR2(9) BLOCKED VARCHAR2(3) SQL> !ls -ltr /dev/rdsk total 0 crw-r-r- 1 oracle oinstall 32, 64 Oct 29 07:44 c0t6d0s0 crw-r----- 1 root oinstall 32, 68 Nov 8 16:39 c0t6d0s4 crw-r----- 1 root oinstall 32, 67 Nov 8 16:39 c0t6d0s3 crw-r-r- 1 oracle oinstall 32, 0 Nov 8 16:39 c0t7d0s0 crw-r-r- 1 oracle oinstall 32, 71 Nov 8 16:39 c0t6d0s7 crw-r-r- 1 oracle oinstall 32, 70 Nov 8 16:39 c0t6d0s6 crw-r-r- 1 oracle oinstall 32, 69 Nov 8 16:39 c0t6d0s5 // Note: Two disks must run as root regarding panic and startup // Note: s0 is for ASM // Note: s5, s6, s7 for resiliency
2.
a. Check packages: SUNWarc SUNWbtool SUNWhea SUNWlibm SUNWlibms SUNWsprot SUNWsprox SUNWtoo SUNWi1of SUNWi1cs SUNWi15cs SUNWxwfnt SUNWuiu8 SUNWulcf b. c. others). Check patches: 127111, 127127 Check OS limits for Oracle software owner (max-shm-memory and
3. a.
Setup storage (ASM over raw devices was used): Identify hard disks to be used in a global zone.
b. Partition them (Note (specific for RAC in zones): dont use slices that start at cylinder 0 for Oracle. If you do so, Oracle will overwrite partition table and disk will become inaccessible):
i. 5 partitions 512 MB each for oracle clusterware (2 for Oracle Cluster Registry and its mirror, 3 for voting disks). ii. One big partition for database files.
c. d.
Map all partitions create into each cluster node. Setup appropriate privileges for mapped partitions in each node.
4. a.
Setup network: Identify 9 IP IP addresses and 9 DNS names (3 for each node):
i. ii. iii.
b. On each node configure one network adapter for public IP and one for Private IP. c. Configure /etc/hosts on each node to resolve all 9 DNS names. Check names are resolved and ping works for public and private IPs (VIPs are inactive at this step).
5. Execute other pre-installation procedures according to Doc #1 (create users and groups if necessary, create folders, configure SSH user equivalency etc.).
6.
7. a. b. c.
Download distibutives: Oracle clusterware 10.2.0.1; Oracle RDBMS 10.2.0.1; 10.2.0.4 Patchset;
8. Install Oracle Clusterware 10.2.0.1 according to Doc #1. Dont run root.sh at the end of installation. Use runInstaller in silent mode.
9. Install 10.2.0.4 patchset into Oracle Clusterware home. Run root.sh at all nodes at the end. Use runInstaller in silent mode.
10. Check if clusterware processes are up and running. Reboot all nodes and check it again. Fix any problems found.
11.
a. As far as network adapters are shared, they have different names on each node. b. Each node should be configured to use its own interfaces for public and private network. To do so, use oifcfg from Clusterware Home. c. Note: VIPs will not start with shared network interfaces. Its expected and OK for tests.
12. Install RDBMS 10.2.0.1. Dont configure ASM and dont create database at this step. Use runInstaller in silent mode.
13. Install 10.2.0.4 patchset into Oracle RDBMS home. silent mode.
Use runInstaller in
14. Use DBCA in silent mode to configure and start ASM instances on each node. Check if ASM instances are up and can mount +DATA diskgroup.
15. Use DBCA in silent mode to create clustered database from General Purpose Database template using ASM as a storage.
16. Follow HomePM installation guides to create <SID> schema. Some scripts modifications are required: a. <path to <RUSS>PMInstallationFiles>/<RUSS>PMInstallationFiles/scripts/postinstall.conf :
i. ii. iii.
iv. v.
ORACLE_DB_RECOVERY_FILE_DEST=+DATA MEASUREMENT_TABLESPACE_DIR=+DATA
i.
17. Configure JBoss and vProbe to use new Oracle connection string with load balancing and connect-time failover enabled.
18. Start MS and make sure that database connections are balanced across cluster nodes.
Overview
The HAS package provides functionality in two areas, database replication and server mode switchover.
Database Replication
Each HAS installation can have a maximum of two oracle database instances. The HAS package will configure the Oracle databases to replicate tables using Oracle Streams. HAS exposes an interface for other Application packages to register database tables with the streaming replication.
Appendix
1. dba_t102.dbt <DatabaseTemplate name="dba_t102" description="" version="10.2.0.3.0"> <CommonAttributes> <option name="ISEARCH" value="false"/> <option name="OMS" value="false"/> <option name="JSERVER" value="true"/> <option name="SPATIAL" value="true"/> <option name="ODM" value="false"> <tablespace id="SYSAUX"/> </option> <option name="IMEDIA" value="true"/> <option name="ORACLE_TEXT" value="true"> <tablespace id="SYSAUX"/> </option> <option name="XDB_PROTOCOLS" value="true"> <tablespace id="SYSAUX"/> </option> <option name="CWMLITE" value="false"> <tablespace id="SYSAUX"/> </option> <option name="EM_REPOSITORY" value="true"> <tablespace id="SYSAUX"/> </option> <option name="SAMPLE_SCHEMA" value="false"/> </CommonAttributes> <Variables/> <CustomScripts Execute="false"/> <InitParamAttributes> <InitParams> <initParam name="audit_file_dest" value="{ORACLE_BASE}/admin/ {DB_UNIQUE_NAME}/adump"/> <initParam name="background_dump_dest" value="{ORACLE_BASE}/admin/ {DB_UNIQUE_NAME}/bdump"/> <initParam name="compatible" value="11.2.0"/> <initParam name="control_files" value="("{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/control01.ctl", "{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/control02.ctl", "{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/control03.ctl")"/> <initParam name="db_block_size" value="16" unit="KB"/> <initParam name="db_create_file_dest" value="/db1/oradata"/> <initParam name="db_recovery_file_dest" value="{ORACLE_BASE}/flash_recovery_area"/> <initParam name="db_recovery_file_dest_size" value="20480" unit="MB"/> <initParam name="dispatchers" value="(PROTOCOL=TCP) (SERVICE={SID}XDB)"/> <initParam name="global_names" value="true"/> <initParam name="java_pool_size" value="100" unit="MB"/> <initParam name="job_queue_processes" value="2"/> <initParam name="parallel_max_servers" value="0"/> <initParam name="parallel_min_servers" value="0"/> <initParam name="remote_login_passwordfile" value="EXCLUSIVE"/> <initParam name="undo_management" value="AUTO"/> <initParam name="undo_tablespace" value="UNDO1"/>
</InitParams> <MiscParams> <archiveLogMode>false</archiveLogMode> <initParamFileName>{ORACLE_HOME}/dbs/init{SID}.ora</initParamFileName> <characterSet>AL32UTF8</characterSet> <nationalCharacterSet>AL16UTF16</nationalCharacterSet> </MiscParams> <SPfile useSPFile="true">{ORACLE_HOME}/dbs/spfile{SID}.ora</SPfile> </InitParamAttributes> <StorageAttributes> <ControlfileAttributes id="Controlfile"> <maxDatafiles>100</maxDatafiles> <maxLogfiles>16</maxLogfiles> <maxLogMembers>3</maxLogMembers> <maxLogHistory>1</maxLogHistory> <maxInstances>8</maxInstances> <image name="control01.ctl" filepath="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/"/> <image name="control02.ctl" filepath="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/"/> </ControlfileAttributes> <DatafileAttributes id="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/sysaux01.dbf"> <tablespace>SYSAUX</tablespace> <temporary>false</temporary> <online>true</online> <status>0</status> <size unit="MB">120</size> <reuse>true</reuse> <autoExtend>true</autoExtend> <increment unit="KB">10240</increment> <maxSize unit="MB">-1</maxSize> </DatafileAttributes> <DatafileAttributes id="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/system01.dbf"> <tablespace>SYSTEM</tablespace> <temporary>false</temporary> <online>true</online> <status>0</status> <size unit="MB">300</size> <reuse>true</reuse> <autoExtend>true</autoExtend> <increment unit="MB">10</increment> <maxSize unit="MB">-1</maxSize> </DatafileAttributes> <DatafileAttributes id="{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/temp1.dbf"> <tablespace>TEMP1</tablespace> <temporary>false</temporary> <online>true</online> <status>0</status> <size unit="MB">32</size> <reuse>true</reuse> <autoExtend>true</autoExtend> <increment unit="KB">640</increment> <maxSize unit="MB">8192</maxSize> </DatafileAttributes>
<DatafileAttributes id="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/undo1_1.dbf"> <tablespace>UNDO1</tablespace> <temporary>false</temporary> <online>true</online> <status>0</status> <size unit="MB">200</size> <reuse>true</reuse> <autoExtend>true</autoExtend> <increment unit="KB">5120</increment> <maxSize unit="MB">-1</maxSize> </DatafileAttributes> <TablespaceAttributes id="SYSAUX"> <online>true</online> <offlineMode>1</offlineMode> <readOnly>false</readOnly> <temporary>false</temporary> <defaultTemp>false</defaultTemp> <undo>false</undo> <local>true</local> <blockSize>-1</blockSize> <allocation>1</allocation> <uniAllocSize unit="KB">-1</uniAllocSize> <initSize unit="KB">64</initSize> <increment unit="KB">64</increment> <incrementPercent>50</incrementPercent> <minExtends>1</minExtends> <maxExtends>4096</maxExtends> <minExtendsSize unit="KB">64</minExtendsSize> <logging>true</logging> <recoverable>false</recoverable> <maxFreeSpace>0</maxFreeSpace> <autoSegmentMgmt>true</autoSegmentMgmt> <bigfile>false</bigfile> <datafilesList> <TablespaceDatafileAttributes id="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/sysaux01.dbf"> <id>-1</id> </TablespaceDatafileAttributes> </datafilesList> </TablespaceAttributes> <TablespaceAttributes id="SYSTEM"> <online>true</online> <offlineMode>1</offlineMode> <readOnly>false</readOnly> <temporary>false</temporary> <defaultTemp>false</defaultTemp> <undo>false</undo> <local>true</local> <blockSize>-1</blockSize> <allocation>3</allocation> <uniAllocSize unit="MB">1</uniAllocSize> <initSize unit="MB">-1</initSize> <increment unit="MB">-1</increment> <incrementPercent>-1</incrementPercent> <minExtends>-1</minExtends> <maxExtends>-1</maxExtends>
<minExtendsSize unit="KB">-1</minExtendsSize> <logging>true</logging> <recoverable>false</recoverable> <maxFreeSpace>0</maxFreeSpace> <bigfile>false</bigfile> <datafilesList> <TablespaceDatafileAttributes id="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/system01.dbf"> <id>-1</id> </TablespaceDatafileAttributes> </datafilesList> </TablespaceAttributes> <TablespaceAttributes id="TEMP1"> <online>true</online> <offlineMode>1</offlineMode> <readOnly>false</readOnly> <temporary>true</temporary> <defaultTemp>true</defaultTemp> <undo>false</undo> <local>true</local> <blockSize>-1</blockSize> <allocation>1</allocation> <uniAllocSize unit="MB">1</uniAllocSize> <initSize unit="KB">-1</initSize> <increment unit="KB">-1</increment> <incrementPercent>-1</incrementPercent> <minExtends>-1</minExtends> <maxExtends>-1</maxExtends> <minExtendsSize unit="KB">-1</minExtendsSize> <logging>true</logging> <recoverable>false</recoverable> <maxFreeSpace>0</maxFreeSpace> <bigfile>false</bigfile> <datafilesList> <TablespaceDatafileAttributes id="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/temp1.dbf"> <id>-1</id> </TablespaceDatafileAttributes> </datafilesList> </TablespaceAttributes> <TablespaceAttributes id="UNDO1"> <online>true</online> <offlineMode>1</offlineMode> <readOnly>false</readOnly> <temporary>false</temporary> <defaultTemp>false</defaultTemp> <undo>true</undo> <local>true</local> <blockSize>-1</blockSize> <allocation>1</allocation> <uniAllocSize unit="KB">-1</uniAllocSize> <initSize unit="KB">512</initSize> <increment unit="KB">512</increment> <incrementPercent>50</incrementPercent> <minExtends>8</minExtends> <maxExtends>4096</maxExtends> <minExtendsSize unit="KB">512</minExtendsSize>
<logging>true</logging> <recoverable>false</recoverable> <maxFreeSpace>0</maxFreeSpace> <bigfile>false</bigfile> <datafilesList> <TablespaceDatafileAttributes id="{ORACLE_BASE}/oradata/ {DB_UNIQUE_NAME}/undo1_1.dbf"> <id>-1</id> </TablespaceDatafileAttributes> </datafilesList> </TablespaceAttributes> <RedoLogGroupAttributes id="1"> <reuse>false</reuse> <fileSize unit="KB">512000</fileSize> <Thread>1</Thread> <member ordinal="0" memberName="redo01.log" filepath="{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/"/> </RedoLogGroupAttributes> <RedoLogGroupAttributes id="2"> <reuse>false</reuse> <fileSize unit="KB">512000</fileSize> <Thread>1</Thread> <member ordinal="0" memberName="redo02.log" filepath="{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/"/> </RedoLogGroupAttributes> <RedoLogGroupAttributes id="3"> <reuse>false</reuse> <fileSize unit="KB">512000</fileSize> <Thread>1</Thread> <member ordinal="0" memberName="redo03.log" filepath="{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/"/> </RedoLogGroupAttributes> <RedoLogGroupAttributes id="4"> <reuse>false</reuse> <fileSize unit="KB">512000</fileSize> <Thread>1</Thread> <member ordinal="0" memberName="redo04.log" filepath="{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/"/> </RedoLogGroupAttributes> <RedoLogGroupAttributes id="5"> <reuse>false</reuse> <fileSize unit="KB">512000</fileSize> <Thread>1</Thread> <member ordinal="0" memberName="redo05.log" filepath="{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/"/> </RedoLogGroupAttributes> <RedoLogGroupAttributes id="6"> <reuse>false</reuse> <fileSize unit="KB">512000</fileSize> <Thread>1</Thread> <member ordinal="0" memberName="redo06.log" filepath="{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/"/> </RedoLogGroupAttributes> </StorageAttributes> </DatabaseTemplate>
2. 3.
russ_10201_enterprise.rsp russ_10204_patchset.rsp
4. backup_db #!/bin/ksh # @(#) $URL: svn://tourmaline/svnrepos/EmbeddedOracle/branches/oracle11.2.0.1/pkgFiles /db/bin/backup_db $ $Id: backup_db 102187 2010-10-08 13:12:56Z jon.clugston $ # # Copyright 2009, 2010 JDS Uniphase Corporation # # Product/Subsystem: <RUSS>/Database # # Description: # # # Change Activity: # # Reference When Who What This program manages database backups using Oracle RMAN.
# NETA-100 # PFM-374 # # # PFM-467 various 2010-06-27 P. Lamontagne Added cold backup option. Added replication option in support of streams replication. 2010-07-02 P. Lamontagne Fix environment issues for
# #
installation environments.
usage() { print -u2 " Manage database backups using Oracle RMAN.
usage: $0 [options] connect_spec configure|crosscheck|delete $0 [options] connect_spec backup [replication|cold] [nodelete] $0 [options] connect_spec list [summary] [all] [copy] $0 [options] connect_spec report $0 [options] connect_spec flash_usage $0 [options] connect_spec run script_file options: -log_dir - The directory to which execution logs are written. -log_file_prefix - The leading part of the log file name. Default is 'db_backup_'. -log_retention - The number of days to retain log files. Default is 14 days. -oracle_home - The value of ORACLE_HOME for the database. Defaults to the value of RDBMS_HOME in \$ADA_HOME/parms/RDC_parms. If \$ADA_HOME/parms/RDC_parms is not present, it defaults to the ORACLE_HOME environment variable. -oracle_sid - The value of ORACLE_SID for the database. Defaults to the value of RDBMS_SID in \$ADA_HOME/parms/RDC_parms. If \$ADA_HOME/parms/RDC_parms is not present, it defaults
to the ORACLE_SID environment variable. -showonly - List the RMAN commands to stdout. The commands are not executed. where backup - Backup the database and archivelogs using the recover copy method. nodelete - Does not remove obsolete backupsets. replication - Only backups archivelogs created prior to the minimum required checkpoint scn from dba_capture. cold - Shuts down the database to take a backup. This option must be used on databases in noarchivelog mode. connect_spec - The connection specification to the database. configure - Configure backup settings. crosscheck - Crosscheck the backup files with the recovery catalog. delete - Delete obsolete and expired backups. flash_usage - List the flash_recovery_area usage. list - List recoverable database backupsets and copies. all - Lists all backupsets, not just recoverable ones. copy - Lists backups that are copies in addition to backupsets. summary - Provides summary output instead of verbose output. report - List obsolete and unrecoverable backups. script_file - Run the contents of script_file in Oracle RMAN.
Note: The program assumes the environment is set correctly for the user to invoke Oracle RMAN.
" }
# # Queries the flash usage statistics from the database. # query_flash_usage() { "$debug" && set -o xtrace $sqlplus -S /nolog <<EOF connect $connect_spec as sysdba set linesize 150 set pagesize 60 set trimout on set feedback off col name format a50 col space_limit format 999,999,999,999,990 col space_used like space_limit col space_reclaimable like space_limit ttitle left 'Flash Recovery Area Definition'
compute sum of percent_space_used space_occupied reclaimable_occupied number_of_files percent_space_reclaimable space_available on report break on report
col space_limit format 999,990.99 heading 'SPACE(GB)|LIMIT' col space_occupied like space_limit heading 'SPACE(GB)|OCCUPIED' col reclaimable_occupied like space_limit heading 'SPACE(GB)|RECLAIMABLE' col percent_space_used format 990.99 heading 'PERCENT|SPACE USED' col percent_space_reclaimable like percent_space_used heading 'PERCENT SPACE|RECLAIMABLE' col space_available like space_limit heading 'SPACE|AVAILABLE' col number_of_files format 999,999,990 heading 'NUMBER|OF FILES' col percent_space_available like percent_space_used heading 'PERCENT|SPACE|AVAILABLE' ttitle left 'Flash Recovery Area Usage By File Type'
select u.file_type ,d.space_limit/(1024*1024*1024) space_limit ,u.percent_space_used ,d.space_limit * (u.percent_space_used/100)/ (1024*1024*1024) space_occupied ,u.percent_space_reclaimable ,d.space_limit * (u.percent_space_reclaimable/100) / (1024*1024*1024) reclaimable_occupied ,u.number_of_files from v\$recovery_file_dest d cross join v\$flash_recovery_area_usage u /
clear break clear compute ttitle left 'Flash Recovery Area Usage Summary' select d.space_limit / (1024*1024*1024) space_limit ,u.percent_space_used * 100 percent_space_used ,d.space_limit * u.percent_space_used / (1024*1024*1024) space_occupied ,u.percent_space_reclaimable * 100 percent_space_reclaimable ,(d.space_limit - (d.space_limit * u.percent_space_used) + (d.space_limit * u.percent_space_reclaimable) ) / (1024*1024*1024) space_available from v\$recovery_file_dest d cross join ( select sum(percent_space_used)/100 percent_space_used ,sum(percent_space_reclaimable)/100 percent_space_reclaimable from v\$flash_recovery_area_usage )u /
exit
EOF }
# # Returns the required_checkpoint_scn from dba_capture. # query_required_checkpoint_scn() { "$debug" && set -o xtrace $sqlplus -S /nolog <<EOF whenever sqlerror exit failure whenever oserror exit failure connect $connect_spec as sysdba set pagesize 0 set linesize 80
# Arguments: # # print_showonly() { "$debug" && set -o xtrace if [[ $# -gt 0 ]] then print -u1 "# RMAN Commands Listing:" while [[ $# -gt 0 ]] do print -u1 "$1" shift done fi } $1 - The string containing the commands to be shown.
# # Invokes the rman command. The command output may be written to a log file. # Arguments: # # # invoke_rman() { "$debug" && set -o xtrace print " connect target $connect_spec $1 - The string containing the rman commands to run. return - The rman return code.
# # Invokes rman. If the showonly command line argument was supplied, then # rman is not run but the commands are written to stdout. # Arguments: # # run_rman() { "$debug" && set -o xtrace typeset inline= if [[ -n "$opt_showonly" ]] then print_showonly "$*" return 0 fi invoke_rman "$1" $1 - The string containing the rman commands to run.
return $? }
# # Constructs the rman commands to be performed for the backup option. # Calls run_rman to execute rman. # rman_backup() { "$debug" && set -o xtrace typeset scn_clause= typeset cmd=" recover copy of database with tag 'whole_db_copy'; backup check logical incremental level 1 as compressed backupset tag='whole_db_copy' for recover of copy with tag 'whole_db_copy' database ; " if [[ -n "$opt_backup_replication" ]] then typeset req_scn= typeset req_scn_output=$(query_required_checkpoint_scn) if [[ $? -eq 0 ]] then req_scn="$(print "$req_scn_output" | cut -f2 -d:)" scn_clause="until scn=$req_scn" cmd="$cmd
backup archivelog $scn_clause delete all input; " else print -u2 "Failed to retrieve the required_checkpoint_scn. Aborting backup." return 1 fi fi
if [[ -z "$opt_backup_nodelete" ]] then cmd="$cmd delete noprompt obsolete; " fi run_rman "$cmd" return $? }
# # Performs a cold backup. # rman_backup_cold() { "$debug" && set -o xtrace typeset cmd=" startup force mount dba; backup
full tag='cold_backup_backupset' as compressed backupset check logical database ; " if [[ -z "$opt_backup_nodelete" ]] then cmd="$cmd delete noprompt obsolete; alter database open; " fi run_rman "$cmd" return $? }
# # Constructs the rman commands to be performed for the configure option. # Calls run_rman to execute rman. # rman_configure() { "$debug" && set -o xtrace
typeset cmd_rman="
sql 'alter system set control_file_record_keep_time=31 scope=both'; sql 'alter system set db_block_checking=medium scope=both'; configure retention policy to redundancy 1; configure backup optimization on; configure default device type to disk; configure controlfile autobackup on; configure device type disk parallelism 2 backup type to compressed backupset; configure datafile backup copies for device type disk to 1; configure archivelog backup copies for device type disk to 1; configure channel device type disk maxpiecesize 1g; configure maxsetsize to unlimited; configure encryption for database off; configure archivelog deletion policy to none; " run_rman "$cmd_rman" return $? }
# # Constructs the rman commands to perform the crosscheck function. # Calls run_rman to execute rman. # rman_crosscheck() { "$debug" && set -o xtrace typeset cmd=" crosscheck backup;
crosscheck copy of database; crosscheck archivelog all; crosscheck backup of controlfile; crosscheck backup of spfile; " run_rman "$cmd" return $? }
# # Constructs the rman commands to perform the delete function. # Calls run_rman to execute rman. # rman_delete() { "$debug" && set -o xtrace typeset cmd=" delete noprompt obsolete; delete noprompt expired backup; delete noprompt expired archivelog all; " run_rman "$cmd" }
# # Constructs the rman commands to perform the list function. # Calls run_rman to execute rman.
# rman_list_backups() { "$debug" && set -o xtrace typeset cmd=" list backup $opt_list_summary $opt_list_all; " if [[ -n "$opt_copy" ]] then cmd="$cmd list copy; " fi run_rman "$cmd" return $? }
# # Constructs the rman commands to perform the report function. # Calls run_rman to execute rman. # rman_report() { "$debug" && set -o xtrace typeset cmd=" report obsolete; report unrecoverable; "
# # Constructs the rman commands to perform the run function. # Calls run_rman to execute rman. # rman_run() { "$debug" && set -o xtrace typeset cmd="@${opt_run_script_file}" run_rman "$cmd" return $? }
# # Parse the command line arguments. # parse_cmdline_args() { if [[ $# -eq 0 ]] then return 1 fi # Parse command line flags while [[ $# -gt 0 ]] do
case "$1" in -help|-h) # Print the usage message. return 1 ;; -debug) debug=true set -o xtrace shift ;; -log_dir) # Get the directory to which the log file is written. shift opt_log_dir="$1" shift ;; -log_file_prefix) # Get the leading part of the log file name. shift opt_log_file_prefix="$1" shift ;; -log_retention) # The number of days to save the log files. shift if [[ -n "${1##+([0-9])}" ]] then print -u2 "Invalid number for log_retention: '$1'" return 1 fi
opt_log_retention="$1" shift ;; -oracle_home) # Value for ORACLE_HOME environment variable. shift opt_oracle_home="$1" shift ;; -oracle_sid) # ORACLE_SID of the database shift opt_oracle_sid="$1" shift ;; -showonly) # Generate the commands but do not run them. opt_showonly=y shift ;; -*) print -u2 "Unknown option: '$1'" return 1 ;; *) # Start of function arguments break ;; esac done # First function argument is the connect string.
connect_spec="$1" shift # Other function arguments if [[ $# -eq 0 ]] then print -u2 "Insufficient number of arguments." return 1 fi while ( [[ $# -gt 0 ]] ) do case "$1" in backup) # Performs a database backup. opt_backup=y shift while [[ $# -gt 0 ]] do case "$1" in nodelete) opt_backup_nodelete=y shift ;; replication) opt_backup_replication=y shift ;; cold)
opt_backup_cold=y shift ;; *) print -u2 "Unknown argument for backup option." return 1 ;; esac done if [[ -n "$opt_backup_replication" && -n "$opt_backup_cold" ]] then print -u2 "Invalid option combination: replication and cold." return 1; fi break ;; configure) # Configures Oracle rman backup parameters. opt_configure=y shift break ;; crosscheck) # Validate that the archivelogs and backupsets are # present and accounted for. opt_crosscheck=y shift break; ;;
delete) # Delete obsolete or unusable backups. opt_delete=y shift break ;; flash_usage) opt_flash_usage=y shift break ;; list) # List the available backupsets. opt_list=y shift while [[ $# -gt 0 ]] do case "$1" in all) opt_list_all= ;; copy) opt_copy=y ;; summary) opt_list_summary=$1 ;; *) print -u2 "Unknown argument for list option." return 1 ;; esac
shift done break; ;; report) # Report on obsolete and unrecoverable backup pieces. opt_report=y shift ;; run) # Run a script through rman. opt_run=y shift if [[ -n "$1" ]] then opt_run_script_file="$1" if ! [[ -f "$1" && -r "$1" ]] then print -u2 "Cannot read script file '$1'." return 1 fi shift else print -u2 "Must supply script file name for run option." return 1 fi break ;;
*) print -u2 "Unknown option: '$1'" return 1 ;; esac done if [[ $# -ne 0 ]] then print -u2 "Too many arguments." return 1; fi
return 0 }
typeset connect_spec= typeset date_command="date +'%Y-%m-%d %H:%M:%S'" typeset debug=false typeset log_file= typeset opt_backup= typeset opt_backup_cold=
typeset opt_backup_nodelete= typeset opt_backup_replication= typeset opt_configure= typeset opt_copy= typeset opt_crosscheck= typeset opt_delete= typeset opt_flash_usage= typeset opt_list= typeset opt_list_all=recoverable typeset opt_list_summary= typeset opt_log_dir= typeset opt_log_file_prefix="db_backup_" typeset -i opt_log_retention=14 typeset opt_oracle_sid= typeset opt_oracle_home= typeset opt_report= typeset opt_run= typeset opt_run_script_file= typeset opt_showonly= typeset program_name="$0" typeset rman_ret=
fi # # Process command line arguments. # cmdline_args="$*" parse_cmdline_args "$@" if [[ $? -ne 0 ]] then usage exit 1 fi
if [[ -z "$ADA_HOME" ]] then typeset mydir=$(dirname "$0") mydir=$( ( cd "$mydir"; pwd ) ) typeset up1=$(dirname "$mydir") ADA_HOME=$(dirname "$up1") export ADA_HOME fi typeset parm_file="$ADA_HOME/parms/RDC_parms" typeset parm_pgm="$ADA_HOME/com/bin/package_param"
if [[ -f "$parm_pgm" && -x "$parm_pgm" && -f "$parm_file" && -r "$parm_file" ]] then export ORACLE_HOME="$($parm_pgm RDC RDBMS_HOME)" export ORACLE_SID="$($parm_pgm RDC RDBMS_SID)" fi
typeset sqlplus=$ORACLE_HOME/bin/sqlplus typeset rman=$ORACLE_HOME/bin/rman export LD_LIBRARY_PATH=$ORACLE_HOME/lib unset LD_LIBRARY_PATH_64 if ! [[ -f $sqlplus ]] then print -u2 "$sqlplus not found" exit 1 fi if ! [[ -f $rman ]] then print -u2 "$rman not found" exit 1 fi
exec 4>&1 if [[ -n "$opt_log_dir" ]] then # # Create the log directory. # mkdir -p ${opt_log_dir} || { print -u2 "Cannot create log directory: '$opt_log_dir'" exit 1
} log_file="${opt_log_dir}/${opt_log_file_prefix}$(date "+%Y%m%d_%H%M %S").log" >$log_file || { print -u2 "Cannot create log file: '$log_file'" exit 1 } # # Start the coprocess to route output to the log file as well as stdout. # (tee -a $log_file 1>&4 2>&4)|& exec 1>&p 2>&1 fi
print -u1 "\n$program_name started at $(eval $date_command)" print -u1 "\nProgram arguments: '$0 $cmdline_args'" if [[ -n "$opt_log_dir" ]] then print -u1 "Logging results to file '$log_file'" fi
if [[ -n "$opt_flash_usage" ]] then
query_flash_usage rman_ret=$? fi
then # Make AIX match Solaris for the find mtime parameter. AIX includes the # current day in its calculation whereas Solaris does not. if [[ $(uname -s) == AIX ]] then ((opt_log_retention=${opt_log_retention}+1)) fi find $opt_log_dir -type f -mtime +${opt_log_retention} ! \( -name $log_file \) -name "${opt_log_file_prefix}[0-9][0-9][0-9][0-9][0-9][0-9][0-9][09]_[0-9][0-9][0-9][0-9][0-9][0-9].log" -print | xargs rm -f fi
print -u2 "\n$program_name completed at $(eval $date_command)" if [[ -n "$opt_log_dir" ]] then print -u2 "\nResults logged to '$log_file'." fi
return $rman_ret 5. Ad 6. Ad 7. ad