oracle filev$transaction oracle 12c database. oracle –12c database a temporary tablespace is used...

25

Upload: dothien

Post on 09-May-2019

295 views

Category:

Documents


0 download

TRANSCRIPT

Oracle – 12c Undo

The Undo Tablespace is used for Automatic Undo Management.

Used to Store Undo Segments

Cannot contain any other Objects

Extents are locally managed

Can only use the DATAFILE and EXTENT MANAGEMENT Clauses.

Undo tablespaces are used to store original data after it has been changed.

If user rollback the transaction the undo tablespace is used to back the data.

More than One Undo tablesapce available in Single database.

if we didn’t create any undo tablespace, then system undo used default.

Undo Tablespace

Oracle – 12c Database

Undo Purpose

Rolling back transactions explicitly with a ROLLBACK command

Rolling back transactions implicitly (automatic instance recovery)

Reconstructing readconsistent image of data

Recovering from logical corruptions

Oracle – 12c Undo

SQL> create undo tablespace undotbs

2 '/u01/app/oracle/oradata/SDBTDB/datafile/undo.dbf‘ size 100m;

Tablespace created.

Create Undo Tablespace

Oracle – 12c Undo

Undo Manage

SQL> alter system set undo_management=auto scope=spfile;

System altered.

SQL> show parameter undo_management

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

undo_management string AUTO

Oracle – 12c Undo

Undo tablespace Switch

SQL> show parameter undo_tablespace;

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

undo_tablespace string UNDOTBS1

SQL> alter system set undo_tablespace=undotbs;

System altered.

SQL> show parameter undo_tablespace;

NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

undo_tablespace string UNDOTBS

Oracle – 12c Undo

Drop a Undo Tablespace

SQL> drop tablespace undo1;

Tablespace dropped.

Oracle – 12c Undo

Undo tablespace guarantee

SQL> alter tablespace undotbs retention guarantee;

Tablespace altered.

SQL> alter tablespace undotbs retention noguarantee;

Tablespace altered.

Oracle – 12c Undo

Oracle 12c Undo Management

See current undo blocks

select begin_time, undotsn, undoblks,

activeblks, unexpiredblks, expiredblks

from v$undostat;

Contains snapshots of v$undostat (use obtain the oldest undo available)

select begin_time, undotsn, undoblks,

activeblks, unexpiredblks, expiredblks

From dba_hist_undostat;

Oracle – 12c Database

Oracle 12c Database

SQL> show parameter undo

NAME TYPE VALUE

------------------------------- ----------- -----------------

undo_management string AUTO

undo_retention integer 900

undo_tablespace string UNDOTBS1

Oracle – 12c Database

v$undostat

v$tempundostat

dba_hist_undostat

dba_undo_extents

dba_rollback_segs

v$rollname

v$rollstat

v$transaction

Oracle 12c Database

Oracle – 12c Database

A Temporary Tablespace is used to manage space for sort operations.

SQL queries are less likely to run out of space.

Database specify multiple default temporary tablespaces at the db level

Parallel execution can utilize multiple temporary tablespaces

single user can simultaneously use multiple temp tablespaces in different sessions.

Temporary Tablesapce

Oracle – 12c Database

Used for Sort Operations

Cannot contain any Permanent Objects.

Locally Managed Extents recommeded.

Tempfiles are also in a NOLOGGING Mode.

Tempfiles cannot be made read only or be renamed.

Tempifiles are required for read-only databases.

Temporary Tablesapce

Oracle – 12c Temporary

Temporary Tablesapce

SQL> select file_id,tablespace_name,bytes/1024/1024 "Size“

2 from dba_temp_files;

FILE_ID TABLESPACE_NAME Size

---------- ------------------------------ ----------

1 TEMP 131

2 TEMPTBS 50

SQL> create temporary tablespace temptbs

2 tempfile '/u01/app/oracle/oradata/SDBTDB/datafile/temp02.dbf'

3 size 50m;

Tablespace created.

Oracle – 12c Temporary

Database Temporary Tablesapce

SQL> alter database default temporary tablespace temptbs;

Database altered.

SQL> select * from database_properties

2 where property_name='DEFAULT_TEMP_TABLESPACE';

PROPERTY_NAME PROPERTY_VALUE

------------------------------ ------------------------------

DESCRIPTION

------------------------------------

DEFAULT_TEMP_TABLESPACE TEMPTBS

Name of default temporary tablespace

Oracle – 12c Temporary

Temporary Tablesapce Autoextend

SQL> alter database tempfile

2 '/u01/app/oracle/oradata/SDBTDB/datafile/temp02.dbf'

3 autoextend on;

Database altered.

Oracle – 12c Temporary

Temporary Tablesapce Autoextend

SQL> select file_name, autoextensible

2 from dba_temp_files;

FILE_NAME

--------------------------------------------------------------------------------

AUT

---

/u01/app/oracle/oradata/SDBTDB/datafile/o1_mf_temp_fsgmx5y2_.tmp

YES

/u01/app/oracle/oradata/SDBTDB/datafile/temp02.dbf

YES

Oracle – 12c Temporary

Temporary Tablesapce Resize

SQL> alter database tempfile 2 resize 80m;

Database altered.

SQL> select file_id,tablespace_name,bytes/1024/1024 "Size"

2 from dba_temp_files ;

FILE_ID TABLESPACE_NAME Size

---------- ------------------------------ ----------

1 TEMP 131

2 TEMPTBS 80

Oracle – 12c Temporary

Temporary Tablesapce Rename

SQL> alter database rename

2 file '/u01/app/oracle/oradata/SDBT/datafile/o1_mf_temp_fsfhy86q_.tmp'

3 to '/u01/app/oracle/oradata/SDBT/datafile/temp01.dbf‘;

Database altered.

Oracle – 12c Database

SQL> alter database tempfile 1 offline;

Database altered.

SQL> select file_id, tablespace_name, status

2 from dba_temp_files;

FILE_ID TABLESPACE_NAME STATUS

---------- -------------------------- -----------

2 TEMPTBS ONLINE

1 TEMP OFFLINE

Tempfile Status

Oracle – 12c Database

SQL> alter database tempfile 1 drop;

Database altered.

SQL> select file_id, tablespace_name, status

2 from dba_temp_files;

FILE_ID TABLESPACE_NAME STATUS

---------- -------------------------- -----------

2 TEMPTBS ONLINE

Drop a Tempfile

Oracle – 12c Database

V$tempfile

dba_temp_files

Dba_tablespace_groups

V$sort_segment

V$tempseg_usage

Temporary Tablesapce