Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

CREATE DATABASE

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.

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-23

CREATE DATABASE

See Also:

ALTER DATABASE on page 9-11 for information on modifying a database

Oracle9i Java Developer’s Guide for information on creating an Oracle9i Java virtual machine

CREATE ROLLBACK SEGMENT on page 14-82 and CREATE TABLESPACE on page 15-80 for information on creating rollback segments and tablespaces

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

13-24 Oracle9i SQL Reference

CREATE DATABASE

Syntax

create_database::=

 

 

USER

SYS

IDENTIFIED

BY

 

password

 

 

USER

SYSTEM

IDENTIFIED

BY

password

 

 

CONTROLFILE

REUSE

 

 

 

 

 

 

 

 

 

 

,

 

 

 

 

 

GROUP

integer

 

 

 

 

LOGFILE

 

 

 

 

 

redo_log_file_spec

 

 

MAXLOGFILES

integer

 

 

 

 

 

MAXLOGMEMBERS

integer

 

 

 

 

 

MAXLOGHISTORY

integer

 

 

 

 

 

MAXDATAFILES

integer

 

 

 

 

database

MAXINSTANCES

integer

 

 

 

CREATE

DATABASE

ARCHIVELOG

 

 

 

 

;

 

 

 

 

 

 

 

 

 

NOARCHIVELOG

 

 

 

 

 

 

FORCE

LOGGING

 

 

 

 

 

 

CHARACTER

SET

charset

 

 

 

 

NATIONAL

CHARACTER

SET

charset

 

 

 

 

 

,

 

 

 

 

 

DATAFILE

 

datafile_tempfile_spec

 

 

 

 

EXTENT

MANAGEMENT

LOCAL

 

 

 

 

default_temp_tablespace

 

 

 

 

 

undo_tablespace_clause

 

 

 

 

 

set_time_zone_clause

 

 

 

 

(redo_log_file_spec::= on page 7-40, datafile_tempfile_spec::= on page 7-39, default_temp_tablespace::= on page 13-26, undo_tablespace_ clause::= on page 13-26, set_time_zone_clause::= on page 13-26)

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-25

CREATE DATABASE

default_temp_tablespace::=

TEMPFILE datafile_tempfile_spec

DEFAULT TEMPORARY TABLESPACE tablespace

temp_tablespace_extent_clause

(datafile_tempfile_spec::= on page 7-39—part of file_specification) temp_tablespace_extent::=

K

M

 

 

 

SIZE

integer

EXTENT

MANAGEMENT

LOCAL

UNIFORM

 

undo_tablespace_clause::=

,

DATAFILE datafile_tempfile_spec

UNDO TABLESPACE tablespace

(datafile_tempfile_spec::= on page 7-39—part of file_specification) set_time_zone_clause::=

 

 

 

 

+

 

 

 

 

 

 

hh

:

mi

SET

TIME_ZONE

=

 

 

 

time_zone_region

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.

13-26 Oracle9i SQL Reference

CREATE DATABASE

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" on page 2-114 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 on page 12-22

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

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-27

CREATE DATABASE

(copies). All redo log files specified in a CREATE DATABASE statement are added to redo log thread number 1.

See Also: file_specification on page 7-39 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:

If either the DB_CREATE_ONLINE_LOG_DEST_n or DB_CREATE_FILE_DEST initialization parameter (or both) is set, then Oracle creates two Oraclemanaged logfiles with system-generated names, 100 MB in size, in the default logfile directory specified in the DB_CREATE_ONLINE_LOG_DEST_n parameter, and if it is not set, then in the DB_CREATE_FILE_DEST parameter.

If neither of these parameters is set, Oracle creates two redo log file groups. The names and sizes of the default files depend on your operating system.

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

13-28 Oracle9i SQL Reference

CREATE DATABASE

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.

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-29

CREATE DATABASE

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 on page 13-15

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.

13-30 Oracle9i SQL Reference

CREATE DATABASE

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:

If the DB_CREATE_FILE_DEST initialization parameter is set, Oracle creates a 100 MB Oracle-managed datafile with a system-generated name in the default file destination specified in the parameter.

If the DB_CREATE_FILE_DEST initialization parameter is not set, Oracle creates one datafile whose name and size depend on your operating system.

Note: Oracle recommends that the total initial space allocated for the SYSTEM tablespace be a minimum of 5 megabytes.

See Also: file_specification on page 7-39 for syntax

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.

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-31

CREATE 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 specify EXTENT MANAGEMENT LOCAL but you do not specify the DATAFILE clause, you can omit the default_temp_tablespace clause. Oracle will create a default temporary tablespace called TEMP with one datafile of size 10M with autoextend disabled.

If you specify both EXTENT MANAGEMENT LOCAL and the DATAFILE clause, then you must also specify the default_temp_tablespace clause and explicitly specify a datafile for that tablespace.

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

If you specify EXTENT MANAGEMENT LOCAL but you do not specify the DATAFILE clause, you can omit the undo_tablespace_clause. Oracle will create an undo tablespace named SYS_UNDOTBS.

If you specify both EXTENT MANAGEMENT LOCAL and the DATAFILE clause, then you must also specify the undo_tablespace_clause and explicitly specify a datafile for that tablespace.

See Also: Oracle9i Database Administrator’s Guide for more information on locally managed and dictionary-managed tablespaces

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 Oraclemanaged 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.

13-32 Oracle9i SQL Reference

CREATE DATABASE

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

You cannot specify the SYSTEM tablespace in this clause.

The default temporary tablespace must have a standard block size.

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

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-33

CREATE DATABASE

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 Oraclemanaged 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.

If you specify this clause, Oracle creates an undo tablespace named tablespace, creates the specified datafiles as part of the undo tablespace, and assigns this tablespace as the undo tablespace of the instance. Oracle will handle management of undo data using this undo tablespace. The DATAFILE clause of this clause has the same behavior as described in "DATAFILE Clause" on page 13-30.

Note: If you have specified a value for the UNDO_TABLESPACE initialization parameter in your initialization parameter file before mounting the database, be sure you specify the same name in this clause. If these names differ, Oracle will return an error when you open the database.

If you omit this clause, Oracle creates a default database with a default undo tablespace named SYS_UNDOTBS and assigns this default tablespace as the undo tablespace of the instance. This undo tablespace allocates disk space from the default files used by the CREATE DATABASE statement, and has an initial extent of 10M. Oracle handles the system-generated datafile as described in "DATAFILE Clause" on page 13-30. If Oracle is unable to create the undo tablespace, the entire CREATE DATABASE operation fails.

See Also:

Oracle9i Database Reference for information on opening a database instance in Automatic Undo Management mode using the UNDO_MANAGEMENT parameter

Oracle9i Database Administrator’s Guide for information on Automatic Undo Management and undo tablespaces

CREATE TABLESPACE on page 15-80 for information on creating an undo tablespace after database creation

13-34 Oracle9i SQL Reference

CREATE DATABASE

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:

By specifying a displacement from UTC (Coordinated Universal Time—formerly Greenwich Mean Time). The valid range of hh:mm is -12:00 to +14:00.

By specifying a time zone region. To see a listing of valid region names, query the TZNAME column of the V$TIMEZONE_NAMES dynamic performance view.

Note: Oracle Corporation recommends that you set the database time zone to UTC ("0:00"). Doing so can improve performance, especially across databases, as no conversion of time zones will be required.

See Also: Oracle9i Database Reference for information on the dynamic performance views

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

SQL Statements: CREATE CLUSTER to CREATE JAVA 13-35

CREATE DATABASE

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.

13-36 Oracle9i SQL Reference

Соседние файлы в папке Oracle selected docs