How to Create a Tablespace in Oracle - Step by Step
How to Create a Tablespace in Oracle
Section titled “How to Create a Tablespace in Oracle”A tablespace is Oracle’s logical storage container — every segment (table, index, LOB) lives in one. Before creating objects, you need a correctly sized tablespace with autoextend configured. This guide covers every tablespace type with production-ready SQL.
Prerequisites
Section titled “Prerequisites”You need the CREATE TABLESPACE system privilege, typically granted to DBAs. You also need:
- An identified datafile location with sufficient disk space
- Knowledge of your storage layout (ASM disk groups or filesystem paths)
-- Verify you have the privilegeSELECT privilegeFROM session_privsWHERE privilege = 'CREATE TABLESPACE';
-- Check existing tablespacesSELECT tablespace_name, status, contents, extent_managementFROM dba_tablespacesORDER BY tablespace_name;
-- Check available space on ASM or filesystemSELECT name, total_mb, free_mb, ROUND(free_mb/total_mb*100,1) AS free_pctFROM v$asm_diskgroup;Step 1: Create a Basic Permanent Tablespace
Section titled “Step 1: Create a Basic Permanent Tablespace”This is the most common operation — a locally managed tablespace with autoextend enabled.
-- Basic permanent tablespace (filesystem)CREATE TABLESPACE app_data DATAFILE '/u01/oradata/ORCL/app_data01.dbf' SIZE 500M AUTOEXTEND ON NEXT 100M MAXSIZE 10G EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
-- Verify creationSELECT tablespace_name, status, contents, extent_management, segment_space_managementFROM dba_tablespacesWHERE tablespace_name = 'APP_DATA';Using ASM (Recommended for Production)
Section titled “Using ASM (Recommended for Production)”-- Permanent tablespace on ASMCREATE TABLESPACE app_data DATAFILE '+DATA/ORCL/DATAFILE/app_data01.dbf' SIZE 1G AUTOEXTEND ON NEXT 256M MAXSIZE 20G EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;Step 2: Create a Temporary Tablespace
Section titled “Step 2: Create a Temporary Tablespace”Every database needs a default temporary tablespace for sort operations. Use TEMPFILE instead of DATAFILE.
-- Create a temporary tablespaceCREATE TEMPORARY TABLESPACE app_temp TEMPFILE '/u01/oradata/ORCL/app_temp01.dbf' SIZE 2G AUTOEXTEND ON NEXT 512M MAXSIZE 10G EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
-- Set as the default temporary tablespace for new usersALTER DATABASE DEFAULT TEMPORARY TABLESPACE app_temp;
-- VerifySELECT tablespace_name, contents, statusFROM dba_tablespacesWHERE contents = 'TEMPORARY';Step 3: Create an Undo Tablespace
Section titled “Step 3: Create an Undo Tablespace”Undo tablespaces hold rollback data for read consistency and flashback operations.
-- Create undo tablespaceCREATE UNDO TABLESPACE undo_new DATAFILE '/u01/oradata/ORCL/undo_new01.dbf' SIZE 2G AUTOEXTEND ON NEXT 500M MAXSIZE 30G;
-- Switch the active undo tablespace (online, no restart needed)ALTER SYSTEM SET undo_tablespace = 'UNDO_NEW' SCOPE=BOTH;
-- Verify the switch took effectSHOW PARAMETER undo_tablespace;Step 4: Create a Bigfile Tablespace
Section titled “Step 4: Create a Bigfile Tablespace”Bigfile tablespaces contain a single, very large datafile (up to 128TB). Ideal for large data warehouses.
-- Create bigfile tablespaceCREATE BIGFILE TABLESPACE dw_data DATAFILE '+DATA/ORCL/DATAFILE/dw_data01.dbf' SIZE 50G AUTOEXTEND ON NEXT 10G MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
-- Resize a bigfile tablespace (single command, no datafile reference needed)ALTER TABLESPACE dw_data RESIZE 100G;
-- Check if tablespace is bigfileSELECT tablespace_name, bigfileFROM dba_tablespacesWHERE tablespace_name = 'DW_DATA';Step 5: Create an Encrypted Tablespace (TDE)
Section titled “Step 5: Create an Encrypted Tablespace (TDE)”Transparent Data Encryption (TDE) encrypts data at rest — required for many compliance frameworks.
-- First, ensure the wallet is openADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY "WalletPassword123" CONTAINER = ALL;
-- Create encrypted tablespaceCREATE TABLESPACE secure_data DATAFILE '/u01/oradata/ORCL/secure_data01.dbf' SIZE 500M AUTOEXTEND ON NEXT 100M MAXSIZE 5G ENCRYPTION USING AES256 DEFAULT STORAGE (ENCRYPT);
-- Verify encryptionSELECT tablespace_name, encryptedFROM dba_tablespacesWHERE tablespace_name = 'SECURE_DATA';Advanced Examples
Section titled “Advanced Examples”Uniform Extent Size (for OLTP workloads)
Section titled “Uniform Extent Size (for OLTP workloads)”-- Uniform extent size — reduces fragmentation for similar-sized objectsCREATE TABLESPACE oltp_idx DATAFILE '/u01/oradata/ORCL/oltp_idx01.dbf' SIZE 2G AUTOEXTEND ON NEXT 512M MAXSIZE 20G EXTENT MANAGEMENT LOCAL UNIFORM SIZE 8M SEGMENT SPACE MANAGEMENT AUTO;Multiple Datafiles at Creation
Section titled “Multiple Datafiles at Creation”-- Create tablespace with multiple datafiles for I/O distributionCREATE TABLESPACE reporting DATAFILE '/u01/oradata/ORCL/rpt01.dbf' SIZE 5G, '/u02/oradata/ORCL/rpt02.dbf' SIZE 5G, '/u03/oradata/ORCL/rpt03.dbf' SIZE 5G AUTOEXTEND OFF EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;Read-Only Tablespace
Section titled “Read-Only Tablespace”-- Create tablespace, load data, then make read-only (for archival)CREATE TABLESPACE archive_2023 DATAFILE '/u01/oradata/ORCL/archive_2023_01.dbf' SIZE 10G AUTOEXTEND OFF;
-- After loading data:ALTER TABLESPACE archive_2023 READ ONLY;Common Mistakes and Pitfalls
Section titled “Common Mistakes and Pitfalls”Using DICTIONARY extent management — Always use EXTENT MANAGEMENT LOCAL. Dictionary-managed tablespaces are obsolete and cause contention on Oracle 10g+.
No MAXSIZE limit with AUTOEXTEND — Setting AUTOEXTEND ON without MAXSIZE allows a tablespace to fill an entire disk. Always set a sensible limit.
Wrong sizing for temp tablespace — Temp tablespaces need enough space for the largest parallel sort operation, not just average usage. Underprovision and you get ORA-01652.
Creating tablespace as SYSTEM user — Objects in SYSTEM or SYSAUX tablespaces cause problems. Always use dedicated application tablespaces.
Using MANUAL segment space management — SEGMENT SPACE MANAGEMENT MANUAL uses freelists and causes contention. Always use AUTO (bitmap-based).
Verification Queries
Section titled “Verification Queries”-- Confirm tablespace was created with correct settingsSELECT t.tablespace_name, t.status, t.contents, t.extent_management, t.segment_space_management, t.bigfile, t.encrypted, ROUND(SUM(d.bytes)/1024/1024/1024, 2) AS size_gbFROM dba_tablespaces tJOIN dba_data_files d ON t.tablespace_name = d.tablespace_nameWHERE t.tablespace_name = 'APP_DATA'GROUP BY t.tablespace_name, t.status, t.contents, t.extent_management, t.segment_space_management, t.bigfile, t.encrypted;
-- Check autoextend settings for all datafilesSELECT file_name, ROUND(bytes/1024/1024, 0) AS current_mb, autoextensible, ROUND(increment_by * 8192/1024/1024, 0) AS next_mb, ROUND(maxbytes/1024/1024/1024, 2) AS max_gbFROM dba_data_filesWHERE tablespace_name = 'APP_DATA';
-- Confirm free space after creationSELECT tablespace_name, ROUND(SUM(bytes)/1024/1024, 0) AS free_mbFROM dba_free_spaceWHERE tablespace_name = 'APP_DATA'GROUP BY tablespace_name;Related Topics
Section titled “Related Topics”- How to Add a Datafile - Extend an existing tablespace
- How to Monitor Tablespace Usage - Track free space and growth
- How to Switch Undo Tablespace - Manage undo online
- Tablespace Scripts - Comprehensive DBA scripts