1. 程式人生 > >Linux 下Oracle 手工create database 指令碼和步驟

Linux 下Oracle 手工create database 指令碼和步驟

原來一直用dbca來建立資料庫,雖然方便,但有些引數就沒有辦法指定 ,所以這次參照網上的資料,整理了一個linux 下手工建立資料庫的指令碼,步驟如下:(只有這樣,才可以批量初始化,建立資料庫,不然就圖形介面的,要大規模的部署,還是有受限制的)

1 設定環境變數 ORACLE_HOME ORACLE_BASE ORACLE_SID
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/dbs
ORACLE_SID=center
PATH=$PATH:$ORACLE_HOME/BIN
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

export ORACLE_BASE ORACLE_HOME ORACEL_SID
export PATH NLS_LANG

2 系統規劃 db_name=center oracle_sid=center
3 手工建立目錄
mkdir -p /u01/app/oracle/admin/center/adump
mkdir -p /u01/app/oracle/admin/center/bdump
mkdir -p /u01/app/oracle/admin/center/cdump
mkdir -p /u01/app/oracle/admin/center/dpdump
mkdir -p /u01/app/oracle/admin/center/pfile
mkdir -p /u01/app/oracle/admin/center/udump

mkdir -p /u02/oradata/center/
mkdir -p /u02/oradata/center/archive


4建立密碼檔案:

orapwd file=/u01/app/oracle/product/10.2.0/db_1/dbs/orapwd_center password=zdsoft

5---修改引數檔案:

例項:/u01/app/oracle/product/10.2.0/dbs/initcenter.ora

---------------------------------------------------

center.__db_cache_size=331350016

center.__java_pool_size=4194304

center.__large_pool_size=8388608

center.__shared_pool_size=138412032

center.__streams_pool_size=0

*._kgl_large_heap_warning_threshold=8388608

*.audit_file_dest='/u01/app/oracle/admin/center/adump'

*.background_dump_dest='/u01/app/oracle/admin/center/bdump'

*.compatible='10.2.0.1.0'

*.control_files='/u01/app/oracle/admin/center/control01.ctl','/u02/oradata/center/control02.ctl','/u02/oradata/center/control03.ctl'

*.core_dump_dest='/u01/app/oracle/admin/center/cdump'

*.db_2k_cache_size=33554432

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=128

*.db_files=4000

*.db_name='center'

*.db_recovery_file_dest_size=4294967296

*.db_recovery_file_dest=''

*.log_archive_dest='/u02/oradata/center/archive'

*.log_checkpoints_to_alert=FALSE

*.open_cursors=300

*.parallel_execution_message_size=65535

*.parallel_max_servers=128

*.pga_aggregate_target=209715200

*.processes=150

*.recyclebin='ON'

*.remote_login_passwordfile='EXCLUSIVE'

*.replication_dependency_tracking=FALSE

*.session_cached_cursors=100

*.sga_target=500m

*.shared_pool_size=100m

*.undo_management='AUTO'

*.undo_retention=0

*.undo_tablespace='UNDOTS'

*.user_dump_dest='/u01/app/oracle/admin/center/udump'

*.workarea_size_policy='AUTO'

_allow_resetlogs_corruption=true

---------------------------------------------------

可將此檔案複製到:/u01/app/oracle/admin/center/pfile/initcenter.ora

6--- 登陸oracle:

> sqlplus / as sysdba

7--- 啟動例項:

SQL> startup nomount pfile=/u01/app/oracle/admin/center/pfile/initcenter.ora

8--- 建立資料庫的指令碼:

-----------------------------------------------------------

CREATE DATABASE center
LOGFILE
GROUP 1 ('/u02/oradata/center/redo01.log','/u02/oradata/center/redo01_1.log') size 500m reuse,
GROUP 2 ('/u02/oradata/center/redo02.log','/u02/oradata/center/redo02_1.log') size 500m reuse,
GROUP 3 ('/u02/oradata/center/redo03.log','/u02/oradata/center/redo03_1.log') size 500m reuse
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXLOGHISTORY 200
MAXDATAFILES 500
MAXINSTANCES 5
ARCHIVELOG
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
DATAFILE '/u02/oradata/center/system01.dbf' SIZE 1000M EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/u02/oradata/center/sysaux01.dbf' SIZE 1000M
UNDO TABLESPACE UNDOTS DATAFILE '/u02/oradata/center/undo.dbf' SIZE 500M
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u02/oradata/center/temp.dbf' SIZE 500M;

-----------------------------------------------------------

9--- 執行如下檔案(安照下面的先後順序):

sql>@$ORACLE_HOME/rdbms/admin/catalog.sql

sql>@$ORACLE_HOME/rdbms/admin/catproc.sql

sql>conn system/manager

sql>@$ORACLE_HOME/sqlplus/admin/pupbld.sql

10--- 建立相關表空間與使用者:

CREATE SMALLFILE TABLESPACE "TBS_NETDISK" DATAFILE '/u02/oradata/center/netdisk01.dbf' SIZE 200M AUTOEXTEND ON NEXT 250M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

CREATE SMALLFILE TABLESPACE "TBS_CENTER" DATAFILE '/u02/oradata/center/center01.dbf' SIZE 200M AUTOEXTEND ON NEXT 250M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

CREATE TABLESPACE TBS_INDX DATAFILE '/u02/oradata/center/indx01.dbf' SIZE 100M;

CREATE USER "ZDCENTER" PROFILE "DEFAULT" IDENTIFIED BY zdsoft DEFAULT TABLESPACE "TBS_CENTER" TEMPORARY TABLESPACE "TEMP" ACCOUNT UNLOCK

GRANT CREATE SESSION,CREATE TABLE,CONNECT,RESOURCE TO "ZDCENTER"

11--- 一點注意的地方:

1>.相關檔案的目錄要設定正確,有資料檔案,控制檔案,引數檔案等,還有就是它們的位置要與控制檔案中指定的要一致。

2>.init.ora中的undo_tablespace的名字必須要與create database的相同,包括大小寫等注意。否則很麻煩,報的錯誤你都不知道是不是在忽悠你!總之,一句話,控制檔案中的內容要和init檔案中的內容以及要和實際檔案的實際情況要相同。

3>.分析資料庫出錯可以到/u01/app/oracle/admin/center/bdump/alert_center.log中查詢。

btw: 刪除使用者和表空間的指令碼

刪除使用者

drop user user_name cascade;

刪除表空間

DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;