Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Matthew.

Asked: December 29, 2000 - 2:17 pm UTC

Last updated: January 04, 2013 - 10:15 am UTC

Version: 8.1.6

Viewed 10K+ times! This question is

You Asked

How can i generate a sql script from an existing database in order to create the database on another server?

Do i need a utility to perform this task?

Thanks for your help!
matthew


and Tom said...

If you are trying to "clone" a database and the operating systems are the same, simply backup the one database and restore it on another machine. that would be the fastest and easiest.

If they are not compatible, you would use dbassist to create a new database, take a FULL export of the existing database and perform an IMP of that. That'll create the users, the tablespaces, everything for you based on the old systems structure.

Rating

  (25 ratings)

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

Comments

More than one database in OS

Venkatesh, June 30, 2004 - 12:00 pm UTC

Hi Tom

Could u please list out the steps of creating more than one database in a server/OS. Assuming that there is a database existing already.

Thanx in advance

Tom Kyte
June 30, 2004 - 1:13 pm UTC

use dbca, follow the prompts, hit ok.

it'll create another one for you.

Create Oracle 10g database from dbca template

Laxman Kondal, June 09, 2006 - 8:47 am UTC

Hi Tom

I am trying to create Oracle 10gR2 database from template (including data) create by DBCA and moved it to another machine in same directory (/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates).

These three files where created by dbca:
wngdrp_temp.dbc
wngdrp_temp.ctl
wngdrp_temp.dfb

and when I ran dbca in different machine having same OS giving SID as wngdrp, I got this error:
ORA-01503: CREATE CONTROL FILE failed
ORA-00200: control file could not be created
ORA-00202: control file: ‘u01/app/oracle/oradata/wngdrp’
ORA-27056: could not delete file

I copied control file wngdrp_temp.ctl into this directory and reran dbca. Still stuck there only.

Could you please direct me to documents where I could find example for creating Oracle 10g database from template using dbca.

Thanks and regards.



Tom Kyte
June 09, 2006 - 9:07 am UTC

you do have full read/write/execute access on that entire directory tree correct?


(the person RUNNING dbca and the oracle software owner)

Create Oracle 10g database from dbca template

Laxman Kondal, June 09, 2006 - 9:25 am UTC

Hi Tom

Thanks for reply and I am running dbca as ORACLE, same as while installing Oracle software.

DBCA runs upto copying database files, first step, and then fails on second step, Creating & starting Oracle instance.
That time progress indicater is 38%.

Thanks and regards.

Tom Kyte
June 09, 2006 - 12:59 pm UTC

you did tell me that you have full read/write access all of the way down that directory.

You should not copy anything there at all.

Create Oracle 10g database from dbca template

Laxman Kondal, June 09, 2006 - 1:21 pm UTC

Hi Tom

User creating database has read/write access all of the way down that directory and the software ownere is oracle who ran the dbca.

Does it mean DBCA can creater database from template on same machine only?

Thanks and regards

Tom Kyte
June 09, 2006 - 1:39 pm UTC

Not sure what is going on, please utilize support to work through this one

The error is basically saying "no privilege to unlink, erase, a file in that directory"

reader

A reader, June 16, 2006 - 10:51 am UTC

Hi Tom

i have oracle 9i on win xp..please clarify some of my doubts.
1)
while creating a new database from command line ,do we need to shut down the older database or we can keep it running as it is..

2)
while creating a new database manually on windows when it says enviornment variable not defined do we have to create that variable as "user variable for administrators or "
system variables" from system properties 's advanced settings


3)whenever i try to open the database it shows this error,although it mounts fine)
ORA-12709: error while loading create database character set.
my nls_lang is null in all places in registry but if i change it to AMERICAN_AMERICA.WE8MSWIN1252 then also it shows the error message


Please guide

Tom Kyte
June 16, 2006 - 7:14 pm UTC

1) pre-existing databases can continue to run

2) you tell me, do you want it to persist or what.

I would not suggest doing it "manually", use dbca.


3) sounds like a bad oracle_home setting to me.

reader

A reader, June 19, 2006 - 11:02 am UTC

Hi Tom ,

like below as you said  i have tried to change the oracle_home also..no go..please help



C:\Documents and Settings\Administrator>echo %ORACLE_HOME%
C:\Oracle9\product\9.0

C:\Documents and Settings\Administrator>echo %ORACLE_BASE%
C:\Oracle9

C:\Documents and Settings\Administrator>echo %ORACLE_SID%
defdb

C:\Documents and Settings\Administrator>sqlplus /nolog

SQL*Plus: Release 9.0.1.0.1 - Production on Mon Jun 19 10:14:13 2006

(c) Copyright 2001 Oracle Corporation.  All rights reserved.

SQL> startup pfile=C:\Oracle9\product\9.0\database\initdefdb.ora
ORA-01031: insufficient privileges
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup pfile=C:\Oracle9\product\9.0\database\initdefdb.ora
ORACLE instance started.

Total System Global Area  118255568 bytes
Fixed Size                   282576 bytes
Variable Size              83886080 bytes
Database Buffers           33554432 bytes
Redo Buffers                 532480 bytes
ORA-12709: error while loading create database character set


SQL>

 

Tom Kyte
June 19, 2006 - 6:26 pm UTC

what was the create database character set then (I'll ask you to have a tar open with support as will, since this is an "internal" error - not having seen your create database steps (and not really wanting to!) they can collect all of that to help diagnose what went wrong.

install a second instance

Dawar Naqvi, October 23, 2006 - 7:18 pm UTC

Tom,

DB Version: 10g
OS : AIX 5.2

I need to install a second instance of Oracle on the existing server.

Could you guide me any link how to create instance?

Regards,
Dawar

Tom Kyte
October 24, 2006 - 12:32 am UTC

why?

the best and only number of instances on a given host is.....

ONE


(but one might ask you - how did you create the FIRST one? the second one would be done in the same manner typically)

install a second instance

Dawar Naqvi, October 24, 2006 - 10:55 am UTC

Tom,

This is our business requirement to install another instance.

this will be use by our third party application.

I am thinking to use dbca command to create the instance.

Do I need to take any precaution steps with dbca?
(Before or after installation of instance)

cheers,
Dawar



Tom Kyte
October 24, 2006 - 2:05 pm UTC

you will do this on your test environment first so when you make a mistake, it doesn't hurt anyone :)

but yes, dbca is the tool to use.

install a second instance

Dawar Naqvi, October 24, 2006 - 4:06 pm UTC

Tom,

I am creating another instance remotely.
As I mentioned earlier one instance is exits.

Does environment varibale set to db1 when I start dbca?

I am able to run dbca when environment variable set to db1.
But I want different ORACLE_HOME & ORACLE_SID.

So I export ORACLE_HOME & ORACLE_SID for #2 DB.

But I found in dbca (configuration assitance) its pickup ORACLE_HOME for DB1.


Cheers,
Dawar


Tom Kyte
October 25, 2006 - 9:25 am UTC


why would this be "another oracle home"????? you DO NOT install the software again for another instance. the oracle home should be THE SAME


dbca is a script, first part of script is - setting the correct and proper oracle home - of which THERE IS ONLY ONE, the oracle home that dbca is installed into

install a second instance

Dawar, October 24, 2006 - 4:52 pm UTC

Tom,


I created second instance.

I used dbca and took every thing default.
I only defined new ORACLE_SID.


ORACLE_HOME for db1 was

/u01/app/oracle/version10.2

so its create new SID folder after ORACLE_HOME and put all files.

My question is how to logon to db2 via sqlplus.

Please note:
ORACLE_HOME is set for db1.

cheers,
Dawar




Tom Kyte
October 25, 2006 - 9:26 am UTC

please utilize support. I don't know what you've done or why - with the multiple oracle homes.

instance

Dawar, October 24, 2006 - 5:28 pm UTC

Tom,

Sorry for ur time,
it was very straight foward.

I set ORACLE_SID=db2

and its connect to the new instance via sqlplus from command prompt.

create another instance with New ORACLE_HOME

Dawar Naqvi, October 25, 2006 - 3:14 pm UTC

Tom,


Is it possible to create another instance with new ORACLE_HOME?

I created new instance by using dbca utility.

So ORACLE_HOME are same in both instances.
But ORACLE_SIDs are different.

Its works fine.

Purpose:
Actually our vendor will import application data on this newly created instance.(11)

This application is not same as the application exists on instance (1) or existed DB.

So I wonder probably it is a good idea to keep both in different ORACLE_HOMEs.

cheers,
Dawar

Tom Kyte
October 25, 2006 - 4:26 pm UTC

is it possible to create one with a new oracle home?

SURE - INSTALL ORACLE AGAIN, create yet another oracle home


But my answer to "is it possible" is most definitely WHY WHY WHY??

DB Creation - Manual or DBCA

A reader, February 05, 2009 - 6:14 am UTC

Hi Tom,

We are to create a master script set to homogenize our database creation (10G).

I know there are two documented ways to create an oracle database, manual (do it yourself) or by using DBCA.

I would prefer to create a first script set with DBCA and modify this as few as absolutely necessary (eg. removing constants like database names). That way, I would get a standardized, documented, oracle supported & supplied and homogenized script set for free. I could also easily exclude (comment out) some options like oracle text and install it later on.

My colleagues want to go the manual way. They argue DBCA creates to many subscripts. DBCA might also run unneeded oracle supplied database scripts (like "owminst.plb"). They want to keep full control of all oracle supplied scripts run on the database. If some options like oracle text are needed afterwards they could also use DBCA to justify the installation. So, they are about to skim over the documentation and create our own proprietary script set.

What do you think?

Tom Kyte
February 05, 2009 - 11:02 am UTC

I am lazy by nature, I would (do) use dbca to create the database and if I was to script it, I would use (do use) dbca to create the scripts.


Now that said, there is nothing inherently wrong with their approach. It would not be my approach (the level of nesting does not bother me, I don't care about that - but they do...)

This is very much a "six one way, half a dozen the other way" issue - matter of choice.

Oracle licenses

John Thompson, February 05, 2009 - 11:49 am UTC

A good reason for having full control over the installation is that by default, DBCA installs options that are extra cost (partitioning and data mining come to mind). We're having to incurr downtime to de-install the option so if we get audited, we'll be safe.
Tom Kyte
February 05, 2009 - 12:10 pm UTC

data mining is selectable on the main dbca screens, you would choose to not configure it.

partitioning is enabled in all 10g databases - we use it even if you do not.

DBCA

A reader, February 05, 2009 - 12:04 pm UTC

You can choose what to install in DBCA. Always choose a custom database and uncheck all the options. It is hard to explain without screen shots. I use DBCA to create plain database with no sample schemas, no partitioning, no JVM, no XML DB...

Software versus Database Creation

Tony, February 05, 2009 - 12:09 pm UTC

You are confusing software installation and database creation. The software installation is where the options are involved, not the creation of the database. The software install should only be done once per machine (minus patches) The database creation is just creating files.

DB Creation - Manual or DBCA

A reader, February 06, 2009 - 10:48 am UTC

It might be more error-prone to do it yourself, no? You might forget a script or run it in wrong order. Additionally, you have to work through the manual database creation chapter within administration guide.

I guess using DBCA is highly recommended by oracle too?
Tom Kyte
February 06, 2009 - 4:01 pm UTC

well, hopefully testing would catch that.

... Additionally, you have to work through the manual
database creation chapter within administration guide. ...

and what is wrong with that exactly? :)

But it is like I said, I'm basically lazy, dbca would automate much for me, but the script might not be aesthetically pleasing.

Yes, to avoid configuration issues, it is recommended to use dbca, recommended but not mandatory.


dbca

sam, December 07, 2012 - 9:44 am UTC

Tom:

Can you advise on what to use for some options in dbca.
I am creating an 11gR2 database for OLTP application.
I will export a 9i schema and import it into this new 11g datbase.


1) Database Location Files (Screen 7)

Shall I select "Use Common location for all database files" or "Oracle managed files"?


2) Under Management options (Screen 4), there is an option to enable daily disk backups to Recovery area.

Under Recover Configuration screen later there is an option to specify flash recovery area for backups.


How are the two options different and do you recommend using them for production?


Tom Kyte
December 14, 2012 - 2:08 pm UTC

just upgrade the database sam. don't waste time/energy with export/import when you can just upgrade.


otherwise - you need to decide how you want to build your database. do you want to use oracle management files? do you not want to use them? your choice. and so on.


(one option is to set up backups, the other is to configure a flash recovery area - seems to say that...)

and again - do you want to enable daily disk backups? or not? and so on.

database

A reader, December 15, 2012 - 9:00 pm UTC

Tom:

These are two different machines: AIX to linux.
I cant upgrade the DB.

From what i see is that most peopl select standard directory and not oracle managed files.

Since this will be tested for a couple of months i dont want the daily backups.

WOuld flash recovery area take a lot of space? can i enable it later when i go live.
Tom Kyte
December 18, 2012 - 7:54 am UTC

SAM,

for all of the times you post here, you would think that you at least would know to provide relevant details so as to avoid wasting time (my time, your time, our time)....


if this is the substance of what you post:

Can you advise on what to use for some options in dbca.
I am creating an 11gR2 database for OLTP application.
I will export a 9i schema and import it into this new 11g datbase.


well, garbage in - garbage out.


seems you've answered your own questions...

you control the size of the fast recovery area, it is up to you and you can enable later - but that would be a bad idea since you would not know how to manage or work with it.

probably best left to your DBA - not to you.

Did you mean a sql plus script?

John Hawksworth, December 16, 2012 - 8:58 am UTC

Tom,

the OP may have meant producing a sql plus script from the original database. The benefit of this is that it enables the user's particular structures to be built at the press of a button in any database.

I've successfully used this method for several years,and it works very well, giving easy build and upgrades. If that is what's wanted, then sql plus can be used to generate the sql plus build scripts. Samples available on request.
Tom Kyte
December 18, 2012 - 12:09 pm UTC

creating a sql plus script from an entire database would be "not the best way".


If you don't have your install scripts in the first place... to recreate your structures at the drop of a hat... in source code control, locked away somewhere...


If you want to clone a database - today in 2012 - rman duplicate it (rman didn't exist when this was first written).

Or cross platform transport it

Or data pump it.


but creating a 'script' (for structures, data, etc) - no, that doesn't really work on todays databases...

Absolutely

A reader, December 18, 2012 - 6:16 pm UTC

Tom,

that's precisely what I was alluding to.
I build our databases entirely from script, and they are indeed under strict version control.

I didn't mean script the database as in what the DBCA does, but rather script our schemas in a blank database, which has been produced by the DBCA (or indeed another script).

Obviously using scripts for duplicating a database is daft, since as you so rightly say, RMAN does that anyway.

oracle managed files

A reader, December 19, 2012 - 11:23 pm UTC

Tom:

Do you normally use "oracle managed files" in your database systems?

http://docs.oracle.com/cd/B10501_01/server.920/a96521/omf.htm


What cases do you recommend using it or not using it?
Tom Kyte
December 20, 2012 - 5:11 pm UTC

It doesn't matter Sam, I'm not you, I don't have your system, I'm not your DBA

what does your DBA say Sam?


(I use Oracle managed files for demo systems, in a real system I would almost certainly be using specific file names. Just my *preference*)

OOMF

A reader, December 21, 2012 - 7:04 am UTC

Tom:

The DBA did not know what OMF is all about. I know your answer about finding another one. Good luck...

Anyway i read this article and got full understanding about what it does and I decided not to use it for production system. It is not really much to drop a datafile and create a new datafile when you create/drop a tablespace (for tablespace OMF).

http://www.idevelopment.info/data/Oracle/DBA_tips/Tablespaces/TBS_8.shtml
Tom Kyte
January 04, 2013 - 10:15 am UTC

The DBA did not know what OMF is all about.

time for a new DBA, this is not a new feature or anything.


create your own database manually in oracle 10g

Asim khan, March 25, 2013 - 4:55 am UTC

------------------------------------------------------------
step1. | First you create your own oracle service like that.
------------------------------------------------------------

go to cmd command line program
c:\>oradim -new -sid lrh -startmode auto

------------------------------------------------------------
step2. | second we start the instance which we have created in the first step.
-------------------------------------------------

to to cmd command.

c:\>set ora_sid=lrh
c:\>sqlplus\nolog

--------------------------------------------------------------------------------------------
step3. | 3rd we will goes for creating Folders
-------------------------------------------------------------------------------------------
-goes to c drive
-there folder create like that (mydb) name
-open mydb folder and create other folder inside them such as
udump,adump,datafiles,log,udump,temp,flash_recovery_area,pfile,cdump,archive and so on

------------------------------------------------------------------------------------------
step4. | 4th we will goes to sql/plsql program and open it and login on sys as sysdba/password
------------------------------------------------------------------------------------------

startup nomount pfile='c:\mydb\initlrh.ora';

----------------------------------------------------------------------------------------------------
step5.| copy and past this code in another notepade page and saved them on the name of initlrh.ora
----------------------------------------------------------------------------------------------------
background_dump_dest='C:\MYDB\bdump'
compatible='10.1.0.2.0'
control_files='C:\MYDB\DATAFILES\control01.ctl',
'C:\MYDB\DATAFILES\control01.ct2.ctl',
'C:\MYDB\DATAFILES\control01.ct3.ctl'
core_dump_dest='C:\MYDB\cdump'
db_block_size=8192
db_cache_size=25165824
db_domain=''
db_file_multiblock_read_count=16
db_name='LRH'
db_recovery_file_dest='C:\MYDB\flash_recovery_area'
db_recovery_file_dest_size=2147483648
dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
java_pool_size=50331648
job_queue_processes=10
large_pool_size=8388608
open_cursors=300
pga_aggregate_target=25165824
processes=150
shared_pool_size=83886080
sort_area_size=65536
undo_management='AUTO'
undo_tablespace='UNDOTBS1'
user_dump_dest='C:\MYDB\udump'
.............................................................................

step6 | copy and past in SQL/plsql page and press enter.

............................................................................

create database LRH
user sys identified by sys
user system identified by system
logfile group 1('c:\mydb\datafiles\redo1.log','c:\mydb\datafiles\redo2.log') size 10m,
group 2('c:\mydb\datafiles\redoa1.log','c:\mydb\datafiles\redoa2.log') size 10m
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
DATAFILE 'c:\mydb\datafiles\system01.dbf' SIZE 325M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNlimited
sysaux DATAFILE 'c:\mydb\datafiles\sysaux01.dbf' SIZE 325M REUSE AUTOEXTEND ON NEXT 1m MAXSIZE unlimited
UNDO TABLESPACE undotbs1
datafile 'c:\mydb\datafiles\undo01.dbf' size 10m
default temporary tablespace temp
tempfile 'c:\mydb\datafiles\temp01.dbf' size 10m

------------------------------------------------------------------------------

step7. | complete the database creation this two query must be run on sys as syddba
and without that your database in not completed.

------------------------------------------------------------

sql>@?/rdbms/admin/catalog.sql ----- for used data dictionary
ql>@?/rdbms/admin/catproc.sql ----- for used pl/sql



how to create your own database in oracle 10g

Asim khan, March 25, 2013 - 5:00 am UTC

------------------------------------------------------------------------------------------
step1. | First you create your own oracle service like that.
------------------------------------------------------------------------------------------

go to cmd command line program
c:\>oradim -new -sid lrh -startmode auto

-------------------------------------------------------------------------------------------
step2. | second we start the instance which we have created in the first step.
-------------------------------------------------------------------------------------------

to to cmd command.

c:\>set ora_sid=lrh
c:\>sqlplus\nolog

--------------------------------------------------------------------------------------------
step3. | 3rd we will goes for creating Folders
-------------------------------------------------------------------------------------------
-goes to c drive
-there folder create like that (mydb) name
-open mydb folder and create other folder inside them such as
udump,adump,datafiles,log,udump,temp,flash_recovery_area,pfile,cdump,archive and so on


----------------------------------------------------------------------------------------------------
step4.| copy and past this code in another notepade page and saved them on the name of initlrh.ora
----------------------------------------------------------------------------------------------------
background_dump_dest='C:\MYDB\bdump'
compatible='10.1.0.2.0'
control_files='C:\MYDB\DATAFILES\control01.ctl',
'C:\MYDB\DATAFILES\control01.ct2.ctl',
'C:\MYDB\DATAFILES\control01.ct3.ctl'
core_dump_dest='C:\MYDB\cdump'
db_block_size=8192
db_cache_size=25165824
db_domain=''
db_file_multiblock_read_count=16
db_name='LRH'
db_recovery_file_dest='C:\MYDB\flash_recovery_area'
db_recovery_file_dest_size=2147483648
dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
java_pool_size=50331648
job_queue_processes=10
large_pool_size=8388608
open_cursors=300
pga_aggregate_target=25165824
processes=150
shared_pool_size=83886080
sort_area_size=65536
undo_management='AUTO'
undo_tablespace='UNDOTBS1'
user_dump_dest='C:\MYDB\udump'

------------------------------------------------------------------------------------------
step5. | 4th we will goes to sql/plsql program and open it and login on sys as sysdba/password
------------------------------------------------------------------------------------------

startup nomount pfile='c:\mydb\initlrh.ora';
.............................................................................

step6 | copy and past in SQL/plsql page and press enter.

............................................................................

create database LRH
user sys identified by sys
user system identified by system
logfile group 1('c:\mydb\datafiles\redo1.log','c:\mydb\datafiles\redo2.log') size 10m,
group 2('c:\mydb\datafiles\redoa1.log','c:\mydb\datafiles\redoa2.log') size 10m
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
DATAFILE 'c:\mydb\datafiles\system01.dbf' SIZE 325M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNlimited
sysaux DATAFILE 'c:\mydb\datafiles\sysaux01.dbf' SIZE 325M REUSE AUTOEXTEND ON NEXT 1m MAXSIZE unlimited
UNDO TABLESPACE undotbs1
datafile 'c:\mydb\datafiles\undo01.dbf' size 10m
default temporary tablespace temp
tempfile 'c:\mydb\datafiles\temp01.dbf' size 10m

------------------------------------------------------------------------------

step7. | complete the database creation this two query must be run on sys as syddba
and without that your database in not completed.

--------------------------------------------------------------------------------

sql>@?/rdbms/admin/catalog.sql ----- for used data dictionary
ql>@?/rdbms/admin/catproc.sql ----- for used pl/sql



More to Explore

Backup/Recovery

Check out the complete guide to all of the Backup & Recovery techniques in the Oracle Database.