Wednesday, February 20, 2013

OEM 12c Manual Agent Installation



Get the agent software from OMS on the OMS server

** This only needs to be done 1 time per platform for agent installation this can be copied to other servers as required that are the same platform/OS this will stage the agent software installation on the OMS server.

1.       Login to the OMS using the emcli utility

# emcli login -username=sysman -password=passwordhere
Login successful

2.        Get List of supported platforms to see if your platform for an agent is there

# emcli get_supported_platforms

Getting list of platforms ...
Check the logs at /u00/app/oracle/Middleware/gc_inst/em/EMGC_OMS1/sysman/emcli/setup/.emcli/agent.log
About to access self-update code path to retrieve the platforms list..
Getting Platforms list  ...
-----------------------------------------------
Version = 12.1.0.2.0
 Platform = Linux x86-64
-----------------------------------------------
Platforms list displayed successfully.


3.       Get the agent for your platform, you will use the platform value from the previous step.

# emcli get_agentimage -destination=/home/oracle -platform="Linux x86-64" -version=12.1.0.2.0

Platform:Linux x86-64
Destination:/home/oracle
 === Partition Detail ===
Space free : 2 GB
Space required : 1 GB
Check the logs at /u00/app/oracle/Middleware/gc_inst/em/EMGC_OMS1/sysman/emcli/setup/.emcli/get_agentimage_2012-12-05_21-04-34-PM.log
Setting property ORACLE_HOME to:/u00/app/oracle/Middleware/oms
calling pulloneoffs with arguments:/u00/app/oracle/Middleware/oms/u00/app/oracle/Middleware/oms/sysman/agent/12.1.0.2.0_AgentCore_226.zip12.1.0.2.0linux_x64
Check this logs for more information: /u00/app/oracle/Middleware/oms/sysman/prov/agentpush/logs

Install Agent on Each Server
** For every server that needs an agent installation do the following steps
1.        Copy the extracted agent software to the node where agent is to be installed
               
# cd /u01/app/oracle
# mkdir software
# cd software
# scp :/home/oracle/12.1.0.2.0_AgentCore_226.zip ./

2.       unzip the copied agent installation

# unzip 12.1.0.2.0_AgentCore_226.zip

3.        Update the agent.rsp file, note that the ORACLE_HOSTNAME has to be update with each install, the example below is for guidance and will vary in your environment.

# vi agent.rsp

Example:
OMS_HOST=oem.domain.com
EM_UPLOAD_PORT=4901
AGENT_REGISTRATION_PASSWORD=weblogic031oemrep
AGENT_INSTANCE_HOME=/u01/app/oracle/product/agent/agent_inst
AGENT_PORT=3872
b_startAgent=true
ORACLE_HOSTNAME=server.domain.com
s_agentHomeName="agent12cR2"


4.        If a load balancer is utilized you will need to ensure the load balancer name is in the /etc/host or DNS otherwise the OMS server name you are using will need to be in /etc/hosts or in DNS

# vi /etc/hosts

# Example
192.168.1.112    oem.domain.com                   oem


5.       Execute the agent silent installation

# /u01/app/oracle/software/agentDeploy.sh AGENT_BASE_DIR=/u01/app/oracle/product/agent RESPONSE_FILE=/u01/app/oracle/software/agent.rsp

Example Output:
Validating the OMS_HOST & EM_UPLOAD_PORT
Executing command : /u01/app/oracle/product/agent/core/12.1.0.2.0/jdk/bin/java -classpath /u01/app/oracle/product/agent/core/12.1.0.2.0/jlib/agentInstaller.jar:/u01/app/oracle/product/agent/core/12.1.0.2.0/oui/jlib/OraInstaller.jar oracle.sysman.agent.installer.AgentInstaller /u01/app/oracle/product/agent/core/12.1.0.2.0 /u01/app/oracle/software /u01/app/oracle/product/agent -prereq

Validating oms host & port with url: http://oem.domain.com:4901/empbs/genwallet
Validating oms host & port with url: https://oem.domain.com:4901/empbs/genwallet
Return status:3
Unzipping the agentcoreimage.zip to /u01/app/oracle/product/agent ....
12.1.0.2.0_PluginsOneoffs_226.zip
Executing command : /u01/app/oracle/software/unzip -o /u01/app/oracle/software/12.1.0.2.0_PluginsOneoffs_226.zip -d /u01/app/oracle/product/agent
Executing command : /u01/app/oracle/product/agent/core/12.1.0.2.0/jdk/bin/java -classpath /u01/app/oracle/product/agent/core/12.1.0.2.0/oui/jlib/OraInstaller.jar:/u01/app/oracle/product/agent/core/12.1.0.2.0/oui/jlib/xmlparserv2.jar:/u01/app/oracle/product/agent/core/12.1.0.2.0/oui/jlib/srvm.jar:/u01/app/oracle/product/agent/core/12.1.0.2.0/oui/jlib/emCfg.jar:/u01/app/oracle/product/agent/core/12.1.0.2.0/jlib/agentInstaller.jar:/u01/app/oracle/product/agent/core/12.1.0.2.0/oui/jlib/share.jar oracle.sysman.agent.installer.AgentInstaller /u01/app/oracle/product/agent/core/12.1.0.2.0 /u01/app/oracle/software /u01/app/oracle/product/agent /u01/app/oracle/product/agent/agent_inst AGENT_BASE_DIR=/u01/app/oracle/product/agent AGENT_BASE_DIR=/u01/app/oracle/product/agent RESPONSE_FILE=/u01/app/oracle/software/agent.rsp


Executing agent install prereqs...
Executing command: /u01/app/oracle/product/agent/core/12.1.0.2.0/oui/bin/runInstaller -ignoreSysPrereqs -prereqchecker -silent -ignoreSysPrereqs -waitForCompletion  -prereqlogloc /u01/app/oracle/product/agent/core/12.1.0.2.0/cfgtoollogs/agentDeploy -entryPoint oracle.sysman.top.agent_Complete -detailedExitCodes PREREQ_CONFIG_LOCATION=/u01/app/oracle/product/agent/core/12.1.0.2.0/prereqs  -J-DORACLE_HOSTNAME=server.domain.com -J-DAGENT_PORT=3872 -J-DAGENT_BASE_DIR=/u01/app/oracle/product/agent
Prereq Logs Location:/u01/app/oracle/product/agent/core/12.1.0.2.0/cfgtoollogs/agentDeploy/prereq.log
Agent install prereqs completed successfully

Cloning the agent home...
Executing command: /u01/app/oracle/product/agent/core/12.1.0.2.0/oui/bin/runInstaller -ignoreSysPrereqs -clone -forceClone -silent -waitForCompletion -nowait ORACLE_HOME=/u01/app/oracle/product/agent/core/12.1.0.2.0 -responseFile /u01/app/oracle/software/agent.rsp  AGENT_BASE_DIR=/u01/app/oracle/product/agent AGENT_BASE_DIR=/u01/app/oracle/product/agent RESPONSE_FILE=/u01/app/oracle/software/agent.rsp -noconfig  ORACLE_HOME_NAME=agent12cR2 -force b_noUpgrade=true
Clone Action Logs Location:/u01/app/oraInventory/logs/cloneActions.log
Cloning of agent home completed successfully

Attaching sbin home...
Executing command: /u01/app/oracle/product/agent/core/12.1.0.2.0/oui/bin/runInstaller -ignoreSysPrereqs -attachHome -waitForCompletion -nowait ORACLE_HOME=/u01/app/oracle/product/agent/sbin ORACLE_HOME_NAME=sbin12c1 -force
Attach Home Logs Location:/u01/app/oracle/product/agent/core/12.1.0.2.0/cfgtoollogs/agentDeploy/AttachHome.log
Attach home for sbin home completed successfully.

Updating home dependencies...
Executing command: /u01/app/oracle/product/agent/core/12.1.0.2.0/oui/bin/runInstaller -ignoreSysPrereqs -updateHomeDeps -waitForCompletion HOME_DEPENDENCY_LIST={/u01/app/oracle/product/agent/sbin:/u01/app/oracle/product/agent/core/12.1.0.2.0,} -invPtrLoc /u01/app/oracle/product/agent/core/12.1.0.2.0/oraInst.loc -force
Update Home Dependencies Location:/u01/app/oracle/product/agent/core/12.1.0.2.0/cfgtoollogs/agentDeploy/UpdateHomeDeps.log
Update home dependency completed successfully.

Performing the agent configuration...
Executing command: /u01/app/oracle/product/agent/core/12.1.0.2.0/oui/bin/runConfig.sh ORACLE_HOME=/u01/app/oracle/product/agent/core/12.1.0.2.0 RESPONSE_FILE=/u01/app/oracle/product/agent/core/12.1.0.2.0/agent.rsp ACTION=configure MODE=perform COMPONENT_XML={oracle.sysman.top.agent.11_1_0_1_0.xml} RERUN=true
Configuration Log Location:/u01/app/oracle/product/agent/core/12.1.0.2.0/cfgtoollogs/cfgfw/CfmLogger.log
Agent Configuration completed successfully

The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root script to run
 /u01/app/oracle/product/agent/core/12.1.0.2.0/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
Agent Deployment Successful.
Agent deployment log location:
/u01/app/oracle/product/agent/core/12.1.0.2.0/cfgtoollogs/agentDeploy/agentDeploy_2012-12-05_22-12-33-PM.log
Agent deployment completed successfully.


7. Run the root.sh as indicated

# su -
# /u01/app/oracle/product/agent/core/12.1.0.2.0/root.sh

Finished product-specific root actions.
/etc exist

Creating /etc/oragchomelist file...
Finished product-specific root actions.


****** Note: All nodes in a cluster must have agent installed and discovered in OEM prior to being able to add any cluster items such as databases, ASM, etc.

Tuesday, July 24, 2012

Export Transfer Monitor Template Between OMSs


Requirements
To be able to export a monitoring template from an Oracle Enterprise Manager Repository so that it can be imported into another OEM Repository the Enterprise Manager Command Line Utility (emcli) must be installed and operational.

Steps

1.       Templates Available for Export, name must match exactly as indicated in OEM.
You can see a list via OEM Console or you can query the OEM repository database. 

Example:

SQL> SELECT TEMPLATE_NAME,TARGET_TYPE FROM MGMT_TEMPLATES;

TEMPLATE_NAME
----------------------------------------------------------------
TARGET_TYPE
----------------------------------------------------------------
Listner
oracle_listener

Prod DEV and TEST Databases
oracle_database

Production
oracle_database

Project Database Hosts
host

CPE Databases
oracle_database

2.       Select the template you want to extract and put into another OEM environment.

3.       Export the Template you want to put in the other OEM environment using the emcli utility.

Examples:

emcli export_template -name="Listner" -target_type=oracle_listener -output_file=/home/oracle/templates/Listener.template

emcli export_template -name='Prod DEV and TEST Databases' -target_type=oracle_database -output_file=/home/oracle/templates/prod_dev_and_test_databases.template

emcli export_template -name='Production' -target_type=oracle_database -output_file=/home/oracle/templates/Production.template

emcli export_template -name='Project Database Hosts' -target_type=host -output_file=/home/oracle/templates/Project_Database_hosts.template

emcli export_template -name='CPE Databases' -target_type=oracle_database -output_file=/home/oracle/templates/CPE_Databases.template

4.       Transfer the file created by the export of the template to the new OEM environment

5.       Import the template into the new OEM environment. 

Example:

emcli import_template -files="Listener.template;prod_dev_and_test_databases.template;Production.template;Project_Database_hosts.template;CPE_Databases.template"

OEM Grid Control Custom Target Properties


This procedure will walk through the requirements and steps to add and remove custom target properties as well as describe how to script populating the values for the target properties.  This procedure describes for the Oracle Enterprise Manager Grid Control 11g, while the steps are similar for earlier versions the EMCLI syntax may vary.  The custom target properties can be found for a target from the Grid Control Console in the target home page:

1.       Navigate to the Target homepage
2.       In the Related Links section, click 'Target Properties'

Requirements
To be able to add a custom target property or to script population of the target property the Oracle Enterprise Manager Command Line Interface (EM CLI) client must be installed.  The EM CLI OMS extensions are installed when the OMS is installed, but the client may require additional installation.
EMCLI Installation Requirements
·         Java version 1.6.0_25 or greater
·         Workstation running Solaris, Linux, HPUX, Tru64, AIX, or Windows with NTFS (client installation)

** See Oracle Documentation if installation is required.

Adding a Target Property
From the command line you will use the Oracle Command Line Interface (EM CLI) to add a target property, there is no way to add a target property from the Oracle Enterprise Manager Grid Control Console Interface.
1.       Log into server operating system where the Oracle Management Server is installed.
2.       From the operating system command line check the that emcli is installed
a.       emcli  (ensure that the emcli is in the PATH)
3.       Add a target property, example shows the addition of a target property to all database targets called URL.
a.       emcli add_target_property -target_type="oracle_database" -property="URL"
Note: You can use wild cards for target type to add to add a property to all target types
emcli add_target_property -target_type="*" -property="URL"

4.       Login to the OEM Grid Control GUI Console and navigate to an Oracle Database target properties.
a.       Navigate to the Target homepage
b.      In the Related Links section, click 'Target Properties'
c.       Check the property has been added.

Script Setting Target Property Value
You can set the target property value using the GUI console by going to the target home page then going to the Related Links Section “Target Properties”, however you may have a need to set the values through a process.  Again the EMCLI is required to be able to do this.

1.       Log into server operating system where the Oracle Management Server is installed.
2.       From the operating system command line check the that emcli is installed
a.       emcli
3.       Set the target property value, example shown shows an update to the URL target property of a database target called GRDPRD.
a.       emcli set_target_property_value -property_records="GRDPRD:oracle_database:URL:
www.mydatabase.com/GRDPRD"
4.       Login to the OEM Grid Control GUI Console and navigate to an Oracle Database target properties to check.
a.       Navigate to the Target homepage
b.      In the Related Links section, click 'Target Properties'
c.       Check the property value has been updated/changed

Remove Target Property
From the command line you will use the Oracle Command Line Interface (EM CLI) to remove a target property, there is no way to remove a target property from the Oracle Enterprise Manager Grid Control Console Interface.  ** Note: Cannot Remove Oracle Supplied Target properties.

1.       Log into server operating system where the Oracle Management Server is installed.

2.       From the operating system command line check the that emcli is installed
a.       emcli

3.       Remove a target property, example shows the removal of a target property from all database targets called URL
a.       emcli remove_target_properties –target_type="oracle_database" –property="URL"

4.       Login to the OEM Grid Control GUI Console and navigate to an Oracle Database target properties.
a.       Navigate to the Target homepage
b.      In the Related Links section, click 'Target Properties'
c.       Check the property has been removed.

Monday, February 13, 2012

ASM Move ASM Disk from one disk group to another, when using ASMlib rename the ASM Disk

1. determine the disk group asm disk that you want to move, this SQL will provide a list of the ASM diskgroups and their associated disks, ensure that you use the size values to determine that if you remove a disk from the disk group that you have enough free space to do so.

set linesize 100
set pagesize 1000
select dg.name, d.name, d.label, dg.type, d.path, d.state, d.OS_MB, d.TOTAL_MB, d.FREE_MB
from v$asm_disk d, v$asm_diskgroup dg
where dg.group_number = d.group_number
order by dg.name, d.name ;


2. Select the disk to remove, in this case we will select RECO3 to remove from the RECO Disk Group.

set head off
set linesize 100

set pagesize 1000
select dg.name, d.name, d.label, dg.type, d.path, d.state, d.OS_MB, d.TOTAL_MB, d.FREE_MB
from v$asm_disk d, v$asm_diskgroup dg
where dg.group_number = d.group_number
   and dg.name = 'RECO'
order by dg.name, d.name ;

RECO RECO1 RECO1 EXTERN
ORCL:RECO1
NORMAL 24999 24999 15606

RECO RECO2 RECO2 EXTERN
ORCL:RECO2
NORMAL 24999 24999 15605


RECO RECO3 RECO3 EXTERN
ORCL:RECO3
NORMAL 24999 24999 15607


3. Remove the ASM disk from the disk group

SQL> alter diskgroup RECO drop disk RECO3 ;

Diskgroup altered.


4. monitor the disk group rebal operation that removes the disk until complete.

SQL> select * from v$asm_operation;

GROUP_NUMBER OPERA STAT POWER ACTUAL SOFAR EST_WORK EST_RATE EST_MINUTES
------------ ----- ---- ---------- ---------- ---------- ---------- ---------- -----------
ERROR_CODE
--------------------------------------------
3 REBAL RUN 1 1 570 10189 903 10

1 row selected.


SQL> select * from v$asm_operation;

no rows selected


5. ensure the disk is no longer part of the diskgroup

set linesize 100
set pagesize 1000
select dg.name, d.name, d.label, dg.type, d.path, d.state, d.OS_MB, d.TOTAL_MB, d.FREE_MB
from v$asm_disk d, v$asm_diskgroup dg
where dg.group_number = d.group_number
and dg.name = 'RECO'
order by dg.name, d.name ;

NAME NAME LABEL TYPE
------------------------------ ------------------------------ ------------------------------- ------
PATH
----------------------------------------------------------------------------------------------------
STATE OS_MB TOTAL_MB FREE_MB
-------- ---------- ---------- ----------
RECO RECO1 RECO1 EXTERN
ORCL:RECO1
NORMAL 24999 24999 10912

RECO RECO2 RECO2 EXTERN
ORCL:RECO2
NORMAL 24999 24999 10909


6. To rename the ASM disk removed to match the disk names of the disk group you are putting the disk into
in this example we are taking the disk from RECO (disk RECO3) and putting into the DATA disk group, some may want to rename the ASM disk from RECO03 to DATA5 to match the new diskgroup
** DATA4 Name is already used as an ASM disk name, but not and ASM lib disk name.

set linesize 100
set pagesize 1000
select dg.name, d.name, d.label, dg.type, d.path, d.state, d.OS_MB, d.TOTAL_MB, d.FREE_MB
from v$asm_disk d, v$asm_diskgroup dg
where dg.group_number = d.group_number
and dg.name = 'DATA'
order by dg.name, d.name ;


NAME NAME LABEL TYPE
------------------------------ ------------------------------ ------------------------------- ------
PATH
----------------------------------------------------------------------------------------------------
STATE OS_MB TOTAL_MB FREE_MB
-------- ---------- ---------- ----------
DATA DATA1 DATA1 EXTERN
ORCL:DATA1
NORMAL 24999 24999 8192


DATA DATA2 DATA2 EXTERN
ORCL:DATA2
NORMAL 24999 24999 8193

DATA DATA3 DATA3 EXTERN
ORCL:DATA3
NORMAL 24999 24999 8195

DATA DATA4 STAGEASMDATA4 EXTERN
ORCL:STAGEASMDATA4
NORMAL 24995 24995 8192


7. Ensure the name we want to use is not used in an ASM Name already.

set linesize 100
set pagesize 1000
column disk_group_name format a20
column disk_file_path format a30
column disk_file_name format a20
column disk_file_fail_group format a20
SELECT
NVL(a.name, '[CANDIDATE]') disk_group_name
, b.path disk_file_path
, b.name disk_file_name
, b.failgroup disk_file_fail_group
FROM
v$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number)
ORDER BY
a.name;

DISK_GROUP_NAME DISK_FILE_PATH     DISK_FILE_NAME FILE_FAIL_GROUP
--------------- ------------------ -------------- ---------------DATA            ORCL:STAGEASMDATA4 DATA4          DATA4
DATA            ORCL:DATA1         DATA1          DATA1
DATA            ORCL:DATA2         DATA2          DATA2
DATA            ORCL:DATA3         DATA3          DATA3
OCR_VOTE        ORCL:OCR_VOTE01    OCR_VOTE01     OCR_VOTE01
OCR_VOTE        ORCL:OCR_VOTE03    OCR_VOTE03     OCR_VOTE03
OCR_VOTE        ORCL:OCR_VOTE02    OCR_VOTE02     OCR_VOTE02
RECO            ORCL:RECO2         RECO2          RECO2
RECO            ORCL:RECO1         RECO1          RECO1

** As we see here the ASMlib name and DISKFILE NAME do not match, this will cause as disk name issue so we have to give our new disk a different name to avoid a duplicate name in the ASM instance.
In our case we will use DATA5 as it is not used already.


8. When using ASM lib you can rename the disk using ASM lib best to do as root, when using OS level, check the OS level name and change it there for most operating systems there is no change need unless the device name changes. When using the OS check the device name which would be the disk path as they can be name when using multi path so use the configuration there to rename.

[root]# /etc/init.d/oracleasm querydisk -p RECO3
Disk "RECO3" is a valid ASM disk
/dev/sdk1: LABEL="RECO3" TYPE="oracleasm"

[root]# /etc/init.d/oracleasm force-renamedisk RECO3 DATA5
Renaming disk "RECO3" to "DATA5": [ OK ]


9. list the disks if using ASMlib, to ensure the disk is renamed.

[root]# /etc/init.d/oracleasm listdisks
DATA1
DATA2
DATA3
DATA5
OCR_VOTE01
OCR_VOTE02
OCR_VOTE03
RECO1
RECO2
STAGEASMDATA4


10. Ensure disk is a candidate disk now to be added to a diskgroup.

set linesize 100
set pagesize 1000
column disk_group_name format a20
column disk_file_path format a30
column disk_file_name format a20
column disk_file_fail_group format a20
SELECT
NVL(a.name, '[CANDIDATE]') disk_group_name
, b.path disk_file_path
, b.name disk_file_name
, b.failgroup disk_file_fail_group
FROM
v$asm_diskgroup a RIGHT OUTER JOIN v$asm_disk b USING (group_number)
ORDER BY
a.name;

DISK_GROUP_NAME DISK_FILE_PATH DISK_FILE_NAME FILE_FAIL_GROUP
--------------- ------------------ -------------- ---------------
DATA ORCL:STAGEASMDATA4 DATA4 DATA4
DATA ORCL:DATA1 DATA1 DATA1
DATA ORCL:DATA2 DATA2 DATA2
DATA ORCL:DATA3 DATA3 DATA3
OCR_VOTE ORCL:OCR_VOTE01 OCR_VOTE01 OCR_VOTE01
OCR_VOTE ORCL:OCR_VOTE03 OCR_VOTE03 OCR_VOTE03
OCR_VOTE ORCL:OCR_VOTE02 OCR_VOTE02 OCR_VOTE02
RECO ORCL:RECO2 RECO2 RECO2
RECO ORCL:RECO1 RECO1 RECO1
[CANDIDATE] ORCL:DATA5


9. Add disk to disk to group, in our case disk DATA4 to diskgroup DATA

SQL> alter diskgroup DATA add disk 'ORCL:DATA5' ;

Diskgroup altered.


10. Monitor Rebal operation that is bringing in the new disk


SQL> select * from v$asm_operation;

GROUP_NUMBER OPERA STAT POWER ACTUAL SOFAR EST_WORK EST_RATE EST_MINUTES
------------ ----- ---- ---------- ---------- ---------- ---------- ---------- -----------
ERROR_CODE
--------------------------------------------
1 REBAL RUN 1 1 682 13467 987 12

SQL> select * from v$asm_operation;

no rows selected


11. Ensure the disk is now part of the diskgroup

set linesize 100
set pagesize 1000
select dg.name, d.name, d.label, dg.type, d.path, d.state, d.OS_MB, d.TOTAL_MB, d.FREE_MB
from v$asm_disk d, v$asm_diskgroup dg
where dg.group_number = d.group_number
and dg.name = 'DATA'
order by dg.name, d.name ;

NAME NAME LABEL TYPE
------------------------------ ------------------------------ ------------------------------- ------
PATH
----------------------------------------------------------------------------------------------------
STATE OS_MB TOTAL_MB FREE_MB
-------- ---------- ---------- ----------
DATA DATA1 DATA1 EXTERN
ORCL:DATA1
NORMAL 24999 24999 11525

DATA DATA2 DATA2 EXTERN
ORCL:DATA2
NORMAL 24999 24999 11525

DATA DATA3 DATA3 EXTERN
ORCL:DATA3
NORMAL 24999 24999 11525

DATA DATA4 STAGEASMDATA4 EXTERN
ORCL:STAGEASMDATA4
NORMAL 25995 25995 11985

DATA DATA5 DATA5 EXTERN
ORCL:DATA5
NORMAL 24999 24999 11527

Thursday, August 11, 2011

Optimal Undo Tablespace Size and Undo Retention

The undo tablespace and its size is related to the retention period and the transactional activity of the database.  These must be regularly reviewed and check to ensure that 1, you are not trying to have a retention period that the undo tablespace can not handle, 2 that you are size properly so that you do not encounter the dreaded ORA-01555 snapshot too old.

Optimal Undo Size and Retention
I have seen many environments where the undo tablespace is far to small for the undo retention setting and they target undo retention the environment requires.  This is due to the fact that the undo tablespace was size and undo retention set, but never rechecked or updated as the environment grew or activity changed.  Therefore if the expectation is that a flashback query can go back 2 hours, but the tablespace is too small the reality is that they really can not go back 2 hours.

First we need to check the Optimal Undo Size based on our desired retention as in most environments this will change regularly based on increases or decreases in the trasnactional activity.

The script below will ask for the desired undo retention, then will examine your database and tell you the optimal undo retention setting for the current environment as the undo tablespace size and transactional activity indicates, but will also show you what the size of the undo tablespace needs to be to be able to support the desired undo retention you have entered.

---------------------------------------------------------------------------------
-- Script: see_optimal_undo_retention.sql
-- Author: Michael Messina, Management Consultant TUSC a Rolta Company
--
-- Description:  Will calculate based on undo utilization and undo size
--               the optimal value for undo_retention.
---------------------------------------------------------------------------------
set serveroutput on size 1000000
set feedback off

ACCEPT desired_undo_retention PROMPT "Enter Desired Undo Retention in Seconds ->"

DECLARE
   v_desired_undo_retention          NUMBER := &desired_undo_retention ;
   v_block_size                      NUMBER ;
   v_undo_size                       NUMBER ;
   v_undo_blocks_per_sec             NUMBER ;
   v_optimal_undo_retention          NUMBER ;
   v_current_undo_retention          NUMBER ;
   v_undo_size_desired_ret           NUMBER ;
  
BEGIN
   -- get the current undo retention setting
   select TO_NUMBER(value)
   INTO v_current_undo_retention
   FROM v$parameter
   WHERE name = 'undo_retention' ;
  
   -- Calculate Actual Undo Size
   SELECT SUM(a.bytes)
   INTO v_undo_size
   FROM v$datafile a,
        v$tablespace b,
        dba_tablespaces c
   WHERE c.contents = 'UNDO'
     AND c.status = 'ONLINE'
     AND b.name = c.tablespace_name
     AND a.ts# = b.ts#;

   -- Calcuate the Undo Blocks per Second
   SELECT MAX(undoblks/((end_time-begin_time)*3600*24))
   INTO v_undo_blocks_per_sec
   FROM v$undostat ;

   -- Get the database block size
   SELECT TO_NUMBER(value)
   INTO v_block_size
   FROM v$parameter
   WHERE name = 'db_block_size';

   v_optimal_undo_retention := v_undo_size/(v_block_size * v_undo_blocks_per_sec) ;
   v_undo_size_desired_ret := ((v_block_size * v_undo_blocks_per_sec) * (v_desired_undo_retention)) / 1024 / 1024 ;
  
   DBMS_OUTPUT.PUT_LINE ('              Current undo Size --> ' || TO_CHAR(v_undo_size/1024/1024) || 'MB') ;
   DBMS_OUTPUT.PUT_LINE (' Current undo_retention Setting --> ' || TO_CHAR(v_current_undo_retention) || ' Seconds') ;
   DBMS_OUTPUT.PUT_LINE (' Optimal undo_retention Setting --> ' || TO_CHAR(ROUND(v_optimal_undo_retention,2)) || ' Seconds') ;
   DBMS_OUTPUT.PUT_LINE (' Desired undo_retention Setting --> ' || TO_CHAR(ROUND(v_desired_undo_retention,2)) || ' Seconds') ;
   DBMS_OUTPUT.PUT_LINE ('Undo Size for desired retention --> ' || TO_CHAR(ROUND(v_undo_size_desired_ret,2)) || 'MB') ;
END ;
/


Example Execution of script:
SQL> @see_optimal_undo_retention.sql
Enter Desired Undo Retention in Seconds ->7200
old   2:    v_desired_undo_retention          NUMBER := &desired_undo_retention ;
new   2:    v_desired_undo_retention          NUMBER := 7200 ;
Current undo Size --> 1980MB
Current undo_retention Setting --> 900 Seconds
Optimal undo_retention Setting --> 100504.96 Seconds
Desired undo_retention Setting --> 7200 Seconds
Undo Size for desired retention --> 141.84MB


In this example on a very small database with no activity I want a retention of 2 hours, The output shows the current undo tablespace size, the current undo retention setting, the optimal undo retention setting indicates what I could make the undo retention based on the current activity and size of the undo tablespace, the desired undo retention that I entered and the undo tablespace size required to meet my desired undo retention setting.