Professional Documents
Culture Documents
An Oracle tablespace is a big unit of logical storage in an Oracle database. It is managed and
used by the Oracle server to store structures data objects, like tables and indexes.
What Is an Oracle Data File?
An Oracle data file is a big unit of physical storage in the OS file system. One or many
Oracle data files are organized together to provide physical storage to a single Oracle
tablespace.
How a Tablespace Is Related to Data Files?
Each tablespace in an Oracle database consists of one or more files called datafiles, which are
physical structures that conform to the operating system in which Oracle is running.
How a Database Is Related to Tablespaces?
A databases data is collectively stored in the datafiles that constitute each tablespace of the
database. For example, the simplest Oracle database would have one tablespace and one
datafile. Another database can have three tablespaces, each consisting of two datafiles (for a
total of six datafiles).
How To View the Tablespaces in the Current Database?
If you want to get a list of all tablespaces used in the current database instance, you can use
the DBA_TABLESPACES view as shown in the following SQL script example:
SQL> connect SYSTEM/fyicenter
Connected.
SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS
2 FROM USER_TABLESPACES;
TABLESPACE_NAME
STATUS
CONTENTS
ONLINE
ONLINE
ONLINE
ONLINE
ONLINE
PERMANENT
UNDO
PERMANENT
TEMPORARY
PERMANENT
BYTES
\ORACLEXE\ORADATA\XE\USERS.DBF 104857600
\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440
\ORACLEXE\ORADATA\XE\UNDO.DBF
94371840
\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840
How To Create a new Oracle Data File? There is no dedicated statement to create a data file.
Data files are created as part of statements that manages other data structures, like tablespace and
database. How To Create a New Tablespace? If you want a new dataspace, you can use the
CREATE TABLESPACE DATAFILE statement as shown in the following script:
CONTENTS
ONLINE
PERMANENT
ONLINE
UNDO
ONLINE
PERMANENT
TEMP
ONLINE
TEMPORARY
USERS
ONLINE
PERMANENT
MY_SPACE
ONLINE
PERMANENT
BYTES
\ORACLEXE\ORADATA\XE\USERS.DBF 104857600
\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440
\ORACLEXE\ORADATA\XE\UNDO.DBF
94371840
\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840
\TEMP\MY_SPACE.DBF
10485760
So one statement created two structures: a tablespace and a data file. If you check your file
system with Windows file explorer, you will see the data file is located in the \temp directory
of. The data file size is about 10MB. Its contents should be blank and full of \x00 at this time.
How To Rename a Tablespace?
You can easily rename a tablespace by using the ALTER TABLESPACE RENAME TO
statement as shown in the example below:
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> ALTER TABLESPACE my_space RENAME TO your_space;
Tablespace created.
CONTENTS
ONLINE
PERMANENT
ONLINE
UNDO
ONLINE
PERMANENT
TEMP
ONLINE
TEMPORARY
USERS
ONLINE
PERMANENT
YOUR_SPACE
ONLINE
PERMANENT
With the INCLUDING CONTENTS AND DATAFILES clause, all contents and mapped data
files are also deleted.
TABLESPACE_NAME
NUM_ROWS
MY_SPACE
USERS
107
...
FILE_ID
BYTES
5 10354688
USERS
4 101974016
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS
65536
USERS has one big free extent of 100MB, and many small free extents
of 64KB.
How To Bring a Tablespace Offline?
If you want to stop users using a tablespace, you can bring it offline
using the ALTER TABLESPACE OFFLINE statement as shown in the
following script:
SQL> connect HR/fyicenter
Connected.
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> ALTER TABLESPACE my_space OFFLINE NORMAL;
Tablespace altered.
Tablespace altered.
SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES
2 FROM DBA_DATA_FILES;
TABLESPACE_NAME FILE_NAME
BYTES
C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600
C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440
C:\ORACLEXE\ORADATA\XE\UNDO.DBF
94371840
C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840
MY_SPACE
C:\TEMP\MY_SPACE.DBF
MY_SPACE
C:\TEMP\MY_SPACE_2.DBF
10485760
5242880
FILE_ID
BYTES
5177344
MY_SPACE
5 10354688
SQL> STARTUP
ORACLE instance started.
Total System Global Area 100663296 bytes
Fixed Size
1285956 bytes
Variable Size
58720444 bytes
Database Buffers
37748736 bytes
Redo Buffers
2908160 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR
trace file
ORA-01110: data file 5: 'C:\TEMP\MY_SPACE.DBF'
SQL> SHUTDOWN;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
1285956 bytes
Variable Size
58720444 bytes
Database Buffers
Redo Buffers
Database mounted.
37748736 bytes
2908160 bytes
BYTES
C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600
C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 503316480
C:\ORACLEXE\ORADATA\XE\UNDO.DBF
94371840
C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 367001600
MY_SPACE
C:\TEMP\MY_SPACE.DBF
MY_SPACE
C:\TEMP\MY_SPACE_2.DBF
At this point, if you dont care about the data in MY_SPACE, you can
drop it now with the database opened.