Home » Oracle » Oracle Database » How to check default tablespace in Oracle database

How to check default tablespace in Oracle database

Default tablespace

  • Default tablespace is the Oracle tablespace where objects like Oracle table and Oracle index are created by the user when no tablespace name is specified in the object creation clause.
  • We can define both the Permanent and temporary tablespace for the users
  • With 9i, you can specify the default permanent and default temp tablespace at database creation time and after the database is created also
  • Each Oracle user created will have the same default Permanent and temporary tablespace as specified at the database level
  • You can specify differently for users by specifying the different ones at the user creation time

How to find the default tablespace at the Database level

Values of the current setting of the Default can be found using the below queries

COLUMN property_name FORMAT A30
 COLUMN property_value FORMAT A30
 COLUMN description FORMAT A50
 SET LINESIZE 200
 SELECT *
 FROM database_properties
 WHERE property_name like '%TABLESPACE';
 PROPERTY_NAME           PROPERTY_VALUE                 DESCRIPTION
 ------------            -------------                    ---------
DEFAULT_PERMANENT_TABLESPACE   USERS   Default Permanent Tablespace ID
DEFAULT_TEMP_TABLESPACE        TEMP     default temporary tablespace

We can find the individual one using the below queries

SQL> SELECT property_name,property_value FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';
 PROPERTY_NAME                  PROPERTY_VALUE
 -------------                  ---------------
 DEFAULT_TEMP_TABLESPACE        TEMP
 
SQL> SELECT property_name,property_value FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_PERMANENT_TABLESPACE';
 PROPERTY_NAME                  PROPERTY_VALUE
 -------------                  --------------
 DEFAULT_PERMANENT_TABLESPACE   USERS

When users are created, and no default permanent and default temp tablespace is given, then users’ defaults permanent and temp tablespace are set to these settings

See also  Oracle 23c/23ai Database New Features

How to change the settings

We should have the new tablespace existing and then we can use the below command

alter database default temporary tablespace temp2;
alter database default permanent tablespace user2;

SQL> SELECT property_name,property_value FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';
 PROPERTY_NAME                  PROPERTY_VALUE
 ------------                   -------------
 DEFAULT_TEMP_TABLESPACE        TEMP2
 SQL> SELECT property_name,property_value FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_PERMANENT_TABLESPACE';
 PROPERTY_NAME                  PROPERTY_VALUE
 -------------                   ------------
 DEFAULT_PERMANENT_TABLESPACE   USERS2

Warning /Caveat

This command sets the default permanent tablespace and temporary tablespace for all the users irrespective of their previous settings. So if some user was created with some different permanent tablespace and temporary tablespace, then that user will also revert to the new default permanent tablespace and temporary tablespace. So it will be better if we can store the default tablespace of all the users in some backup table before changing it. Then you can do the comparison and change for the users where it is required

create table before_tab_permanent select username,default_tablespace from dba_users where default_tablespace not in (SELECT property_value FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_PERMANENT_TABLESPACE';

create table before_tab_temporary select username,TEMPORARY_TABLESPACE from dba_users where TEMPORARY_TABLESPACE not in (SELECT property_value FROM DATABASE_PROPERTIES where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';

spool change_tablespace_user.sql
select 'alter user'|| username||' default tablespace'|| default_tablespace ||';' from before_tab_permanent;
select 'alter user'|| username||' TEMPORARY tablespace'|| TEMPORARY_TABLESPACE||';' from before_tab_temporary;
spool off

@change_tablespace_user.sql

How to check tablespace assigned to user in Oracle

select username,default_tablespace,TEMPORARY_TABLESPACE from dba_users where username = '&1';

How to change the default tablespace for the particular User

alter user <username> default tablespace <tablespace_name>;
alter user <username> temporary tablespace <tablespace_name>;
Verify the Results
select username,default_tablespace,TEMPORARY_TABLESPACE from dba_users where username = '&1';

Hope you like the content on how to check the default tablespace in the Oracle database. Please provide feedback.

See also  Oracle E-Business Suite Architecture in 12.2

Also Reads
Oracle Database Administration Tutorials
https://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4174.htm#REFRN23302
How to check Tablespace in Oracle
How to check temp tablespace in Oracle: This article is about temp tablespace in Oracle, resize the tempfile, drop the tempfile, and find the temp usage by Session
shrink datafile in Oracle: Check out how to shrink the datafile and reclaim space on the filesystem. How to resolve ORA-03297
Supplemental Logging in Oracle
Query to find object dependencies in oracle
JSON in Oracle database

1 thought on “How to check default tablespace in Oracle database”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top