Showing posts with label Tablespace Management. Show all posts
Showing posts with label Tablespace Management. Show all posts

Monday, 3 February 2025

What are the different types of tablespaces available in Oracle Database & their purpose?

 In an Oracle database, tablespaces are fundamental to how data is organized and managed. They act as logical containers for storing various types of data. Here's a breakdown of the key tablespace types: 

1. SYSTEM Tablespace

  • Purpose: This is the most crucial tablespace. It houses the data dictionary, which contains metadata about the entire database. This includes information about users, tables, indexes, and other database objects.

Sunday, 2 February 2025

What is the purpose of using tablespaces in Oracle Database?

Tablespaces serve several crucial purposes in Oracle databases, all contributing to better organization, performance, and manageability. Here's a breakdown of the key reasons for using them:   

Logical Data Organization: Tablespaces provide a logical layer of abstraction between the physical datafiles and the database objects (tables, indexes, etc.). This allows you to organize data logically, grouping related objects together.  For example, you might have a tablespace for application data, another for user data, and another for indexes. This logical separation simplifies management and makes it easier to understand the structure of your data. 

What are tablespaces in Oracle Database?

 In Oracle Database, a tablespace is a fundamental unit of logical storage. Think of it as a container that holds data for your database objects, such as tables, indexes, and other data. Here's a breakdown of what they are and why they're important:   

Wednesday, 22 August 2018

Problems with Missing tempfiles in Physical Standby ORA-01157 | ORA-01110 | ORA-01187

Temporary File physically missing but Entry exists in Control File | ORA-01157 | ORA-01110 | ORA-01187

Temporary tablespaces or tempfiles doesn't lead to data loss if lost or corrupted but are the major part of database operations. The same space is used in all kind of sort operations whenever data is fetched from the datafiles. In this post, I am basically discussing a scenario where I am working on my Physical Standby database and I am not having my physical files for tempfiles but the entry exists in the Control File and then issues I faced because of that. At the end, I found out the way to resolve the same but the same can give trouble to most of the DBAs so here is the Problem and Solution for the same.

Thursday, 16 August 2018

Difference Between Smallfile and Bigfile Tablespaces | Oracle Database

SMALLFILE Vs BIGFILE Tablespaces in Oracle Database | Which one to choose?


Oracle Database normally use the SMALLFILE tablespace which is also the By Default tablespace creation method. At the time of database creation, SYSTEM and SYSAUX are also created as smallfile tablespaces and, for the others getting created, will also be smallfile only if you don't specify BIGFILE clause while creating them.

Tuesday, 14 August 2018

Create a Tablespace in Oracle Database

How to Create a Tablespace in Oracle Database?

Tablespaces are the part of Logical Storage Structures in Oracle Database and are very different from the Physical Structure Components because of their purpose and the way they are managed. Albeit both Physical and Logical Structures are related to each other. DBAs normally have the knowledge of both the structures but usually they deal mostly with Physical Structures (Datafiles, Controlfiles and Redo logs). Tablespaces are something which is quite a Developer thing or the one who is going to use the segments inside the Tablespace to create his/her objects.

Sunday, 13 May 2018

ORA-19722: datafile is an incorrect version - Oracle Database

ORA-19722: datafile is an incorrect version | ORA-39123: Data Pump transportable tablespace job aborted

ORA-19722: datafile is an incorrect version

Thursday, 10 May 2018

How to Transport Tablespace in Oracle Database?

Transport Tablespaces in Oracle Database 11g


How to transport a tablespace in Oracle database | Steps to transport a tablespace | Manual guide on how to transport a tablespace | how to check if a tablespace is transportable or not

Transport Tablespaces in Oracle Database 11g

Monday, 9 October 2017

CREATE, DROP or ADD Tempfile in Oracle Database

CREATE, DROP or ADD Temporary datafile in Oracle Database

Managing Temporary tablespace in Oracle Database

We all are aware of the TEMP Tablespace which is a very useful part of oracle database to perform all the temporary operations liking sorting etc. Below shown are some commands to manage these temporary tablespaces or datafiles:

To view information about Temporary Tablespaces and Tempfiles,

SQL>select * from dba_temp_files;
SQL>select * from v$tempfile;

To view information about free space in tempfiles,

SQL>select * from V$TEMP_SPACE_HEADER;

To create a new Temporary Tablespace,

SQL> create temporary tablespace TEMP tempfile '/u02/database/mydb/temp_01.dbf' SIZE 500m autoextend on next 10M maxsize unlimited;

To drop an existing Temporary Tablespace,

SQL> Drop tablespace TEMP including contents and datafiles;

To add Tempfile in Temporary Tablespace,

SQL> Alter tablespace temp add tempfile '/u02/database/mydb/temp_02.dbf' size 50m reuse autoextend on next 1m maxsize 500m;

Sunday, 14 May 2017

Missing Tempfile in Oracle Database | ORA - 25153 Temporary Tablespace is Empty

Missing Temporary File Scenarios | ORA - 25153 Temporary Tablespace is Empty


ORA-01157: cannot identify/lock data file 202 - see DBWR trace file
ORA-01110: data file 202: '/oracle/app/product/10.1.0/db_1/dbs/D:ORACLEPRODUCT10.1.0ORADATATEXERPTEMP1.DBF'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

I have covered the 2 most common scenarios where you might be getting trouble with temporary tablespace because of missing tempfiles.

Scenario 1: Temporary file (tempfile) is lost at OS Level. But for database, it is still there.
To understand this simply, it means physically the file is somehow lost for your Oracle Database. OR your Oracle Database is unable to find the Temporary file in the location for which the record is maintained in your Oracle Environment. For example:

SQL> select * from dba_objects order by object_name;
     select * from dba_objects order by object_name
              *
     ERROR at line 1:
     ORA-01115: IO error reading block from file 201 (block # 3)
     ORA-01110: data file 201: '/oracle/oradata/ORCL/temp2_01.tmp'
     ORA-27041: unable to open file
     SVR4 Error: 2: No such file or directory
     Additional information: 3

As long as you are Starting Up or Shutting Down your Oracle Database, it won't stop you from doing the same. Only it will notify you in the trace file regarding missing temporary file.

Solution: Drop the temporary file at database level and add a new one

      SQL> alter database tempfile '/oracle/oradata/ORCL/temp2_01.tmp' drop;
      Database altered.

      SQL> select tablespace_name, file_name from dba_temp_files;
      no rows selected.

      SQL> alter tablespace temp2
        2  add tempfile '/oracle/oradata/ORCL/temp2_01.tmp' size 5m;
      Tablespace altered.


Scenario 2: The Tempfile is lost at Database Level. In simple words, somehow you have dropped the tempfile using the DROP command at database level and now the database is missing temporary file.
In this case, when you'll get an error like:

 SQL> alter table test add primary key (c);
     alter table test add primary key (c)
     *
     ERROR at line 1:
     ORA-25153: Temporary Tablespace is Empty

Solution : Simply add a new tempfile to overcome this type of situation.

      In 8i : Remove the OS tempfile before adding a new tempfile

      From 9i : Add a new tempfile straight forward
      To add a tempfile :
      SQL> alter tablespace TEMP_TEMPFILE_LOCAL
          2   add tempfile '/oracle/oradata/ORCL/temp2_01.tmp';

You can get more information on the same by visiting the below mentioned Oracle Support Link:

Note:160426.1 TEMPORARY Tablespaces : Tempfiles or Datafiles ?

Saturday, 22 October 2016

How to Rename Datafiles in Multiple Tablespaces All Together

How to Rename Datafiles in Multiple Tablespaces All Together


Oracle Database also provides you the ability to rename or relocate multiple datafiles simultaneously. For the same purpose, you need to use ALTER DATABASE RENAME FILE Statement. This statement helps you to rename multiple datafiles all together in one single query or one single operation.

Note - You must be provided the ALTER DATABASE privilidge in order to go ahead with this method.

Saturday, 27 August 2016

Rename and Relocate Datafile | Oracle Database

Rename and Relocate a Datafile in Oracle Database


Renaming or Relocating Datafiles belonging to a Single Tablespace

You can rename datafiles to either change their names or relocate them.

To rename or relocate datafiles belonging to a Single Tablespace do the following.

Oracle Views to get Info About Tablespaces and Datafiles | Oracle Database

Oracle Views to get Information regarding Oracle Tablespaces and Datafiles

Oracle has provided many Data dictionary views to get information about tablespaces and datafiles.  Some of them are:

To view information about Tablespaces in a database give the following query

SQL> select * from dba_tablespaces;
SQL> select * from v$tablespace;

To view information about Datafiles

SQL> select * from dba_data_files;
SQL> select * from v$datafile;

To view information about Tempfiles

SQL> select * from dba_temp_files;
SQL> select * from v$tempfile;

To view information about free space in datafiles

SQL> select * from dba_free_space;

To view information about free space in tempfiles


SQL> select * from V$TEMP_SPACE_HEADER;

How to Drop a Tablespace | Oracle Database

How to Drop a Tablespace in Oracle Database


You can drop a tablespace and its contents (the segments contained in the tablespace) from the database if the tablespace and its contents are no longer required. You must have the DROP TABLESPACE system privilege to drop a tablespace.

Caution: Once a tablespace has been dropped, the data in the tablespace is not recoverable. Therefore, make sure that all data contained in a tablespace to be dropped will not be required in the future. Also, immediately before and after dropping a tablespace from a database, back up the database completely

To drop a tablespace give the following command.

SQL> drop tablespace ica;

This will drop the tablespace only if it is empty. If it is not empty and if you want to drop it anyhow then add the following keyword

SQL> drop tablespace ica including contents;

This will drop the tablespace even if it is not empty. But the datafiles will not be deleted you have to use operating system command to delete the files.

But If  you include datafiles keyword then, the associated datafiles will also be deleted from the disk.


SQL> drop tablespace ica including contents and datafiles;

How to rename a Tablespace | Oracle Database

How to rename a Tablespace in Oracle Database


Using the RENAME TO clause of the ALTER TABLESPACE, you can rename a permanent or temporary tablespace. For example, the following statement renames the users tablespace:

ALTER TABLESPACE TAB1 RENAME TO TAB11;

The following affect the operation of this statement:
  • The COMPATIBLE parameter must be set to 10.0 or higher.
  • If the tablespace being renamed is the SYSTEM tablespace or the SYSAUX tablespace, then it will not be renamed and an error is raised.
  • If any datafile in the tablespace is offline, or if the tablespace is offline, then the tablespace is not renamed and an error is raised.

How to Make a Tablespace Read only | Oracle Database

How to Make a Tablespace Read only in Oracle Database


Making a tablespace read-only prevents write operations on the datafiles in the tablespace. The primary purpose of read-only tablespaces is to eliminate the need to perform backup and recovery of large, static portions of a database. Read-only tablespaces also provide a way to protecting historical data so that users cannot modify it. Making a tablespace read-only prevents updates on all tables in the tablespace, regardless of a user's update privilege level.

To make a tablespace read only

SQL>alter tablespace ica read only;

Again to make it read write


SQL> alter tablespace ica read write;

Making Tablespace Online or Offline in Oracle Database

Making Tablespace Online or Offline in Oracle Database


Taking tablespaces Offline or Online

You can take an online tablespace offline so that it is temporarily unavailable for general use. The rest of the database remains open and available for users to access data. Conversely, you can bring an offline tablespace online to make the schema objects within the tablespace available to database users. The database must be open to alter the availability of a tablespace.

We usually take tablespaces offline for maintenance purposes.

To alter the availability of a tablespace, use the ALTER TABLESPACE statement. You must have the ALTER TABLESPACE or MANAGE TABLESPACE system privilege.

To Take a Tablespace Offline give the following command

SQL> alter tablespace ica offline;

To again bring it back online give the following command.

SQL> alter tablespace ica online;

To take individual datafile offline type the following command

SQL> alter database datafile ‘/u01/oracle/ica/ica_tbs01.dbf’ offline;

Again to bring it back online give the following command

SQL> alter database datafile ‘/u01/oracle/ica/ica_tbs01.dbf’ online;

Note: You can’t take individual datafiles offline it the database is running in NOARCHIVELOG mode.  If the datafile has become corrupt or missing when the database is running in NOARCHIVELOG mode then you can only drop it by giving the following command


SQL> alter database datafile ‘/u01/oracle/ica/ica_tbs01.dbf’ offline for drop;

How to Increase the Size of Tablespace and Datafiles

How to Increase the Size of Tablespace and Datafiles



To Extend the Size of a tablespace

Option 1

 You can extend the size of a tablespace by increasing the size of an existing datafile by typing the following command

SQL> alter  database ica datafile ‘/u01/oracle/data/icatbs01.dbf’ resize
 100M;

This will increase the size from 50M to 100M

Option 2

You can also extend the size of a tablespace by adding a new datafile to a tablespace. This is useful if the size of existing datafile is reached o/s file size limit or the drive where the file is existing does not have free space. To add a new datafile to an existing tablespace give the following command.


SQL> alter tablespace add datafile  ‘/u02/oracle/ica/icatbs02.dbf’ size 
50M;


Option 3

You can also use auto extend feature of datafile. In this, Oracle will automatically increase the size of a datafile whenever space is required. You can specify by how much size the file should increase and Maximum size to which it should extend.

To make a existing datafile auto extendable give the following command

SQL> alter database datafile ‘/u01/oracle/ica/icatbs01.dbf’ auto extend 
ON next 5M maxsize 500M;

You can also make a datafile auto extendable while creating a new tablespace itself by giving the following command.

SQL> create tablespace ica datafile ‘/u01/oracle/ica/icatbs01.dbf’ size 
50M auto extend ON next 5M maxsize 500M;

To decrease the size of a tablespace

You can decrease the size of tablespace by decreasing the datafile associated with it. You decrease a datafile only up to size of empty space in it. To decrease the size of a datafile give the following command

SQL> alter database datafile ‘/u01/oracle/ica/icatbs01.dbf’ resize 30M;


Coalescing Tablespaces

A free extent in a dictionary-managed tablespace is made up of a collection of contiguous free blocks. When allocating new extents to a tablespace segment, the database uses the free extent closest in size to the required extent. In some cases, when segments are dropped, their extents are deallocated and marked as free, but adjacent free extents are not immediately recombined into larger free extents. The result is fragmentation that makes allocation of larger extents more difficult.

You should often use the ALTER TABLESPACE ... COALESCE statement to manually coalesce any adjacent free extents. To Coalesce a tablespace give the following command


SQL> alter tablespace ica coalesce;

Managing Tablespaces and Datafiles in Oracle

Tablespace And Datafile Management in Oracle - Full Explanation


Using multiple tablespaces provides several Advantages

Separate user data from data dictionary data to reduce contention among dictionary objects and schema objects for the same datafiles.
Separate data of one application from the data of another to prevent multiple applications from being affected if a tablespace must be taken offline.
Store different the datafiles of different tablespaces on different disk drives to reduce I/O contention.
Take individual tablespaces offline while others remain online, providing better overall availability.

Creating  New Tablespaces

You can create Locally Managed or Dictionary Managed Tablespaces. In prior versions of Oracle only Dictionary managed Tablespaces were available but from Oracle ver. 8i you can also create Locally Managed tablespaces. The advantages of locally managed tablespaces are

Locally managed tablespaces track all extent information in the tablespace itself by using bitmaps, resulting in the following benefits:

Concurrency and speed of space operations is improved, because space allocations and deallocations modify locally managed resources (bitmaps stored in header files) rather than requiring centrally managed resources such as enqueues
Performance is improved, because recursive operations that are sometimes required during dictionary-managed space allocation are eliminated

To create a locally managed tablespace give the following command

SQL> CREATE TABLESPACE ica_lmts DATAFILE '/u02/oracle/ica/ica01.dbf' 
SIZE 50M EXTENT MANAGEMENT LOCAL AUTOALLOCATE;

AUTOALLOCATE causes the tablespace to be system managed with a minimum extent size of 64K.

The alternative to AUTOALLOCATE is UNIFORM. which specifies that the tablespace is managed with extents of uniform size. You can specify that size in the SIZE clause of UNIFORM. If you omit SIZE, then the default size is 1M. The following example creates a Locally managed tablespace with uniform extent size of 256K

SQL> CREATE TABLESPACE ica_lmt DATAFILE '/u02/oracle/ica/ica01.dbf' SIZE
 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K;

To Create Dictionary Managed Tablespace

SQL> CREATE TABLESPACE ica_lmt DATAFILE '/u02/oracle/ica/ica01.dbf' SIZE
 50M EXTENT MANAGEMENT DICTIONARY;

Bigfile Tablespaces (Introduced in Oracle Ver. 10g)

A bigfile tablespace is a tablespace with a single, but very large (up to 4G blocks) datafile. Traditional smallfile tablespaces, in contrast, can contain multiple datafiles, but the files cannot be as large. Bigfile tablespaces can reduce the number of datafiles needed for a database.

To create a bigfile tablespace give the following command


SQL> CREATE BIGFILE TABLESPACE ica_bigtbs  DATAFILE '/u02/oracle/ica/big
tbs01.dbf' SIZE 50G;