Windows下Oracle建立數據庫的3種方式

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

 

1.1 Creating a Database with Interactive DBCA

 

 

1.2  Creating a Database with Noninteractive/Silent DBCA

 

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

dbca -silent -createDatabase-templateName General_Purpose.dbcshell

-gdbname ora11g -sidora11g -responseFile NO_VALUE -characterSet AL32UTF8數據庫

-memoryPercentage 30-emConfiguration LOCALoracle

Enter SYSTEM userpassword:app

passworddom

Enter SYS userpassword:ide

passwordui

Copying database filesthis

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

 

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.

 

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.

 

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'

 

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.

 

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.

 

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.

 

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.

 

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;

 

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:

 

Step 12: (Optional) Run Scripts toInstall Additional Options

Step 13: Back Up the Database.

Step 14: (Optional) EnableAutomatic Instance Startup

 

That's all!

相關文章
相關標籤/搜索