Windows下Oracle创建数据库的3种方式

时间:2021-10-08 23:28:59

1.   Creating a Database with DBCA

DatabaseConfiguration Assistant (DBCA) is the preferred way to create a database,because it is a more automated approach, and your database is ready to use whenDBCA completes. DBCA can be launched by the Oracle Universal Installer (OUI),depending upon the type of install that you select. You can also launch DBCA asa standalone tool at any time after Oracle Database installation. You can runDBCA in interactive mode or noninteractive/silent mode. Interactivemodeprovides a graphical interface and guided workflow for creating and configuringa database. Noninteractive/silent mode enables you to script database creation.You can run DBCA in noninteractive/silent mode by specifying command-linearguments, a response file, or both.

1.1 Creating a Database with Interactive DBCA

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式

1.2  Creating a Database with Noninteractive/Silent DBCA

The following examplecreates a database by passing command-line arguments to DBCA:

dbca -silent -createDatabase-templateName General_Purpose.dbc

-gdbname ora11g -sidora11g -responseFile NO_VALUE -characterSet AL32UTF8

-memoryPercentage 30-emConfiguration LOCAL

Enter SYSTEM userpassword:

password

Enter SYS userpassword:

password

Copying database files

1% complete

3% complete

...

To ensure completely silent operation, you can redirect stdout to a file.In this case, however, you must supply passwords for the administrativeaccounts in command-line arguments or the response file.

To view brief help for DBCA command-line arguments, enter the followingcommand:

dbca -help

For more detailed argument information, including defaults, view theresponse file template found on your distribution media. Appendix A of yourplatform installation guide provides the name and location of this file.

dbca -help

dbca  [-silent | -progressOnly |-customCreate] {<command> <options> }  | { [<command> [options] ]-responseFile  <response file > }[-continueOnNonFatalErrors <true | false>]

有关详细信息, 请参阅手册。

可以输入以下命令之一:

通过指定以下参数创建数据库:

-createDatabase

-templateName <默认位置或完整模板路径中现有模板的名称>

[-cloneTemplate]

-gdbName <全局数据库名>

[-sid <数据库系统标识符>]

[-sysPassword <SYS 用户口令>]

[-systemPassword <SYSTEM 用户口令>]

[-emConfiguration <CENTRAL|LOCAL|ALL|NONE>

-dbsnmpPassword <DBSNMP 用户口令>

-sysmanPassword <SYSMAN 用户口令>

[-hostUserName <EM 备份作业的主机用户名>

-hostUserPassword <EM 备份作业的主机用户口令>

-backupSchedule <使用 hh:mm 格式的每日备份计划>]

[-centralAgent <Enterprise Manager *代理主目录>]]

[-disableSecurityConfiguration <ALL|AUDIT|PASSWORD_PROFILE|NONE>

[-datafileDestination <所有数据库文件的目标目录> |  -datafileNames <含有诸如控制文件, 表空间, 重做日志文件数据库对象以及按 name=value 格式与这些对象相对应的裸设备文件名映射的 spfile 的文本文件。>]

[-redoLogFileSize <每个重做日志文件的大小 (MB)>]

[-recoveryAreaDestination <所有恢复文件的目标目录>]

[-datafileJarLocation  <数据文件 jar 的位置, 只用于克隆数据库的创建>]

[-storageType < FS | ASM >

[-asmsnmpPassword     <用于 ASM 监视的 ASMSNMP 口令>]

-diskGroupName   <数据库区磁盘组名>

-recoveryGroupName       <恢复区磁盘组名>

[-characterSet <数据库的字符集>]

[-nationalCharacterSet  <数据库的国家字符集>]

[-registerWithDirService <true | false>

-dirServiceUserName    <目录服务的用户名>

-dirServicePassword    <目录服务的口令>

-walletPassword    <数据库 Wallet 的口令>]

[-listeners  <监听程序列表, 该列表用于配置具有如下对象的数据库>]

[-variablesFile   <用于模板中成对变量和值的文件名>]]

[-variables  <以逗号分隔的name=value 对列表>]

[-initParams <以逗号分隔的 name=value 对列表>]

[-sampleSchema  <true |false> ]

[-memoryPercentage <用于 Oracle 的物理内存百分比>]

[-automaticMemoryManagement ]

[-totalMemory <为 Oracle 分配的内存(MB)>]

[-databaseType <MULTIPURPOSE|DATA_WAREHOUSING|OLTP>]]

通过指定以下参数来配置数据库:

-configureDatabase

-sourceDB    <源数据库 sid>

[-sysDBAUserName     <用户名 (具有 SYSDBA 权限)>

-sysDBAPassword     <sysDBAUserName 用户名的口令>]

[-registerWithDirService|-unregisterWithDirService|-regenerateDBPassword<true | false>

-dirServiceUserName    <目录服务的用户名>

-dirServicePassword    <目录服务的口令>

-walletPassword    <数据库 Wallet 的口令>]

[-disableSecurityConfiguration<ALL|AUDIT|PASSWORD_PROFILE|NONE>

[-enableSecurityConfiguration<true|false>

[-emConfiguration<CENTRAL|LOCAL|ALL|NONE>

-dbsnmpPassword <DBSNMP 用户口令>

-sysmanPassword <SYSMAN 用户口令>

[-hostUserName <EM 备份作业的主机用户名>

-hostUserPassword <EM 备份作业的主机用户口令>

-backupSchedule <使用 hh:mm 格式的每日备份计划>]

[-centralAgent <EnterpriseManager *代理主目录>]]

通过指定以下参数使用现有数据库创建模板

-createTemplateFromDB

-sourceDB    <服务采用<host>:<port>:<sid> 格式>

-templateName      <新的模板名>

-sysDBAUserName     <用户名 (具有 SYSDBA 权限)>

-sysDBAPassword     <sysDBAUserName 用户名的口令>

[-maintainFileLocations<true | false>]

通过指定以下参数使用现有数据库创建克隆模板:

-createCloneTemplate

-sourceSID    <源数据库 sid>

-templateName      <新的模板名>

[-sysDBAUserName     <用户名 (具有 SYSDBA 权限)>

-sysDBAPassword     <sysDBAUserName 用户名的口令>]

[-maintainFileLocations<true | false>]

[-datafileJarLocation       <存放压缩格式数据文件的目录>]

通过指定以下参数生成脚本以创建数据库:

-generateScripts

-templateName <默认位置或完整模板路径中现有模板的名称>

-gdbName <全局数据库名>

[-scriptDest       <所有脚本文件的目标位置>]

通过指定以下参数删除数据库:

-deleteDatabase

-sourceDB    <源数据库 sid>

[-sysDBAUserName     <用户名 (具有 SYSDBA 权限)>

-sysDBAPassword     <sysDBAUserName 用户名的口令>]

通过指定以下选项来查询帮助: -h | -help

2. Creating a Database with the CREATE DATABASE Statement

Using the CREATE DATABASE SQL statement is amore manual approach to creating a database. One advantage of using thisstatement over using DBCA is that you can create databases from within scripts.If you use the CREATE DATABASE statement, you mustcomplete additional actions before you have an operational database. Theseactions include building views on the data dictionary tables and installingstandard PL/SQL packages. You perform these actions by running the suppliedscripts.

If you have existing scripts for creating your database, consider editingthose scripts to take advantage of new Oracle Database features. Theinstructions in this section apply to single-instance installations only. See the Oracle RealApplication Clusters (Oracle RAC) installation guide for your platform for instructionsfor creating an Oracle RAC database.

Step 1: Specify an InstanceIdentifier (SID)

Thefollowing example for UNIX and Linux operating systems sets the SID for theinstancethat you will connect to in Step 6: Connect to the Instance:

1.Bourne, Bash, orKorn shell:

ORACLE_SID=mynewdb

export ORACLE_SID

2.C shell:

setenv ORACLE_SID mynewdb

The following examplesets the SID for the Windows operating system:

set ORACLE_SID=mynewdb

Windows下Oracle创建数据库的3种方式

Step 2: Ensure That the RequiredEnvironment Variables Are Set

Depending on your platform, before you can start SQL*Plus(as required in Step 6: Connect to the Instance), you may have to setenvironment variables, or at least verify that they are set properly. Forexample, on most platforms, ORACLE_SID and ORACLE_HOME must be set. In addition, it is advisable to set the PATH variable to include the ORACLE_HOME/bin directory.On the UNIX and Linux platforms, you must set these environment variablesmanually. On the Windows platform, OUI automatically assigns values to ORACLE_HOME and ORACLE_SID in the Windows registry. Ifyou did not create a database upon installation, OUI does not set ORACLE_SID in the registry, and you willhave to set the ORACLE_SIDenvironmentvariable when you create your database later.

Step 3: Choose a DatabaseAdministrator Authentication Method

You must be authenticated and granted appropriate system privileges inorder to create a database. You can be authenticated as an administrator withthe required privileges in the following ways:

■ With a password file

■ With operating system authentication

In this step, you decide on an authentication method.

To be authenticated with a password file, create thepassword file as described in "Creating and Maintaining a PasswordFile" on page 1-22. To be authenticated with operating systemauthentication, ensure that you log in to the host computer with a user accountthat is a member of the appropriate operating system user group. On the UNIXand Linux platforms, for example, this is typically the dba user group. On the Windowsplatform, the user installing the Oracle software is automatically placed in therequired user group.

ORAPWD FILE=filename [ENTRIES=numusers][FORCE={Y|N}] [IGNORECASE={Y|N}]

Step 4: Create the InitializationParameter File

When an Oracle instance starts, it reads aninitialization parameter file. This file can be a text file, which can becreated and modified with a text editor, or a binary file, which is created anddynamically modified by the database. The binary file, which is preferred, iscalled a serverparameter file. In this step, you create a text initialization parameterfile. In a later step, you create a server parameter file from the text file.One way to create the text initialization parameter file is to edit the samplepresented in "Sample Initialization Parameter File" on page 2-26.  If you create the initialization parameterfile manually, ensure that it contains at least the parameters listed in Table2–2. All other parameters not listed have default values.

Windows下Oracle创建数据库的3种方式

For convenience, store your initialization parameter file in the OracleDatabase default location, using the default file name. Then when you startyour database, it will not be necessary to specify the PFILE clause of the STARTUPcommand, becauseOracle Database automatically looks in the default location for theinitialization parameter file.

Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式

Csong.__db_cache_size=1845493760

Csong.__java_pool_size=16777216

Csong.__large_pool_size=33554432

Csong.__oracle_base='D:\app\Csong'#ORACLE_BASEset from environment

Csong.__pga_aggregate_target=822083584

Csong.__sga_target=2449473536

Csong.__shared_io_pool_size=0

Csong.__shared_pool_size=503316480

Csong.__streams_pool_size=16777216

*.audit_file_dest='D:\app\Csong\admin\Csong\adump'

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='D:\app\Csong\oradata\Csong\control01.ctl','D:\app\Csong\fast_recovery_area\Csong\control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='Csong'

*.db_recovery_file_dest='D:\app\Csong\fast_recovery_area'

*.db_recovery_file_dest_size=4385144832

*.diagnostic_dest='D:\app\Csong'

*.dispatchers='(PROTOCOL=TCP)(SERVICE=CsongXDB)'

*.local_listener='LISTENER_Csong'

*.nls_language='SIMPLIFIEDCHINESE'

*.nls_territory='CHINA'

*.open_cursors=300

*.pga_aggregate_target=812646400

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=2438987776

*.undo_tablespace='UNDOTBS1'

Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式

Step 5: (Windows Only) Create anInstance

On the Windows platform, before you can connect to an instance, you mustmanually create it if it does not already exist. The ORADIM command creates an Oracle instance by creating a newWindows service.

To create an instance:

■ Enter the following command at a Windows command prompt:

oradim -NEW -SID sid -STARTMODE MANUAL -PFILE pfile

where sid is the desired SID(for example mynewdb) and pfile is the full path to the textinitialization parameter file. This command creates the instance but does notstart it.

Caution: Do not set the -STARTMODEargument to AUTO at this point, because this causes the new instance tostart and attempt to mount the database, which does not exist yet. You canchange this parameter to AUTO, if desired, in Step14.

Windows下Oracle创建数据库的3种方式

Start SQL*Plus and connect to your Oracle Database instance with the SYSDBA system

privilege.

■ To authenticate with a password file, enter the followingcommands, and then

enter the SYS password whenprompted:

$ sqlplus /nolog

SQL> CONNECT SYSAS SYSDBA

■ To authenticate with operating system authentication,enter the following

commands:

$ sqlplus /nolog

SQL> CONNECT / ASSYSDBA

SQL*Plus outputs the following message:

Connected to an idleinstance.

Windows下Oracle创建数据库的3种方式

Note: SQL*Plus may output a message similar to the following:

Connected to:

Oracle Database 11gEnterprise Edition Release 11.2.0.1.0 - Production

With thePartitioning, OLAP and Data Mining options

If so, the instance is already started. You may have connected to thewrong instance. Exit SQL*Plus with the EXIT command, check that ORACLE_SID is set properly, and repeat this step.

Step 7: Create a Server ParameterFile

The server parameter file enables you to change initialization parameterswith the ALTER SYSTEM command and persistthe changes across a database shutdown and startup. You create the serverparameter file from your edited text initialization file.

The following SQL*Plus command reads the text initialization parameterfile (PFILE) with the default name from the default location, creates a serverparameter file (SPFILE) from the text initialization parameter file, and writesthe SPFILE to the default location with the default SPFILE name.

CREATE SPFILE FROMPFILE;

You can also supply the file name and path for both the PFILE and SPFILEif you are not using default names and locations.

Tip: The database must be restarted before the serverparameter file takes effect.

Note: Although creating a serverparameter file is optional at this point, it is recommended. If you do notcreate a server parameter file, the instance continues to read the textinitialization parameter file

whenever it starts.

Important—If you are using OracleManaged Files and your initialization parameter file does not contain the CONTROL_FILES parameter,then you must create a server parameter file now so the database can save thenames and location of the control files that it creates during the CREATE DATABASE statement. See "SpecifyingOracle Managed Files at Database Creation" on page 2-19 for more information.

Windows下Oracle创建数据库的3种方式

Step 8: Start the Instance

Start an instance without mounting a database. Typically, you do this onlyduring database creation or while performing maintenance on the database. Usethe STARTUP command with the NOMOUNT clause. In this example, because the initialization parameterfile or server parameter file is stored in the default location, you are not requiredto specify the PFILE clause:

STARTUP NOMOUNT

At this point, the instance memory is allocated and its processes arestarted. The database itself does not yet exist.

Windows下Oracle创建数据库的3种方式

Step 9: Issue the CREATE DATABASEStatement

To create the newdatabase, use the CREATE DATABASE statement.

Example 1

The following statement creates database mynewdb. This database name must agree with the DB_NAME parameter in the initialization parameter file. Thisexample assumes the following:

■ The initialization parameter file specifies the numberand location of control files with the CONTROL_FILES parameter.

■ The directory /u01/app/oracle/oradata/mynewdbexists.

■ The directories /u01/logs/myand /u02/logs/my exist.

CREATE DATABASE Csong

USER SYS IDENTIFIEDBY sys

USER SYSTEMIDENTIFIED BY sys

LOGFILE GROUP 1('D:\app\Csong\oradata\Csong\redo01a.log') SIZE 100M BLOCKSIZE 512,

GROUP 2('D:\app\Csong\oradata\Csong\redo02a.log') SIZE 100M BLOCKSIZE 512,

GROUP 3('D:\app\Csong\oradata\Csong\redo03a.log') SIZE 100M BLOCKSIZE 512

MAXLOGFILES 32

MAXLOGMEMBERS 5

MAXLOGHISTORY 1

MAXDATAFILES 100

CHARACTER SETAL32UTF8

NATIONAL CHARACTERSET AL16UTF16

EXTENT MANAGEMENTLOCAL

DATAFILE'D:\app\Csong\oradata\Csong\system01.dbf' SIZE 325M REUSE

SYSAUX DATAFILE'D:\app\Csong\oradata\Csong\sysaux01.dbf' SIZE 325M REUSE

DEFAULT TABLESPACEusers

DATAFILE'D:\app\Csong\oradata\Csong\users01.dbf'

SIZE 500M REUSEAUTOEXTEND ON MAXSIZE UNLIMITED

DEFAULT TEMPORARYTABLESPACE tempts1

TEMPFILE'D:\app\Csong\oradata\Csong\temp01.dbf'

SIZE 20M REUSE

UNDO TABLESPACEundotbs1

DATAFILE'D:\app\Csong\oradata\Csong\undotbs01.dbf'

SIZE 200M REUSEAUTOEXTEND ON MAXSIZE UNLIMITED;

Windows下Oracle创建数据库的3种方式

Windows下Oracle创建数据库的3种方式

Example 2

This example illustrates creating a database with Oracle Managed Files,which enables you to use a much simpler CREATE DATABASE statement. To use Oracle Managed Files, theinitialization parameter DB_CREATE_FILE_DESTmust be set. Thisparameter defines the base directory for the various database files that thedatabase creates and automatically names. The following statement is an exampleof setting this parameter in the initialization parameter file:

DB_CREATE_FILE_DEST='/u01/app/oracle/oradata'

With Oracle Managed Files and the following CREATE DATABASE statement, the database creates the SYSTEM and SYSAUX tablespaces, createsthe additional tablespaces specified in the statement, and chooses defaultsizes and properties for all data files, control files, and redo log files.Note that these properties and the other default database properties set bythis method may not be suitable for your production environment, so it isrecommended that you examine the resulting configuration and

modify it if necessary.

CREATE DATABASEmynewdb

USER SYS IDENTIFIEDBY sys_password

USER SYSTEM IDENTIFIEDBY system_password

EXTENT MANAGEMENTLOCAL

DEFAULT TEMPORARYTABLESPACE temp

UNDO TABLESPACEundotbs1

DEFAULT TABLESPACEusers;

Tip: If your CREATE DATABASE statementfails, and if you did not complete Step 7, then ensure that there is not a pre-existingserver parameter file (SPFILE) for this instance that is setting initialization

parameters in an unexpected way. For example, an SPFILEcontains a setting for the complete path to all control files, and the CREATE DATABASE statement fails if thosecontrol files do not exist. Ensure that you shut down and restart the instance(with STARTUP NOMOUNT) after removingan unwanted SPFILE. See "Managing Initialization Parameters Using a ServerParameter File" on page 2-32 for more information.

Step 10: Create AdditionalTablespaces

To make the database functional, you must create additional tablespacesfor your application data. The following sample script creates some additionaltablespaces:

CREATE TABLESPACEapps_tbs LOGGING

DATAFILE '/u01/app/oracle/oradata/mynewdb/apps01.dbf'

SIZE 500M REUSEAUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED

EXTENT MANAGEMENTLOCAL;

-- create atablespace for indexes, separate from user tablespace (optional)

CREATE TABLESPACEindx_tbs LOGGING

DATAFILE'/u01/app/oracle/oradata/mynewdb/indx01.dbf'

SIZE 100M REUSEAUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED

EXTENT MANAGEMENTLOCAL;

Step 11: Run Scripts to Build DataDictionary Views

Run the scripts necessary to build data dictionary views, synonyms, andPL/SQL

packages, and to support proper functioning of SQL*Plus.

In SQL*Plus, connect to your Oracle Database instance with the SYSDBA administrative

privilege:

@?/rdbms/admin/catalog.sql

@?/rdbms/admin/catproc.sql

In SQL*Plus, connect to your Oracle Database instance as SYSTEM user:

@?/sqlplus/admin/pupbld.sql

The at-sign (@) is shorthand forthe command that runs a SQL*Plus script. The question mark (?) is a SQL*Plus variable indicating the Oracle homedirectory. The following table contains descriptions of the scripts:

Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式Windows下Oracle创建数据库的3种方式

Step 12: (Optional) Run Scripts toInstall Additional Options

Step 13: Back Up the Database.

Step 14: (Optional) EnableAutomatic Instance Startup

 

That's all!