Friday, 19 May 2017

Multitenant : Local Undo Mode in Oracle Database 12c Release 2

In Oracle Database 12c Release 1 all containers in an instance shared the same undo tablespace. In Oracle 12c Release 2 each container in an instance can use its own undo tablespace. This new undo management mechanism is called local undo mode, whilst that of previous releases is now known as shared undo mode. Local undo mode is the default mode in newly created databases, so you will probably only need to consider switching undo modes for upgraded instances.
You should switch to local undo mode unless you have a compelling reason not to. Some of the new multitenant features in 12.2 rely on local undo. This article demonstrates how to switch to shared undo mode, only so you can see the process of switching back to local undo mode.
  • Switching to Shared Undo Mode 

We can display the current undo mode using the following query, which shows we are currently in local undo mode.

COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A30

SELECT property_name, property_value
FROM   database_properties
WHERE  property_name = 'LOCAL_UNDO_ENABLED';

PROPERTY_NAME                  PROPERTY_VALUE
------------------------------ ------------------------------
LOCAL_UNDO_ENABLED             TRUE

SQL>

We also check for the presence of the undo tablespaces for the root container (con_id=1) and user-defined pluggable database (con_id=3).

SELECT con_id, tablespace_name
FROM   cdb_tablespaces
WHERE  tablespace_name LIKE 'UNDO%'
ORDER BY con_id;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         1    UNDOTBS1
         3    UNDOTBS1

SQL>

The following commands demonstrate how to switch to shared undo mode using the ALTER DATABASE LOCAL UNDO OFF command.

CONN / AS SYSDBA

SHUTDOWN IMMEDIATE;
STARTUP UPGRADE;

ALTER DATABASE LOCAL UNDO OFF;

SHUTDOWN IMMEDIATE;
STARTUP;

Once the instance is restarted we can check the undo mode again and see we are now in shared undo mode.

COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A30

SELECT property_name, property_value
FROM   database_properties
WHERE  property_name = 'LOCAL_UNDO_ENABLED';

PROPERTY_NAME                  PROPERTY_VALUE
------------------------------ ------------------------------
LOCAL_UNDO_ENABLED             FALSE

SQL>

We still have the local undo tablespace for the user-defined pluggable database (con_id=3), even though the instance will no longer use it.

SELECT con_id, tablespace_name
FROM   cdb_tablespaces
WHERE  tablespace_name LIKE 'UNDO%'
ORDER BY con_id;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         1    UNDOTBS1
         3    UNDOTBS1

SQL>

For clarity, we should remove it.

ALTER SESSION SET CONTAINER = pdb1;

SELECT file_name
FROM   dba_data_files
WHERE  tablespace_name = 'UNDOTBS1';

--------------------------------------------------------------------------
/u02/app/oracle/oradata/cdb1/pdb1/undotbs01.dbf

SQL>


DROP TABLESPACE undotbs1;

Tablespace dropped.

SQL>

The instance is now running in shared undo mode, with all old local undo tablespaces removed.
  • Switching to Local Undo Mode

We display the current undo mode using the following query, which shows we are currently in shared undo mode.

CONN / AS SYSDBA

COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A30

SELECT property_name, property_value
FROM   database_properties
WHERE  property_name = 'LOCAL_UNDO_ENABLED';

PROPERTY_NAME                  PROPERTY_VALUE
------------------------------ ------------------------------
LOCAL_UNDO_ENABLED             FALSE

SQL>

We also check for the presence of the undo tablespaces and only see that of the root container (con_id=1).

SELECT con_id, tablespace_name
FROM   cdb_tablespaces
WHERE  tablespace_name LIKE 'UNDO%'
ORDER BY con_id;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         1   UNDOTBS1

SQL>

The following commands demonstrate how to switch to local undo mode using the ALTER DATABASE LOCAL UNDO ON command.

CONN / AS SYSDBA

SHUTDOWN IMMEDIATE;
STARTUP UPGRADE;

ALTER DATABASE LOCAL UNDO ON;

SHUTDOWN IMMEDIATE;
STARTUP;

Once the instance is restarted we can check the undo mode again and see we are now in local undo mode.

COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A30

SELECT property_name, property_value
FROM   database_properties
WHERE  property_name = 'LOCAL_UNDO_ENABLED';

PROPERTY_NAME                  PROPERTY_VALUE
------------------------------ ------------------------------
LOCAL_UNDO_ENABLED             TRUE

SQL>

When we check for undo tablespaces we see Oracle has created a local undo tablespace for each user-defined pluggable databases.

SELECT con_id, tablespace_name
FROM   cdb_tablespaces
WHERE  tablespace_name LIKE 'UNDO%'
ORDER BY con_id;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         1    UNDOTBS1
         3    UNDO_1

SQL>

If we create a new pluggable database, we can see it is also created with a local undo tablespace.

CREATE PLUGGABLE DATABASE pdb2 ADMIN USER pdb_adm IDENTIFIED BY Password1;
ALTER PLUGGABLE DATABASE pdb2 SAVE STATE;

SELECT con_id, tablespace_name
FROM   cdb_tablespaces
WHERE  tablespace_name LIKE 'UNDO%'
ORDER BY con_id;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         1    UNDOTBS1
         3    UNDO_1
         4    UNDOTBS1

SQL>
  • Other Considerations

The documentation describes an optional step to create an undo tablespace in the seed database, if you don't want to rely on the auto-creation of the local undo tablespace.You can read about this here.