Overview of Database Creation Tasks on Windows Using Command-Line Tools

Learn how to create a new database manually. As part of its database software files, Oracle Database provides a sample initialization parameter file, which can you can edit to suit your needs.

You can choose to create database creation scripts using Oracle Database Configuration Assistant.

The following are the types of Database creation tasks:

  • Copy an existing database and delete the old database.

  • Copy an existing database and keep the old database.

  • Create a new database when no database exists on your system.

Manual Database Creation Tasks

Use Manual Database Creation Tasks to understand the manual tasks involved in creating a new database for each of these database creation categories. Each step is explained in detail in the following subsections.

Table 4-1 Manual Database Creation Tasks

Task Copy existing database and delete old database Copy existing database and keep old database Create new database when no database exists on system
About Exporting an Existing Database

Yes

Note 1

Not applicable

Deleting Database Files

Yes

No

Not applicable

Modifying the Initialization Parameter File

Yes

Yes

Yes

Starting an Oracle Database Instance

Yes

Yes

Yes

About Creating and Starting an Oracle Database Service

No

Yes

Yes

Putting the CREATE DATABASE Statement in a Script

Yes

Yes

Yes

Running the CREATE DATABASE Script

Yes

Yes

Yes

About Importing a Database

Yes

Note 2

Not applicable

Updating ORACLE_SID in the Registry

No

Only if you change the default SID

Yes

Backing Up the New Database

Yes

Yes

Yes

Note 1

Yes if you copy data from the existing database to the new database; otherwise, no.

Note 2

Yes if you import tables and other objects exported from the existing database; otherwise, no.

An example in the following sections demonstrates how to create a database. In this example, the existing database is the starter database with a SID of orcl located in directory C:\app\username\oradata\orcl. Copy orcl to a new database with a database name and SID of prod located in the directory C:\app\username\oradata\prod. Then, delete the starter database orcl.

About Exporting an Existing Database

You are required to export an existing database only if you intend to copy its contents to a new database.

If you are working with data from an earlier Oracle release, then you can use Export for this task. If you are using Oracle Database 10g Release 1 (10.1) or later data, then Oracle recommends that you use Data Pump Export because it supports new Oracle Database 10g Release 1 (10.1) or later features, such as floating points.

Although you can start Data Pump Export or Export in either the parameter mode or an interactive mode, Oracle recommends parameter mode. Interactive mode provides less functionality than the parameter mode and exists for backward compatibility only.

The syntax for Data Pump Export parameter mode is:

C:\> expdp SYSTEM DUMPFILE=myexp.dmp FULL=y LOGFILE=myexp.log
Password: password

The syntax for Data Pump Export interactive mode is:

C:\> expdp SYSTEM 
Password: password

Enter only the command expdp SYSTEM to begin an interactive session and let Data Pump Export prompt you for information it needs.

Note:

If you use the parameter mode, then Data Pump Export considers the file names and the directory names to be invalid if they contain one or more blank spaces. The workaround is to enclose the full path in the DUMPFILE= parameter in triple quotation marks. For example:

DUMPFILE="""C:\program files\export.dmp"""

If Data Pump Export is used in an interactive mode, then the file name or the directory name can contain a space without quotation marks.

The syntax for Export parameter mode is:

C:\> exp SYSTEM FILE=myexp.dmp FULL=y LOG=myexp.log
Password: password

The syntax for the Export interactive mode is:

C:\> exp SYSTEM
Password: password

Enter only the command exp SYSTEM to begin an interactive session and let Export prompt you for information it needs.

Note:

If you use the parameter mode, then Export considers the file names and the directory names to be invalid if they contain one or more blank spaces. The workaround is to enclose the full path in the FILE= parameter in triple quotation marks. For example:

FILE="""C:\program files\export.dmp"""

If Export is used in an interactive mode, then the file name or the directory name can contain a space without quotation marks.

See Also:

Oracle Database Utilities for more information about using Data Pump Export or Export

Exporting All Data from an Existing Database

Describes how to export all data from an existing database to a new database.

To export:

  1. Set ORACLE_SID to the database service of the database whose contents you intend to export. For example, if the database you intend to export is the starter database orcl, then enter the following at the command prompt. Note that there are no spaces around the equal sign (=) character.
    C:\> set ORACLE_SID=orcl
    
  2. If the existing database is Oracle Database 10g Release 1 (10.1) or later, then start Data Pump Export from the command prompt:
    C:\> expdp SYSTEM DUMPFILE=myexp.dmp FULL=y LOG=myexp.log
    Password: password
    

    You now have a full database export of the starter database orcl in the file myexp.dmp. All messages from Data Pump Export are logged in file myexp.log.

  3. If the existing database is earlier than Oracle Database 10g Release 1 (10.1), then start Export from the command prompt:
    C:\> exp SYSTEM FILE=myexp.dmp FULL=y LOG=myexp.log
    Password: password
    

    You now have a full database export of the starter database orcl in the file myexp.dmp. All messages from Export are logged in the file myexp.log.

Deleting Database Files

Deleting database files is required only when you copy an existing database to a new database to replace the old database.

In the following example, you delete the database files of the starter database orcl.

To delete database files:

  1. Shut down starter database orcl at the command prompt:
    C:\> oradim -SHUTDOWN -SID orcl -SHUTTYPE inst -SHUTMODE immediate
    
  2. Delete the following files from the directory C:\app\username\oradata\orcl:
    control01.ctl
    control02.ctl
    control03.ctl
    index01.dbf
    drsys01.dbf
    cwmlite01.dbf
    example01.dbf
    system01.dbf
    temp01.dbf
    tools01.dbf
    undotbs01.dbf
    user01.dbf
    xdb01.dbf
    redo01.log
    redo02.log
    redo03.log

Modifying the Initialization Parameter File

Describes how to modify the initialization parameter file.

To use the starter database orcl as the basis for your new database:

  1. Copy ORACLE_BASE\admin\orcl\pfile\init.ora.

  2. Place the copy in ORACLE_BASE\admin\prod\pfile\init.ora.

  3. Modify the file by performing the following tasks:

    Note:

    Starting with Oracle9i Release 2 (9.2), nesting of quotation marks using the backslash (\) escape character is no longer supported. This affects how Oracle Database interprets the parameter values in your initialization parameter file. For example, if you specified CONTROL_FILES = "ctlfile\'1.ora" in releases before release 9.2, the file name was interpreted as ctlfile'1.ora. Starting with release 9.2, the file name will be interpreted as ctlfile\'1.ora.

    Oracle highly recommends modifying your parameter files to remove such references and other methods of nesting quotation marks in the initialization parameter values.

    1. If you do not have an existing database on your system, then you cannot copy an existing initialization parameter file to use as the basis for your new initialization parameter file. However, you can use the sample initialization parameter file initsmpl.ora provided in:

      ORACLE_HOME\admin\sample\pfile
      

      This is the basis for the initialization parameter file for the database prod.

    2. If you use the initsmpl.ora file as the basis for the initialization parameter file, then the following parameters must be set to the indicated values, otherwise you cannot start database prod:

      DB_NAME=prod.domain

      The parameter DB_NAME indicates the database name and must match the name used in the CREATE DATABASE statement. Give a unique database name to each database. You can use eight characters for a database name. The name is not required to match the SID of the database service.

      INSTANCE_NAME=prod.domain

      SERVICE_NAMES=prod.domain

      CONTROL_FILES = ( "C:\app\username\oradata\prod\control01.ctl", "C:\app\username\oradata\prod\control02.ctl", "C:\app\username\oradata\prod\control03.ctl")

      The parameter CONTROL_FILES lists the database control files. You do not have to control files on your file system at this point, because control files are created when you run the CREATE DATABASE statement. Ensure that you specify the complete path and the file name, including the drive letter.

      DB_FILES=100

      Modifying the initialization parameter DB_FILES is not required, but it is recommended to optimize performance. Set this parameter to the same number as the value of the MAXDATAFILES option of the CREATE DATABASE statement. The value of 100 is used for this example.

      The DIAGNOSTIC_DEST initialization parameter sets the location of the Automatic Diagnostic Repository (ADR), which is a directory structure stored outside of the database. The ADR is used in problem diagnostics.

      Use DIAGNOSTIC_DEST = ORACLE_HOME\log if the environment variable ORACLE_BASE is not set.

      Use DIAGNOSTIC_DEST = ORACLE_BASE variable if the environment variable ORACLE_BASE is set.

      See Also:

About Creating and Starting an Oracle Database Service

Learn how to create and start an Oracle Database service.

Perform either of the following steps:

  • Copy an existing database to a new database and keep the old database

  • Create a new database when you have no other database to copy

Before you create the database, first create a Windows service to run the database. This service is the Oracle Database process, oracle.exe, installed in the form of a Windows service.

Use ORADIM to create the service.

Creating and Starting an Oracle Database Service

Learn how to create and start an Oracle Database service.

To create and start an Oracle Database service:

  1. Run ORADIM from the command prompt:
    C:\> oradim -NEW -SID prod -STARTMODE manual
    -PFILE "C:\app\username\admin\prod\pfile\init.ora"
    

    Note that the previously created initialization parameter file is specified, with complete path, including drive name. You can check if the service is started in the Services window of the Control Panel. ORADIM automatically creates Oracle Database services under the Oracle Home User account. If the Oracle Home User account is a Windows Local User Account or a Windows Domain User Account, then ORADIM prompts for its password.

  2. Set the value of ORACLE_SID to prod. Note that there are no spaces around the equal sign (=) character:
    C:\> set ORACLE_SID=prod
    

Access to Oracle Wallets in a File System for Oracle Database Services

Discusses about accessing Oracle Wallets.

When an Oracle wallet is created in the file system, only the user creating the wallet is granted access to that wallet by wallet creation tools. Therefore, Oracle Database services (running as the Windows User Account) might not be able to access the wallet unless you explicitly grant access to the wallet using Windows tools.

Starting an Oracle Database Instance

Learn how to start an instance without mounting a database.

Start an instance without mounting a database.

SQL> STARTUP NOMOUNT

You must not specify the PFILE clause in this example, because the initialization parameter file is stored in the default location. At this point, there is no database. Only the System Global Area (SGA) is created and the background processes are started in preparation for the creation of a new database.

Adding the CREATE DATABASE Statement in a Script

The CREATE DATABASE statement is a SQL statement that creates the database.

A script containing this statement can be used anytime you create a database.

The CREATE DATABASE statement has the following parameters:

  • MAXDATAFILES - default value: 32, maximum value: 65534

  • MAXLOGFILES - default value: 32, maximum value: 255

The CHARACTER SET parameter determines the database character set of the new database. The default value is US7ASCII, however the recommended value is AL32UTF8. AL32UTF8 is the Oracle implementation of the Unicode Standard character set in UTF-8 encoding form. Unicode is suitable for storing text in practically any written language of the world.

When you run the CREATE DATABASE statement, Oracle Database performs several operations depending upon the clauses that you specified in the CREATE DATABASE statement or the initialization parameters that you have set.

Note:

Oracle Managed Files is a feature that works with the CREATE DATABASE statement to simplify administration of Oracle Database. Oracle Managed Files eliminates the requirement to directly manage operating system files comprising an Oracle Database server, because you specify operations in terms of database objects rather than file names.

To create the database prod, copy and save the following statement in a file named script_name.sql:

CREATE DATABASE prod
USER SYS IDENTIFIED BY sys_password
USER SYSTEM IDENTIFIED BY system_password
MAXLOGFILES 5
MAXDATAFILES 100
DATAFILE 'C:\app\username\oradata\prod\system01.dbf' SIZE 325M REUSE
AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
UNDO TABLESPACE "UNDOTBS" DATAFILE 'app\username\oradata\prod\undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
CHARACTER SET AL32UTF8
logfile 'C:\app\username\oradata\prod\redo01.log' size 100M reuse,
        'C:\app\username\oradata\prod\redo02.log' size 100M reuse,
        'C:\app\username\oradata\prod\redo03.log' size 100M reuse
EXTENT MANAGEMENT LOCAL;

See Also:

Running the CREATE DATABASE Script

Use this procedure to run the CREATE DATABASE script.

To use the SQL script to create a database:

  1. Verify that the service is started in the Control Panel. In this example, the service name is OracleServicePROD, and its status column must display Started. If not, then select the service name and select Start.

    You can also check the status of the service by entering the following at the command prompt:

    C:\> net START
    

    A list of all the Windows services currently running on the system appears. If OracleServicePROD is missing from the list, then enter:

    C:\> net START OracleServicePROD
    
  2. Make PROD the current SID:
    C:\> set ORACLE_SID=PROD
    
  3. Add ORACLE_HOME\bin to your PATH environment variable:
    set PATH=ORACLE_BASE\ORACLE_HOME\bin;%PATH%
    
  4. Start SQL*Plus from the command prompt, and connect to the database as SYSDBA:
    C:\> sqlplus /NOLOG
    SQL> CONNECT / AS SYSDBA 
    

    The message connected appears.

  5. Turn on spooling to save messages:
    SQL> SPOOL script_name.log
    
  6. Run the script script_name.sql that you created in Adding the CREATE DATABASE Statement in a Script.
    SQL> C:\app\username\product\12.2.0\dbhome_1\rdbms\admin\script_name.sql;
    

    If the database is successfully created, then the instance is started and the following message appears numerous times: Statement processed

About Importing a Database

Learn how to use Data Pump Import or Import.

You can use Data Pump Import (for Oracle Database 10g Release 1 (10.1) or later data) or Import (for earlier data) to import the full export created into the new database. Although you can start Data Pump Import or Import using either the parameter mode or the interactive mode, Oracle recommends the parameter mode because it provides more functionality. Interactive mode exists solely for backward compatibility.

The syntax for Data Pump Import parameter mode is:

C:\> impdp SYSTEM DUMPFILE=myexp.dmp FULL=y LOG=myexp.log
Password: password

The syntax for Data Pump Import interactive mode is:

C:\> impdp SYSTEM 
Password: password

Enter only impdp SYSTEM to begin an interactive session and let Data Pump Import prompt you for information it needs.

Note:

  • If you use the parameter mode, then Data Pump Import considers the file names and the directory names to be invalid if they contain one or more blank spaces. The workaround is to enclose the full path in the DUMPFILE= parameter in triple quotation marks. For example:

    DUMPFILE="""C:\program files\export.dmp"""

    If you use Data Pump Import in an interactive mode, then the file name or the directory name can contain a space without the quotation marks.

  • If the original database from which the export file was generated contains a tablespace that is not in the new database, then Import tries to create that tablespace with associated data files.

    The easy solution is to ensure that both the databases contain the same tablespaces. Data files are not required to be identical. Only the tablespace names are important.

See Also:

Oracle Database Utilities for more information about using Data Pump Import or Import

Updating ORACLE_SID in the Registry

If this is the first database on your computer or if you intend to make the new database the default database, then you must make a change in the registry.

Perform the following steps:

  1. Start Registry Editor at the command prompt:
    C:\> regedit

    The Registry Editor window appears.

  2. Select the subkey \HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME0 for the first Oracle home on your computer. For subsequent installations to different Oracle homes on the same computer, the path is \HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEID where ID is the unique number identifying the Oracle home.
  3. Locate the parameter ORACLE_SID on the right side of the Registry Editor window.
  4. Double-click the parameter name and change the data to the new SID, which is prod in this example.

Creating the ORACLE_SID Parameter

If you do not yet have the parameter ORACLE_SID, because this is the first database on your system, then you must create it.

To create the parameter ORACLE_SID:

  1. Select New from the Edit menu.
  2. Select Expandable String Value from the menu list.
  3. A New Value #1 expandable string value name is created on the right pane of the Registry Editor window of data type REG_EXPAND_SZ.
  4. Right-click the parameter, select Rename to rename it to ORACLE_SID and press Enter.
  5. Double-click the ORACLE_SID entry to change the value data to the new SID.

    An Edit String dialog box appears:

  6. Enter PROD in the Value data field.
  7. Click OK.

    Registry Editor adds parameter ORACLE_SID.

  8. Select Exit from the File menu.

    Registry Editor exits.

Backing Up the New Database

Use this procedure to prevent data loss.

Note:

If anything goes wrong while operating the new database without a backup, then you must repeat the database creation procedure. Back up your database now to prevent loss of data.

To back up the new database:

  1. Shut down the database instance and stop the service:
    C:\> oradim -SHUTDOWN -SID prod -SHUTTYPE srvc,inst -SHUTMODE immediate

    Note:

    Although ORADIM returns the prompt immediately, you must wait for the database and the service to stop completely before continuing to Step 2. Wait until the Control Panel indicates service OracleServicePROD has stopped. If you do not do this, then the backup is useless because it was taken while data was being written to data files.

  2. Back up database files using the tool of your choice.

    Database files consist of the initialization parameter file, control files, online redo log files, and data files.

    When the backup is complete, you can start the database again, create users and objects, if necessary, make any other changes, and use the database.

    Back up the database after making any significant changes, such as switching into the archiving mode or adding a tablespace or a data file.

Note:

Do not store database files on a compressed drive. This can result in write errors and a decreased performance.