11g文档学习2----创建数据库


学习oracle官方之路 ---- 11g Release 2 (11.2)
Oracle Database Administrator's Guide
11g Release 2 (11.2)
E25494-05

Creating and Configuring an Oracle Database

创建数据库有两种方式,其中dbca又分为两种;
(1)Creating a Database with DBCA
  (a)Creating a Database with Interactive DBCA
  (b)Creating a Database with Noninteractive/Silent DBCA
(2)Creating a Database with the CREATE DATABASE Statement
本文档主要学习命令行创建数据库,操作步骤如下:

Step 1: Specify an Instance Identifier (SID)

sid 最长8个字符;部分平台sid区分大小写;
linux/unix平台设置sid的方法,注意不同的语言不同设置方法。
    Bourne, Bash, or Korn shell:
    ORACLE_SID=mynewdb
    export ORACLE_SID

    C shell:
    setenv ORACLE_SID mynewdb

windows平台设置sid的方法
set ORACLE_SID=mynewdb


Step 2: Ensure That the Required Environment Variables Are Set

查看ORACLE_SID和ORACLE_HOME是否设置好;

Step 3: Choose a Database Administrator Authentication Method
选择一种管理员认证方法,
(1)通过密码文件认证;
(2)通过系统认证;


Step 4: Create the Initialization Parameter File

        手动创建的参数至少包括DB_NAME,CONTROL_FILES,MEMORY_TARGET;其他参数不写将会自动使用默认值;
        创建好的参数文件放在默认位置,数据库启动时将自动设别;

创建数据文件存储路径
[root@OL541 u01]# mkdir -p /u02/data
[root@OL541 u02]# mkdir arclog

编辑参数文件:/u01/app/oracle/product/11.2.0/db_1/dbs/pfileorcl.ora,内容如下:
db_name='orcl'
memory_target=900M
control_files = (/u02/data/control1.ctl,/u02/data/control2.ctl,/u02/data/control3.ctl)



Step 5: (Windows Only) Create an Instance

    On the Windows platform, before you can connect to an instance, you must manually create it if it does not already exist. The ORADIM command creates an Oracle instance by creating a new Windows 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 text initialization parameter file. This command creates the instance but does not start it.

    Caution:Do not set the -STARTMODE argument to AUTO at this point, because this causes the new instance to start and attempt to mount the database, which does not exist yet. You can change this parameter to AUTO, if desired, in Step 14.

Step 6: Connect to the Instance

    Start SQL*Plus and connect to your Oracle Database instance with the SYSDBA system privilege.
    To authenticate with a password file, enter the following commands, and then enter the SYS password when prompted:
    $ sqlplus /nolog
    SQL> CONNECT SYS AS SYSDBA

    To authenticate with operating system authentication, enter the following commands:
    $ sqlplus /nolog
    SQL> CONNECT / AS SYSDBA

    SQL*Plus outputs the following message:
    Connected to an idle instance.


Step 7: Create a Server Parameter File

     通过pfile文件创建spfile;创建后重启数据库,数据库将自动读取spfile文件启动;
     CREATE SPFILE FROM PFILE;
     SYS@orcl>create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/pfileorcl.ora';
     
Step 8: Start the Instance

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

        @>conn / as sysdba
        Connected to an idle instance.
        SYS@orcl>startup nomount
        ORACLE instance started.

        Total System Global Area  941600768 bytes
        Fixed Size                  1348860 bytes
        Variable Size             549456644 bytes
        Database Buffers          385875968 bytes
        Redo Buffers                4919296 bytes


Step 9: Issue the CREATE DATABASE Statement

Example 1
编写创建数据库脚本:
 vim create_database.sql
 内容如下:

CREATE DATABASE orcl
   USER SYS IDENTIFIED BY oracle
   USER SYSTEM IDENTIFIED BY oracle
   LOGFILE GROUP 1 ('/u02/data/orcl/redo01.log') SIZE 100M BLOCKSIZE 512,
           GROUP 2 ('/u02/data/orcl/redo02.log') SIZE 100M BLOCKSIZE 512,
           GROUP 3 ('/u02/data/orcl/redo03.log') SIZE 100M BLOCKSIZE 512
   MAXLOGFILES 30
   MAXLOGMEMBERS 5
   MAXLOGHISTORY 1
   MAXDATAFILES 100
   CHARACTER SET AL32UTF8
   NATIONAL CHARACTER SET AL16UTF16
   EXTENT MANAGEMENT LOCAL
   DATAFILE '/u02/data/orcl/system01.dbf' SIZE 450M REUSE
   SYSAUX DATAFILE '/u02/data/orcl/sysaux01.dbf' SIZE 450M REUSE
   DEFAULT TABLESPACE users
      DATAFILE '/u02/data/orcl/users01.dbf'
      SIZE 10M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
   DEFAULT TEMPORARY TABLESPACE temp
      TEMPFILE '/u02/data/orcl/temp01.dbf'
      SIZE 20M REUSE
   UNDO TABLESPACE undotbs
      DATAFILE '/u02/data/orcl/undotbs01.dbf'
      SIZE 20M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

===================================================================
Example 2

pfileorcl.ora 文件中只有db_name='orcl'

create spfile from pfile='/u02/data/orcl/pfileorcl.ora';
退出sql,重进
startup nomount
alter system set db_create_file_dest='/u02/data/orcl' scope=spfile;
重启数据库到mount状态;


创建数据库的脚本如下:
CREATE DATABASE orcl
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
EXTENT MANAGEMENT LOCAL
DEFAULT TEMPORARY TABLESPACE temp
UNDO TABLESPACE undotbs
DEFAULT TABLESPACE users;


Step 10: Create Additional Tablespaces

创建额外的表空间
编写脚本:[oracle@OL541 ~]$ vi create_tbs.sql

CREATE TABLESPACE apps_tbs LOGGING
     DATAFILE '/u02/data/orcl/apps01.dbf'
     SIZE 50M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED
     EXTENT MANAGEMENT LOCAL;
-- create a tablespace for indexes, separate from user tablespace (optional)
CREATE TABLESPACE indx_tbs LOGGING
     DATAFILE '/u02/data/orcl/indx01.dbf'
     SIZE 10M REUSE AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED
     EXTENT MANAGEMENT LOCAL;


Step 11: Run Scripts to Build Data Dictionary Views

Run the scripts necessary to build data dictionary views, synonyms, and PL/SQL packages, and to support proper functioning of SQL*Plus.

conn / as sysdba
@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql

conn system/oracle
@?/sqlplus/admin/pupbld.sql

脚本作用
Script     Description
CATALOG.SQL     Creates the views of the data dictionary tables, the dynamic performance views, and public synonyms for many of the views. Grants PUBLIC access to the synonyms.
CATPROC.SQL     Runs all scripts required for or used with PL/SQL.
PUPBLD.SQL       Required for SQL*Plus. Enables SQL*Plus to disable commands by user.

3个脚本依次执行完成,但发现没有日志输出记录,下次得建一个日志输出;

Step 12: (Optional) Run Scripts to Install Additional Options
创建额外的对象

Step 13: Back Up the Database.
备份数据库
停止数据库,可整个复制一下;

Step 14: (Optional) Enable Automatic Instance Startup

windows下设置允许自动启动
ORADIM -EDIT -SID sid -STARTMODE AUTO -SRVCSTART SYSTEM [-SPFILE]



附录:

1、用户密码问题
    USER SYS IDENTIFIED BY password
    USER SYSTEM IDENTIFIED BY password
这两个选项在创建数据库时不是必须的,但强烈建议使用;
他们默认密码分别是:sys/change_on_install,system/manager

2、local managed tablespace
EXTENT MANAGEMENT LOCAL 指定本选项将使用本地管理方式,同时参数文件中COMPATIBLE必须设置大于10.0.0;
如不指定EXTENT MANAGEMENT LOCAL,将默认使用不推荐的字典管理表空间;


3、关于SYSAUX表空间
        SYSAUX表空间是system的辅助表空间,不可删除或重命名;在创建初始不得小于400M;
    SYSTEM表空间的属性和SYSAUX一样;
    
    
4、关于undo 表空间

创建数据库时不指定undo表空间,系统将自动创建一个名为SYS_UNDOTBS的表空间;
spfile参数中undo_management默认是AUTO,undo_retention默认是900;

5、关于temp表空间;
    如果system表空间采用本地管理模式,system表空间将不能用作为临时表空间;

6、Specifying Oracle Managed Files at Database Creation        
   使用OMF将减少大量创建数据库需要的命令;你只需要指定一个目录或ASM磁盘;
   OMF需在spfile中设置相关的参数如下:DB_CREATE_FILE_DEST, DB_CREATE_ONLINE_LOG_DEST_n, or DB_RECOVERY_FILE_DEST
   OMF可管理的文件:
    Tablespaces and their data files
    Temporary tablespaces and their temp files
    Control files
    Redo log files
    Archived redo log files
    Flashback logs
    Block change tracking files
    RMAN backups

7、大数据文件表空间
   大数据文件表空间只能有一个数据文件,该数据文件可有最多4G blocks;每个数据库最多64K个数据文件;
   
8、表空间类型
   如不指定表空间类型,即SET DEFAULT BIGFILE TABLESPACE or SET DEFAULT SMALLFILE TABLESPACE,则会默认采用smallfile tablespace;    
   
   示例:创建数据库时采用大数据文件表空间;
   CREATE DATABASE mynewdb
     USER SYS IDENTIFIED BY sys_password
     USER SYSTEM IDENTIFIED BY system_password
     SET DEFAULT BIGFILE TABLESPACE
     UNDO TABLESPACE undotbs
     DEFAULT TEMPORARY TABLESPACE tempts1;

        创建数据库后修改默认表空间类型;
        ALTER DATABASE SET DEFAULT BIGFILE TABLESPACE;

        查询当前数据库的表空间默认类型;
    SELECT PROPERTY_VALUE FROM DATABASE_PROPERTIES  WHERE PROPERTY_NAME = 'DEFAULT_TBS_TYPE';
        
        SYSTEM和SYSAUX表空间始终采用默认的表空间类型,但对UNDO和DEFAULT TEMP表空间可特别指定表空间类型;
        
9、关于数据库Time Zone and Time Zone File   
        在创建数据库时如SET TIME_ZONE 可指定数据库时区,如不用则采用操作系统的时区;
        数据库有两个时区文件
        默认时区文件:ORACLE_HOME/oracore/zoneinfo/timezlrg_11.dat.
        小一点的时区文件:ORACLE_HOME/oracore/zoneinfo/timezone_11.dat.
        查询当前数据库使用的时区文件中的时区名:SELECT * FROM V$TIMEZONE_NAMES;        
        
        所有的数据库共享信息必须使用相同的时区数据文件;
        不建议使用小的时区文件;
        
10、Specifying FORCE LOGGING Mode            
     NOLOGGING参数可导致数据库一些操作不写redo,虽然提高效率,但出问题将无法恢复。
     取消数据库强制日志:ALTER DATABASE NO FORCE LOGGING;
     查看当前数据库是否强制日志模式:select  FORCE_LOGGING  from v$database;
     强制日志模式,数据库级别优先于表空间级别;
     oracle建议数据库和表空间不要同时设置成强制日志模式;
     重建控制文件后会丢失强制日志模式,所以在重建控制文件时应指定强制日志模式;
     不使用强制日志模式情况:性能极大降低,对恢复无大要求,没有运行在归档模式下。

11、Specifying Initialization Parameters

        pfile参数只要有DB_NAME就能启动,其他参数会取默认值;
        DB_NAME must be set to a text string of no more than eight characters. During database creation, the name provided for DB_NAME is recorded in the data files, redo log files, and control file of the database. If during database instance startup the value of the DB_NAME parameter (in the parameter file) and the database name in the control file are different, the database does not start.

        Fast Recovery Area,不能使用裸设备;
        控制文件,不指定位置,系统将自动在参数文件目录内创建。
        block size 32K只能用于64-bit平台上。
        PROCESSES 是指允许最多的操作系统进程与oracle 通讯;
        DDL_LOCK_TIMEOUT,默认值是0;To enable DDL statements to wait for locks, specify a DDL lock timeout—the number of seconds a DDL command waits for its required locks before failing.
        COMPATIBLE :控制数据库所能使用的功能;创建库时参数不指定,则使用当前软件版本11.2.0,不能降级;
        license:license_max_sessions和license_max_users可控制数据库用户数和连接量;
        创建spfile:CREATE SPFILE FROM MEMORY; 或create pfile='/u02/data/pfiletmp.ora' from memory;

12、CloneDB
        11.2.0.3开始支持CloneDB;
        
        
13、Dropping a Database        
        删除数据库,将删除控制文件和控制文件中所列的数据文件;不会删除归档日志;
        命令:DROP DATABASE;
        删除数据库操作建议将数据库置于restrict模式;在restrict模式时,不能通过TNS连接,只能管理员在本地连接;
        startup mount restrict
        drop database;
        
        或者:
        startup
        alter database close;
        alter system enable restricted session;
        drop database;
        就是说drop database 必须处于mount restrict模式;
        
        数据库启动
        只读模式:ALTER DATABASE OPEN READ ONLY;
    默认的读写模式:ALTER DATABASE OPEN READ WRITE;
        
14、数据库字典视图        
        View                                         Description
        DATABASE_PROPERTIES     Displays permanent database properties
        GLOBAL_NAME                     Displays the global database name
        V$DATABASE                         Contains database information from the control file

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29519108/viewspace-1426747/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29519108/viewspace-1426747/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值