Category Archives: tablespaces

Oracle 12c – Relocate SYSAUX occupants

In Oracle the SYSAUX tablespace is an auxiliary storage location for the SYSTEM tablespace.  Many of the Oracle database components which are not critical to the core functionality reside in the SYSAUX tablespace.  If the SYSAUX tablespace becomes unavailable, core database will still function, though pieces of the database which rely on SYSAUX components will fail or have limited capabilities.  You can view the components of the SYSAUX tablespace through the view V$SYSAUX_OCCUPANTS  as described below:

 

SQL> desc v$SYSAUX_OCCUPANTS

 Name                                      Null?    Type

 —————————————– ——– —————————-

 OCCUPANT_NAME                                      VARCHAR2(64)

 OCCUPANT_DESC                                      VARCHAR2(64)

 SCHEMA_NAME                                        VARCHAR2(64)

 MOVE_PROCEDURE                                     VARCHAR2(64)

 MOVE_PROCEDURE_DESC                                VARCHAR2(64)

 SPACE_USAGE_KBYTES                                 NUMBER

 CON_ID                                             NUMBER

SQL>

 

Procedure shown in the MOVE_PROCEDURE column of V$SYSAUX_OCCUPANTS details procedure name to move the product. This article will detail the steps to move the LGNMR component from SYSAUX tablespaces to its own tablespace storage.

 

  1. Logon to your database server as the oracle software owner.

 

[larry@linux2 ~]$ su – oracle

Password:

Last login: Wed Jan 11 15:04:41 EST 2017 on pts/2

Enter database to use:

1 – ORCL

2 – CDB1

Option >

1

[oracle@linux2 ~]$

 

  1. Connect to SQLPLUS as sysdba.

 

[oracle@linux2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Thu Jan 12 09:03:45 2017

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics, Real Application Testing

and Unified Auditing options

 

SQL>

 

  1. Create a new tablespace called LOGMINER.

 

SQL> create tablespace LOGMINER datafile ‘/u01/oradata/orcl/orcl/LOGMNR_data01.dbf’ size 1g;

Tablespace created.

SQL>

 

  1. Extract the move_procedure from V$SYSAUX_OCCUPANTS view for LOGMNR.

 

SQL> select occupant_name, schema_name, move_procedure from v$sysaux_occupants where occupant_name=’LOGMNR’;

OCCUPANT_NAME

—————————————————————-

SCHEMA_NAME

—————————————————————-

MOVE_PROCEDURE

—————————————————————-

LOGMNR

SYSTEM

SYS.DBMS_LOGMNR_D.SET_TABLESPACE

SQL>

 

  1. Execute procedure passing the new tablespace name.

 

execute SYS.DBMS_LOGMNR_D.SET_TABLESPACE(‘LOGMINER’);

 

SQL> execute SYS.DBMS_LOGMNR_D.SET_TABLESPACE(‘LOGMINER’);

PL/SQL procedure successfully completed.

SQL>

 

  1. This completes movement of LOGMNR from sysaux tablespace.

 

 

 

Larry Catt

OCP

Oracle 12c – Create a default permanent tablespace

You can create a default permanent tablespace for newly created users to avoid them having the SYSTEM tablespace as the default, which is never recommended.  Both the CREATE DATABASE and ALTER DATABASE commands support the DEFAULT TABLESPACE clause.  Command that sets the default tablespace to ‘USERS’ tablespace for all users is:

 

Example:

 

ALTER DATABASE DEFAULT TABLESPACE users;

 

SQL> ALTER DATABASE DEFAULT TABLESPACE users;

Database altered.

SQL>

 

If you are not sure what the default tablespace is for newly created users, you can view the  DATABASE_PROPERTIES to shows the database default tablespace with a property_name of DEFAULT_TEMP_TABLESPACE and DEFAULT_PERMANENT_TABLESPACE.

 

Example:

 

SELECT property_name, property_value FROM database_properties where property_name like ‘%TABLESPACE’;

 

SQL> SELECT property_name, property_value FROM database_properties where property_name like ‘%TABLESPACE’;

PROPERTY_NAME

——————————————————————————–

PROPERTY_VALUE

——————————————————————————–

DEFAULT_TEMP_TABLESPACE

TEMP

DEFAULT_PERMANENT_TABLESPACE

USERS

SQL>

 

Once a default permanent tablespace is defined, all objects for users will be created there unless they have their own default tablespace defined or the create statement defines a different tablespace.

 

 

Larry Catt

OCP

Oracle 12c – Manage VLDB

Very Large Databases use partitioning to improve the ability to support large data sets.  Breaking large tables into smaller manageable chunks.  This allows for partition pruning, which prevents access to partitions which will not have data queried.  Partitioning and indexing work together to provide parallel processing to search multiple partitions at same time as in data ware housing.

 

Partitioning Methods: 

You can partition data into a single level or two level for a composite partition.  How the data is accessed determines the best implementation method.   Regardless of partitioning method, you have three ways to control distributing of partitions:

  1. Range
  2. Hash
  3. List

 

Single Level Partitioning

One or more of the columns acts as the partition key spitting the table into multiple sections.

  1. Range Partitioning – maps data to a range of values in the partition key. Each row is identified with a mapping to partition key.   This is the most common partitioning method and is commonly used with dates.  Partition is created with a VALUES LESS THEN clause which show the upper bound of a date column.  The highest partition can use a MAXVALUE to provide an upper limit.
  2. Hash Partitioning – This method uses a hashing algorithm to map data to partitioning key. Used to evenly spread data among partitions. It is easier to implement then range.  Good to use if no date column exists and no obvious partitioning key exists.
  3. List Partitioning – Allows you to provide a list of values for partitioning key column and divides data base on list. You control exactly how rows are mapped to partitions.  You list a set of values to be placed in separate partitions and use the DEFAULT clause to specify a partition for any value not in the list.

 

Composite Partitions

This combines the basic partitioning methods into multiple sub-partitions of the same method or different methods.  Provides for a finer level of sub-division of data.   Possible composite partitions are:

  • Range-Range
  • Range-Hash
  • Range-List
  • List-Range
  • List-Hash
  • List-List
  • Hash-Hash

 

 

Larry Catt

OCP

Oracle 12c – Manage database Structures

Management of Oracle database storage structures provides the ability to persistently store data for long term retrieval and recovery processes.   The management of this structures can be done both from the command line, via EM Express and EM cloud control.    EM Express and EM Cloud control gives the administrator the ability to view, create, and alter various storage structures in the database in a Graphical User Interface through the STORAGE page.   Command line option requires that the administrator knows the syntax of DDL statements to perform the same tasks.  Oracle data structure of concern of storage are:

  • Tablespaces: create, drop, add datafiles, and change status of tablespace
  • Undo Management – shows current status of undo tablespaces and gives validation that it is sized correctly.
  • Redo Log Groups – allows you to create, drop, add members to redo log groups.
  • Archive Logs – Allows you view info about archive logs.
  • Control Files: – see content of control files and allows you to backup control files to trace.

OMF – Oracle Managed Files are intends to simplify the management of files associated with database.  When OMF is in use, the administrator specifies a directory for different file types.  OMF cannot be used with RAW devices.    OMF can be used for the following storage structures:

  • Tablespaces
  • Redo log files
  • control files
  • archive logs
  • block change tracking files
  • Flashback logs
  • RMAN backups.

OMF does nothing with administrative file like trace files, audit files, alert logs, and core files.   OMF requires three initialization parameter to be set

  • DB_CREATE_FILE_DEST – defines directory where data files and temp files are stored, Also used or redo logs and control files if DB_CREATE_ONLINE_LOG_DEST_n is not defined.
  • DB_CREATE_ONLINE_LOG_DEST_n – Defines directory for redo log files and control files.   You can specify up to 5 multiplex locations.
  • DB_RECOVERY_FILE_DEST – Define Fast Recovery Area. , Also used or redo logs and control files if DB_CREATE_ONLINE_LOG_DEST_n is not defined.

 

Larry Catt

OCP

 

 

 

 

 

Managing tablespaces in CDB and PDB

An Oracle 12c multitenant database consist of a CDB which houses one to many PDBs serving end user applications.    Thus objects such as tablespaces can become a little confusing to manage with questions of do they belong to CDB or PDB or both.   This article tries to clear this subject and give a brief tutorial in managing tablespaces in the multitenant architecture.

 

Rules to tablespaces in CDB and PDB:

 

  1. Permanent tablespace can only be associated with a single container (CDB or PDB).
  2. When you create a tablespace in a container, it belongs to that container.
  3. CDB can have only one active undo tablespace or one active undo tablespace for each instance of RAC.
  4. Only one default temporary tablespace for CDB.
  5. PDBs can use the CDB’s temporary tablespace.
  6. Each PDB can have its own default temporary tablespace.
  7. PDBs can have their own tablespaces.
  8. Permanent Default tablespace in PDB can still use the ALTER DATABASE command, but it is preferred to use the command:

ALTER PLUGGABLE DATABASE DEFAULT TABLESPACE tbs_user_pdb;

  1. CDB will have only one temporary tablespace.
  2. To modify the temporary tablespace for CDB, the current container must be root.
  3. You can have other temporary tablespaces in CDB with specific users assigned to them, but only one default.
  4. Each PDB can have only one temporary tablespace and when PDB is unplugged so is its temporary tablespace.

 

 

 

Managing tablespaces in Multitenant architecture.

 

  1. Logon as the oracle software owner.

[larry@linux2 ~]$ su – oracle

Password:

Last login: Tue Oct 25 09:29:48 EDT 2015 on pts/1

[oracle@linux2 ~]$

 

  1. Connect to your CDB with sqlplus and show current container.

 

[oracle@linux2 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Wed Oct 26 10:02:53 2015

 

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL> show con_name

 

CON_NAME

——————————

CDB$ROOT

SQL>

 

  1. Create a new permanent tablespace in the root container of cdb1_user, set it as the default tablespace for root.

 

SQL> create tablespace cdb1_users

datafile ‘/opt/app/oradata/cdb1_users.dbf’ size 10m;  2

 

Tablespace created.

 

SQL> ALTER DATABASE DEFAULT TABLESPACE cdb1_users;

 

Database altered.

 

SQL>

 

  1. View tablespaces from the root container and default tablespaces.

 

SQL> select tablespace_name from dba_tablespaces;

 

TABLESPACE_NAME

——————————

SYSTEM

SYSAUX

UNDOTBS1

TEMP

USERS

CDB1_USERS

 

6 rows selected.

 

SQL> select distinct(default_tablespace) from dba_users;

 

DEFAULT_TABLESPACE

——————————

SYSAUX

CDB1_USERS

SYSTEM

 

 

  1. Change to one of your pluggable database and note that you cannot see the newly create tablespace cdb1_users.

 

SQL> alter session set container=pdb1;

 

Session altered.

 

SQL> select tablespace_name from dba_tablespaces;

 

TABLESPACE_NAME

——————————

SYSTEM

SYSAUX

TEMP

USERS

 

SQL>

 

  1. Create a tablespace tablespace in your PDB and move back to your root container.

 

SQL> create tablespace pdb1_users

datafile ‘/opt/app/oradata/pdb1_users.dbf’ size 10m;  2

 

Tablespace created.

 

SQL> select tablespace_name from dba_tablespaces;

 

TABLESPACE_NAME

——————————

SYSTEM

SYSAUX

TEMP

USERS

PDB1_USERS

 

SQL> alter session set container=CDB$ROOT;

 

Session altered.

 

SQL> select tablespace_name from dba_tablespaces;

 

TABLESPACE_NAME

——————————

SYSTEM

SYSAUX

UNDOTBS1

TEMP

USERS

CDB1_USERS

 

6 rows selected.

 

SQL>

 

 

  1. This completes the management of tablespaces within the multitenant database architecture.

 

Larry Catt

OCP

Oracle 12c – Implement Space Management

Oracle provides a large amount of storage options to reduce the space required for data storage and increase the speed of retrieval.   This article provides a brief overview of space management in an Oracle 12c database with some general suggestions to increase flexibility and performance.

 

Local Managed Tablespaces:

You should always use locally managed tablespaces in Oracle, this is where bitmaps in the tablespace to manage all extents and not external in the data dictionary.  Any tablespace can be locally managed, including SYSTEM and SYSAUX.   Advantage of local managed tablespaces:

  1. Allocation and deallocation of space is local managed, resulting in higher performance.
  2. Local managed temporary tablespaces do not generate undo or redo.
  3. The AUTOALLOCATE clause allows for automatically extent sizing.
  4. Reduce contention on data dictionary resulting from no access by tablespace.
  5. No need to coalesce free extents.

DBMS_SPACE_ADMIN is a package containing procedures specific to locally managed tablespaces.

Use the ‘EXTENT MANAGEMENT LOCAL AUTOALLOCATE’ is the clause to specify local management with auto select of extent sizes which is the default.  To have uniformed extent sizes you must specify, ‘UNIFORM’

Example:

 

CREATE TABLESPACE data1

DATAFILE ‘/ u02/ oracle/ data/ orcl01. dbf’

SIZE 50M

EXTENT MANAGEMENT LOCAL AUTOALLOCATE;

 

CREATE TABLESPACE data1 DATAFILE ‘/ u02/ oracle/ data/ orcl01. dbf’ SIZE 50M;

 

Two methods you can use for segment space in locally managed tablespace.  Manual and Automatic:  Manual uses a free lists to manage free space in segments.   Automatic is the default method and it uses bitmaps to manage free space and is more efficient.   You can explicitly specify clause:  ‘SEGMENT SPACE MANAGEMENT AUTO’

Example:

 

CREATE TABLESPACE data1

DATAFILE ‘/ u02/ oracle/ data/ orcl01. dbf’

SIZE 50M

EXTENT MANAGEMENT LOCAL AUTOALLOCATE

SEGMENT SPACE MANAGEMENT AUTO;

 

 

BASIC TABLE COMPRESSION

Is the lowest level compression and does not compress data in a table from INSERT/UPDATE.   Data is only compressed during bulk loads.   Basic compression is available in EE license and its format is the same as Advance Compression.  It is possible to convert from Basic to Advance, by simply changing the storage definition of the table or partition.

 

Advance Row Compression

Originally called OLTP Table compression in 11g, Advance Row compression compresses data regardless how it arrived.  It also minimizes overhead in write operations by eliminating duplicates in data blocks even across rows.  Advance Compression is an additional licensing option.

 

Hybrid Columnar Compression

Hybrid Columnar Compression (HCC) is a method of organizing data within a set of database blocks.   The underlying OS must support HCC and requires the use of Oracle Storage Exadata, Pillar Axiom or Sun ZFS Storage Appliance.  It stores multiple rows by columns, in what is call compression units.  Columns of like data are stored together similar data types, thus can achieve compression of x6 x15.

 

Tables created in tablespace with compression option will be compressed unless you specify no compression or another compression method in the CREATE TABLE clause.

 

Segment Shrink

Online segment shrink allows you to reclaim fragmented free space below high watermark in a segment.  With the following benefits:

  1. Compacting provides better cache use.
  2. Compact data has less data blocks to be scanned.

Segment shrink is performed online without DML operations interference.    Concurrent DML operations are blocked at end of shrink for space deallocation.  Indexes are maintained and usable after shrink.   Unused disk space is reclaimed above and below high water mark.  No additional space is needed during shrink.  By default shrink operation compact data, move the high water mark and release unused space.

Segment shrink requires row movement and thus requires you to enable row movement and disable rowed triggers.  Shrink operations can only happen on segments using locally managed tablespace with ASSM Automatic segment space management.  In ASSM all segment types are shrinkable except:

  1. IOT mapping tables
  2. Tables with rowed based materialized views.
  3. Tables with function-based indexes.
  4. SECUREFILE LOBs
  5. Compressed tables.

 

Invoking Online Segment Shrink – SHRINK SPACE

You can shrink space in the following by use of SHRINK SPACE clause

  1. Table – with ALTER TABLE..
  2. Index-Organized Table – with ALTER TABLE
  3. Index – with ALTER INDEX
  4. Partition – with ALTER TABLE
  5. Sub-partition – with ALTER TABLE
  6. Materialized view – with ALTER MATERIALIZED VIEW
  7. Materialized view log – with ALTER MATERIALIZED VIEW LOG

 

Two operations with SHRINK SPACE clause.

  1. COMPACT – shrink operation divided into two sections. First phase:  defragments and compacts rows, does not reset high water mark or release space.  You can re-issue shrink operation without the COMPACT operation during off hours to complete deallocation of space and movement of high water mark.
  2. CASCADE – This extends shrink operation to all dependent objects.

 

Example shrink a table and all of its dependent segments:

 

ALTER TABLE employees SHRINK SPACE CASCADE;

 

Example shrink a single partition of a partitioned table:

 

ALTER TABLE customers MODIFY PARTITION cust_P1 SHRINK SPACE;

 

 

 

Larry Catt

OCP