Skip Headers

Oracle9i SQL Reference
Release 2 (9.2)

Part Number A96540-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page Go to next page
View PDF

CREATE DATABASE


Caution:

This statement prepares a database for initial use and erases any data currently in the specified files. Use this statement only when you understand its ramifications.



Note Regarding Security Enhancements:

In this release of Oracle and in subsequent releases, several enhancements are being made to ensure the security of default database user accounts.

To provide guidance for configuring Oracle9i in a secure manner, Oracle Corporation provides a security checklist. Oracle Corporation recommends that you read this checklist and configure your database accordingly. The security checklist can be found at the following URL:

http://otn.oracle.com/deploy/security/oracle9i/pdf/9iR2_checklist.pdf


Purpose

Use the CREATE DATABASE statement to create a database, making it available for general use.

This statement erases all data in any specified datafiles that already exist in order to prepare them for initial database use. If you use the statement on an existing database, all data in the datafiles is lost.

After creating the database, this statement mounts it in either exclusive or parallel mode (depending on the value of the CLUSTER_DATABASE initialization parameter) and opens it, making it available for normal use. You can then create tablespaces and rollback segments for the database.

See Also:

Prerequisites

To create a database, you must have the SYSDBA system privilege.

If the REMOTE_LOGIN_PASSWORDFILE initialization parameter is set to EXCLUSIVE, Oracle returns an error when you attempt to re-create the database. To avoid this message, either set the parameter to SHARED, or re-create your password file before re-creating the database.

See Also:

Oracle9i Database Reference for more information about the REMOTE_LOGIN_PASSWORDFILE parameter

Syntax

create_database::=

Text description of statements_546a.gif follows
Text description of create_database


(redo_log_file_spec::=, datafile_tempfile_spec::=, default_temp_tablespace::=, undo_tablespace_clause::=, set_time_zone_clause::=)

default_temp_tablespace::=

Text description of statements_58.gif follows
Text description of default_temp_tablespace


(datafile_tempfile_spec::=--part of file_specification)

temp_tablespace_extent::=

Text description of statements_545.gif follows
Text description of temp_tablespace_extent


undo_tablespace_clause::=

Text description of statements_546.gif follows
Text description of undo_tablespace_clause


(datafile_tempfile_spec::=--part of file_specification)

set_time_zone_clause::=

Text description of statements_56.gif follows
Text description of set_time_zone_clause


Keyword and Parameters

database

Specify the name of the database to be created. The name can be up to 8 bytes long. The database name can contain only ASCII characters. Oracle writes this name into the control file. If you subsequently issue an ALTER DATABASE statement that explicitly specifies a database name, Oracle verifies that name with the name in the control file.


Note:

You cannot use special characters from European or Asian character sets in a database name. For example, characters with umlauts are not allowed.


If you omit the database name from a CREATE DATABASE statement, Oracle uses the name specified by the initialization parameter DB_NAME. If the DB_NAME initialization parameter has been set, and you specify a different name from the value of that parameter, Oracle returns an error.

See Also:

"Schema Object Naming Guidelines" for additional rules to which database names should adhere

USER SYS ..., USER SYSTEM ...

Use these clauses to establish passwords for the SYS and SYSTEM users. These clauses are not mandatory in this release of Oracle9i. However, if you specify either clause, you must specify both clauses.

If you do not specify these clauses, Oracle creates default passwords "change_on_install" for user SYS and "manager" for user SYSTEM. You can subsequently change these passwords using the ALTER USER statement. You can also use ALTER USER to add password management attributes after database creation.

See Also:

ALTER USER

CONTROLFILE REUSE Clause

Specify CONTROLFILE REUSE to reuse existing control files identified by the initialization parameter CONTROL_FILES, thus ignoring and overwriting any information they currently contain. Normally you use this clause only when you are re-creating a database, rather than creating one for the first time. You cannot use this clause if you also specify a parameter value that requires that the control file be larger than the existing files. These parameters are MAXLOGFILES, MAXLOGMEMBERS, MAXLOGHISTORY, MAXDATAFILES, and MAXINSTANCES.

If you omit this clause and any of the files specified by CONTROL_FILES already exist, Oracle returns an error.

LOGFILE Clause

Specify one or more files to be used as redo log files. Each redo_log_file_spec specifies a redo log file group containing one or more redo log file members (copies). All redo log files specified in a CREATE DATABASE statement are added to redo log thread number 1.

See Also:

file_specification for a full description

GROUP integer

Specify the number that identifies the redo log file group. The value of integer can range from 1 to the value of the MAXLOGFILES parameter. A database must have at least two redo log file groups. You cannot specify multiple redo log file groups having the same GROUP value. If you omit this parameter, Oracle generates its value automatically. You can examine the GROUP value for a redo log file group through the dynamic performance view V$LOG.

If you omit the LOGFILE clause:

MAXLOGFILES Clause

Specify the maximum number of redo log file groups that can ever be created for the database. Oracle uses this value to determine how much space in the control file to allocate for the names of redo log files. The default, minimum, and maximum values depend on your operating system.

MAXLOGMEMBERS Clause

Specify the maximum number of members, or copies, for a redo log file group. Oracle uses this value to determine how much space in the control file to allocate for the names of redo log files. The minimum value is 1. The maximum and default values depend on your operating system.

MAXLOGHISTORY Clause

This parameter is useful only if you are using Oracle in ARCHIVELOG mode with Real Application Clusters. Specify the maximum number of archived redo log files for automatic media recovery Real Application Clusters. Oracle uses this value to determine how much space in the control file to allocate for the names of archived redo log files. The minimum value is 0. The default value is a multiple of the MAXINSTANCES value and depends on your operating system. The maximum value is limited only by the maximum size of the control file.

MAXDATAFILES Clause

Specify the initial sizing of the datafiles section of the control file at CREATE DATABASE or CREATE CONTROLFILE time. An attempt to add a file whose number is greater than MAXDATAFILES, but less than or equal to DB_FILES, causes the Oracle control file to expand automatically so that the datafiles section can accommodate more files.

The number of datafiles accessible to your instance is also limited by the initialization parameter DB_FILES.

MAXINSTANCES Clause

Specify the maximum number of instances that can simultaneously have this database mounted and open. This value takes precedence over the value of initialization parameter INSTANCES. The minimum value is 1. The maximum and default values depend on your operating system.

ARCHIVELOG | NOARCHIVELOG

ARCHIVELOG

Specify ARCHIVELOG if you want the contents of a redo log file group to be archived before the group can be reused. This clause prepares for the possibility of media recovery.

NOARCHIVELOG

Specify NOARCHIVELOG if the contents of a redo log file group need not be archived before the group can be reused. This clause does not allow for the possibility of media recovery.

The default is NOARCHIVELOG mode. After creating the database, you can change between ARCHIVELOG mode and NOARCHIVELOG mode with the ALTER DATABASE statement.

FORCE LOGGING

Use this clause to put the database into FORCE LOGGING mode. Oracle will log all changes in the database except for changes in temporary tablespaces and temporary segments. This setting takes precedence over and is independent of any NOLOGGING or FORCE LOGGING settings you specify for individual tablespaces and any NOLOGGING settings you specify for individual database objects.

FORCE LOGGING mode is persistent across instances of the database. That is, if you shut down and restart the database, the database is still in FORCE LOGGING mode. However, if you re-create the control file, Oracle will take the database out of FORCE LOGGING mode unless you specify FORCE LOGGING in the CREATE CONTROLFILE statement.


Note:

FORCE LOGGING mode can have performance effects. Please refer to Oracle9i Database Administrator's Guide for information on when to use this setting.


See Also:

CREATE CONTROLFILE

CHARACTER SET Clause

Specify the character set the database uses to store data. The supported character sets and default value of this parameter depend on your operating system.

Restriction on CHARACTER SET

You cannot specify the AL16UTF16 character set as the database character set.

See Also:

Oracle9i Database Globalization Support Guide for more information about choosing a character set

NATIONAL CHARACTER SET Clause

Specify the national character set used to store data in columns specifically defined as NCHAR, NCLOB, or NVARCHAR2 (either AF16UTF16 or UTF8). The default is 'AL16UTF16'.

See Also:

Oracle9i Database Globalization Support Guide for information on Unicode datatype support.

DATAFILE Clause

Specify one or more files to be used as datafiles. All these files become part of the SYSTEM tablespace.


Caution:

This clause is optional, as is the DATAFILE clause of the undo_tablespace_clause. Therefore, to avoid ambiguity, if your intention is to specify a datafile for the SYSTEM tablespace with this clause, do not specify it immediately after an undo_tablespace_clause that does not include the optional DATAFILE clause. If you do so, Oracle will interpret the DATAFILE clause to be part of the undo_tablespace_clause.


If you are running the database in automatic undo mode and you specify a datafile name for the SYSTEM tablespace, then Oracle expects to generate datafiles for all tablespaces. Oracle does this automatically if you are using Oracle-managed files (that is, you have set values for the DB_CREATE_FILE_DEST or DB_CREATE_ONLINE_LOG_DEST_n initialization parameter). However, if you are not using Oracle-managed files and you specify this clause, then you must also specify the undo_tablespace_clause and the default_temp_tablespace clause.

If you omit this clause:

EXTENT MANAGEMENT LOCAL

Use this clause to create a locally managed SYSTEM tablespace. If you omit this clause, the SYSTEM tablespace will be dictionary managed.


Caution:

Once you create a locally managed SYSTEM tablespace, you cannot change it to be dictionary managed, nor can you create any other dictionary-managed tablespaces in this database.


If you specify this clause, the database must have a default temporary tablespace, because a locally managed SYSTEM tablespace cannot store temporary segments.

If you have opened the instance in Automatic Undo Management mode, similar requirements exist for the database undo tablespace:

default_temp_tablespace

Specify this clause to create a default temporary tablespace for the database. Oracle will assign to this temporary tablespace any users for whom you do not specify a different temporary tablespace. If you do not specify this clause, the SYSTEM tablespace is the default temporary tablespace.

The TEMPFILE clause part of this clause is optional if you have enabled Oracle-managed files by setting the DB_CREATE_FILE_DEST initialization parameter. If you have not specified a value for this parameter, the TEMPFILE clause is required.


Note:

On some operating systems, Oracle does not allocate space for the tempfile until the tempfile blocks are actually accessed. This delay in space allocation results in faster creation and resizing of tempfiles, but it requires that sufficient disk space is available when the tempfiles are later used. To avoid potential problems, before you create or resize a tempfile, ensure that the available disk space exceeds the size of the new tempfile or the increased size of a resized tempfile. The excess space should allow for anticipated increases in disk space use by unrelated operations as well. Then proceed with the creation or resizing operation.


Restrictions on Default Temporary Tablespaces

The temp_tablespace_extent clause lets you specify how the tablespace is managed.

EXTENT MANAGEMENT LOCAL

This clause indicates that some part of the tablespace is set aside for a bitmap. All temporary tablespaces have locally managed extents, so this clause is optional.

UNIFORM integer

Specify the size of the extents of the temporary tablespace in bytes. All extents of temporary tablespaces are the same size (uniform). If you do not specify this clause, Oracle uses uniform extents of 1M.

SIZE integer

Specify in bytes the size of the tablespace extents. Use K or M to specify the size in kilobytes or megabytes.

If you do not specify SIZE, Oracle uses the default extent size of 1M.

See Also:

Oracle9i Database Concepts for a discussion of locally managed tablespaces

undo_tablespace_clause

If you have opened the instance in automatic undo mode (that is, the UNDO_MANAGEMENT initialization parameter is set to AUTO), you can specify the undo_tablespace_clause to create a tablespace to be used for undo data. If you want undo space management to be handled by way of rollback segments, omit this clause. You can also omit this clause if you have set a value for the UNDO_TABLESPACE initialization parameter. If that parameter has been set, and if you specify this clause, then tablespace must be the same as that parameter value.

The DATAFILE clause part of this clause is optional if you have enabled Oracle-managed files by setting the DB_CREATE_FILE_DEST initialization parameter. If you have not specified a value for this parameter, the DATAFILE clause is required.

set_time_zone_clause

Use the SET TIME_ZONE clause to set the time zone of the database. You can specify the time zone in two ways:

Oracle normalizes all TIMESTAMP WITH LOCAL TIME ZONE data to the time zone of the database when the data is stored on disk. If you do not specify the SET TIME_ZONE clause, Oracle uses the operating system's time zone of the server. If the operating system time zone is not a valid Oracle time zone, the database time zone defaults to UTC.

Examples

Creating a Database: Example

The following statement creates a database and fully specifies each argument:

CREATE DATABASE sample
   CONTROLFILE REUSE 
   LOGFILE
      GROUP 1 ('diskx:log1.log', 'disky:log1.log') SIZE 50K, 
      GROUP 2 ('diskx:log2.log', 'disky:log2.log') SIZE 50K 
   MAXLOGFILES 5 
   MAXLOGHISTORY 100 
   MAXDATAFILES 10 
   MAXINSTANCES 2 
   ARCHIVELOG 
   CHARACTER SET AL32UTF8
   NATIONAL CHARACTER SET AL16UTF16
   DATAFILE  
      'disk1:df1.dbf' AUTOEXTEND ON,
      'disk2:df2.dbf' AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
   DEFAULT TEMPORARY TABLESPACE temp_ts
   UNDO TABLESPACE undo_ts 
   SET TIME_ZONE = '+02:00';

This example assumes that you have enabled Oracle-managed files by specifying a value for the DB_CREATE_FILE_DEST parameter in your initialization parameter file. Therefore no file specification is needed for the DEFAULT TEMPORARY TABLESPACE and UNDO TABLESPACE clauses.