Unit 5.2 Database Administration
Unit 5.2 Database Administration
In oracle, Undo data, also known as rollback data, is information stored in the database that records the changes made
by transactions. The information allows database to undo changes in case of rollback. Undo data is pre-modified data
that is recorded or captured for all transactions which changes data.
In other words, Oracle creates and manages data that is used to roll back, or undo, changes to the database. Such
information consists of records of the actions of transactions, primarily before they are committed. These records are
collectively referred to as undo.
Undo records are used to undo changes that were made to the database by the uncommitted transaction. Undo records
provide read consistency by maintaining the before image of the data for users who are accessing the data at the same
time that another user is changing it. During database recovery, undo records are used to undo any uncommitted
changes applied from the redo log to the data files.
Why we need Undo Data ?
1.Rollback Operations: Undo data allows transactions to be rolled back to their previous state in case of a rollback
operation (e.g., due to an error or explicit rollback command).
2.Recovery: Undo data is essential for database recovery operations, such as rolling forward or rolling back changes
during instance recovery or media recovery.
3.Read Consistency: Undo data provides read consistency by maintaining previous versions of data. It ensures that
queries return consistent results, even when other transactions are modifying the data concurrently.
4.PITR using Oracle Flashback Query and Recovery from logical corruptions using oracle flashback features.
You can also explicitly create an undo tablespace. Upon starting the database instance, Oracle automatically selects the
first available undo tablespace. If no undo tablespace is available, the instance starts without one, and undo records are
stored in the SYSTEM tablespace. This practice is not recommended, and a warning message is written to the alert log
file.
If the database contains multiple undo tablespaces, you can optionally specify which one to use at startup by setting the
UNDO_TABLESPACE initialization parameter. For example:
UNDO_TABLESPACE = undotbs_01
undotbs_01
If the specified tablespace does not exist, the STARTUP command will fail. The UNDO_TABLESPACE parameter can also be
used to assign a specific undo tablespace to an instance in an Oracle Real Application Clusters (RAC) environment.
Alternatively, the database can operate in manual undo management mode, where undo space is managed through
rollback segments without using an undo tablespace.
1.Create UNDO Tablespace :
Administering Undo Data
•You can create a specific undo tablespace using the UNDO TABLESPACE clause of the CREATE DATABASE statement OR The CREATE
UNDO TABLESPACE statement is the same as the CREATE TABLESPACE statement
ALTER TABLESPACE undotbs_01 ADD DATAFILE '/u01/oracle/rbdb1/undo0102.dbf' AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED;
CREATE DATABASE rbdb1
CONTROLFILE REUSE
.
.
.
UNDO TABLESPACE undotbs_01 DATAFILE '/u01/oracle/rbdb1/undo0101.dbf';
2.Undo Tablespace Management:
You can alter an undo tablespaces using the ALTER TABLESPACE statement.
However, since most aspects of undo tablespaces are system managed, you need only be concerned with the following
actions:
•Adding a data file
•Renaming a data file
•Bringing a data file online or taking it offline
•Beginning or ending an open backup on a data file
•Enabling and disabling undo retention guarantee
These are also the only attributes you are permitted to alter.
If an undo tablespace runs out of space, or you want to prevent it from doing so, you can add more files to it or resize
existing data files.
ALTER TABLESPACE undotbs_01 ADD DATAFILE '/u01/oracle/rbdb1/undo0102.dbf' AUTOEXTEND ON NEXT 1M
MAXSIZE UNLIMITED;
Administering Undo Data
2.Automatic Undo Management (AUM):
•Enable Automatic Undo Management (AUM) to let Oracle manage undo space automatically. You can enable AUM using the following
command: ALTER SYSTEM SET undo_management = 'AUTO';
3.Undo Retention Adjustment:
•Adjust the undo retention parameter (UNDO_RETENTION) to ensure that undo data is retained long enough to support the needs of
your application.
4.Monitoring and Tuning Undo Performance:
•Regularly monitor undo performance using AWR reports or Oracle Enterprise Manager.
•Tune undo performance by adjusting parameters such as UNDO_RETENTION, UNDOTBS1, and UNDO_TABLESPACE based on workload
requirements.
5.Monitoring and Resolving Undo Space Issues:
•Monitor for undo space issues such as space exhaustion or undo tablespace full events.
•Resolve undo space issues by adding additional data files to the undo tablespace, increasing the size of existing data files, or adjusting
undo retention.
6.Undo Advisor:
•Use the Undo Advisor to estimate the undo tablespace size and recommend changes to undo retention settings based on workload
characteristics.
Configure Fixed Size Undo
Automatic tuning of undo retention typically achieves better results with a fixed-size undo tablespace. If you decide to use a fixed-
size undo tablespace, then the Undo Advisor can help you estimate needed capacity. You can access the Undo Advisor through
Oracle Enterprise Manager Database Express (EM Express) or through the DBMS_ADVISOR PL/SQL package.
The Undo Advisor relies for its analysis on data collected in the Automatic Workload Repository (AWR). It is therefore important
that the AWR have adequate workload statistics available so that the Undo Advisor can make accurate recommendations. For
newly created databases, adequate statistics may not be available immediately. In such cases, continue to use the default auto-
extending undo tablespace until at least one workload cycle completes.
An adjustment to the collection interval and retention period for AWR statistics can affect the precision and the type of
recommendations that the advisor produces
To use the Undo Advisor, you first estimate these two values:
•The length of your expected longest running query
After the database has completed a workload cycle, you can view the Longest Running Query field on the System
Activity subpage of the Automatic Undo Management page.
•The longest interval that you will require for Oracle Flashback operations For example, if you expect to run Oracle
Flashback queries for up to 48 hours in the past, your Oracle Flashback requirement is 48 hours. We ca then take the
maximum of these two values and use that value as input to the Undo Advisor. Running the Undo Advisor does not alter
the size of the undo tablespace. The advisor just returns a recommendation. You must use ALTER DATABASE statements
to change the tablespace data files to fixed sizes.
The following example assumes that the undo tablespace has one auto-extending data file named undotbs.dbf. The example
changes the tablespace to a fixed size of 300MB.
ALTER DATABASE DATAFILE '/oracle/dbs/undotbs.dbf' RESIZE 300M;
ALTER DATABASE DATAFILE '/oracle/dbs/undotbs.dbf' AUTOEXTEND OFF;
Monitoring Undo Data
• Undo Tablespace Size:
Regularly monitor the size of the undo tablespace to ensure it has sufficient space to accommodate undo data
for all active transactions. You can check this using the following query:
• Undo Retention:
Monitor undo retention to ensure that it's set appropriately based on the database workload. Use the
following query to check the undo retention time:
When retention guarantee is enabled, the specified minimum undo retention is assured; the database never overwrites
unexpired undo data, even if it leads to transaction failures due to insufficient space in the undo tablespace. By contrast, if
retention guarantee is not enabled, the database may overwrite unexpired undo data when space is low, potentially
reducing the overall undo retention for the system. This option is disabled by default.
Enabling retention guarantee can result in multiple DML operations failing. Exercise caution when enabling this feature.
Retention guarantee can be enabled by specifying the RETENTION GUARANTEE clause for the undo tablespace when
creating it using either the CREATE DATABASE or CREATE UNDO TABLESPACE statement. Alternatively, you can specify this
clause later in an ALTER TABLESPACE statement. You can disable retention guarantee using the RETENTION NOGUARANTEE
clause.
To determine the retention guarantee setting for the undo tablespace, you can query the DBA_TABLESPACES view. The
RETENTION column contains values of GUARANTEE, NOGUARANTEE, or NOT APPLY, with NOT APPLY used for tablespaces
other than the undo tablespace.
Guarantee Retention Period
In oracle database to ensure the success of long-running queries or Oracle Flashback operations, you have the option to
enable retention guarantee.
When retention guarantee is enabled, the specified minimum undo retention is assured; the database never overwrites
unexpired undo data, even if it leads to transaction failures due to insufficient space in the undo tablespace. By contrast, if
retention guarantee is not enabled, the database may overwrite unexpired undo data when space is low, potentially
reducing the overall undo retention for the system. This option is disabled by default.
Enabling retention guarantee can result in multiple DML operations failing. Exercise caution when enabling this feature.
Retention guarantee can be enabled by specifying the RETENTION GUARANTEE clause for the undo tablespace when
creating it using either the CREATE DATABASE or CREATE UNDO TABLESPACE statement. Alternatively, you can specify this
clause later in an ALTER TABLESPACE statement. You can disable retention guarantee using the RETENTION NOGUARANTEE
clause.
To determine the retention guarantee setting for the undo tablespace, you can query the DBA_TABLESPACES view. The
RETENTION column contains values of GUARANTEE, NOGUARANTEE, or NOT APPLY, with NOT APPLY used for tablespaces
other than the undo tablespace.