Skip to Main Content
  • Questions
  • Script to generate create tablespace...

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Jenny.

Asked: March 04, 2003 - 7:32 pm UTC

Last updated: April 08, 2005 - 6:53 am UTC

Version: 8.1.7

Viewed 10K+ times! This question is

You Asked

Tom,

I'm trying to collect DDLs for tablespaces within a database. Instead of using OEM and do copy and paste to another file, I was wondering if you happen to have a script that you can share with me that would generate "CREATE TABLESPACE ... " ddls?

Thanks,
Jenny

and Tom said...

exp userid=u/p full=y rows=n

you can ctl-c that right after it says "exporting profiles", for example:


$ exp userid=/ full=y rows=n

Export: Release 8.1.7.4.0 - Production on Wed Mar 5 09:22:20 2003
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production
Export done in WE8ISO8859P1 character set and WE8ISO8859P1 NCHAR character set
Note: table data (rows) will not be exported

About to export the entire database ...
. exporting tablespace definitions
. exporting profiles
. exporting user definitions
. exporting roles
. exporting resource costs
. exporting rollback segment definitions^C
EXP-00008: ORACLE error 1013 encountered
ORA-01013: user requested cancel of current operation
EXP-00000: Export terminated unsuccessfully


And then:

imp userid=u/p full=y show=y

will show the create tablespace commands. They will be "wrapped" and in need of fixing. If you are using UNIX, strings works nicely here:

$ strings expdat.dmp | grep 'CREATE TABLESPACE'
CREATE TABLESPACE "RBS_TS_01" DATAFILE '/d01/oradata/ora817dev/rbs_ts_01.dbf' SIZE 156344320 REUSE AUTOEXTEND ON NEXT 1048576 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288 ONLINE PERMANENT
CREATE TABLESPACE "RBS_TS_02" DATAFILE '/d02/oradata/ora817dev/rbs_ts_02.dbf' SIZE 665952256 REUSE AUTOEXTEND ON NEXT 1048576 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288 ONLINE PERMANENT
CREATE TABLESPACE "RBS_TS_03" DATAFILE '/d03/oradata/ora817dev/rbs_ts_03.dbf' SIZE 200384512 REUSE AUTOEXTEND ON NEXT 1048576 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288 ONLINE PERMANENT
CREATE TABLESPACE "RBS_TS_04" DATAFILE '/d04/oradata/ora817dev/rbs_ts_04.dbf' SIZE 48340992 REUSE AUTOEXTEND ON NEXT 1048576 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288 ONLINE PERMANENT
CREATE TABLESPACE "RBS_TS_05" DATAFILE '/d01/oradata/ora817dev/rbs_ts_05.dbf' SIZE 26320896 REUSE AUTOEXTEND ON NEXT 1048576 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288 ONLINE PERMANENT
CREATE TABLESPACE "USERS" DATAFILE '/d04/oradata/ora817dev/users.dbf' SIZE 1553M REUSE AUTOEXTEND ON NEXT 524288 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288 ONLINE PERMANENT NOLOGGING
CREATE TABLESPACE "DRSYS" DATAFILE '/d04/oradata/ora817dev/drsys.dbf' SIZE 36700160 REUSE AUTOEXTEND ON NEXT 524288 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288 ONLINE PERMANENT
CREATE TABLESPACE "CLAMS" DATAFILE '/d03/oradata/ora817dev/clams.dbf' SIZE 78118912 REUSE AUTOEXTEND ON NEXT 524288 MAXSIZE 2000M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 524288


Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Also can be done using dynemic sql

A Reader, March 05, 2003 - 9:57 am UTC

By joining dba_tablespaces and dba_data_files you can easily create a spool file which will dump create statements for tablespaces.
It may take some efforts to write sql but once you have it you can reuse quiet easily.

That's exactly what I was looking for!

Jenny, March 05, 2003 - 12:37 pm UTC

Thank you!!!

REUSE

Thiru, August 24, 2004 - 1:59 pm UTC

What does the word REUSE in creating tablespaces do? Does it mean that if the datafile already exists then overwrite it? And if we dont use the word REUSE and if the datafile exists, does it give error?

Thanks.

Tom Kyte
August 24, 2004 - 3:33 pm UTC

reuses the existing datafile if one exists.

if the file exists and you didn't reuse, it would bomb, yes.

why isn't reuse faster than a normal create?

Justin, April 08, 2005 - 12:11 am UTC

system@DEV> create tablespace data datafile 'C:\ORADATA\DEV\DATA01.DBF' size 500m;

Tablespace created.

Elapsed: 00:00:34.04
system@DEV> drop tablespace data;

Tablespace dropped.

Elapsed: 00:00:02.00
system@DEV> create tablespace data datafile 'C:\ORADATA\DEV\DATA01.DBF' size 500m reuse;

Tablespace created.

Elapsed: 00:00:42.03

There's nothing else going on on this box during these tests.

Any thoughts?

Thanks much

Tom Kyte
April 08, 2005 - 6:53 am UTC

reuse just lets Oracle overwrite the existing file.

it still needs to be "initialized", wiped out, set to "new datafile status", written.

More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.