手工建立Oracle資料庫詳解
閱讀導航
資料庫版本:
1.設定環境變數和建立目錄
2.建立初始化參數檔案
3.啟動執行個體到nomount狀態建立資料庫
4.運行指令碼建立字典、視圖、包、角色、許可權、同義字
5.檢查資料庫相關資訊
6.啟用歸檔日誌
資料庫版本:
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
1.設定環境變數和建立目錄
$ export ORACLE_HOME=/u01/app/product/11.2.0/db_1
$ export ORACLE_SID=mandb
$ mkdir -p /disk2/oradata/mandb/datafile
$ mkdir -p /disk2/oradata/mandb/logfile
2.建立初始化參數檔案
$ vim /disk2/oradata/mandb/datafile/mandb.ora
db_name='mandb' #database name
instance_name='mandb'
control_files='/disk2/oradata/mandb/datafile/mandb_control01.ctl'
memory_target=500m
db_block_size=32768
db_create_file_dest='/disk2/oradata/mandb/datafile'
db_block_size 指定建立的資料庫預設塊大小,如果不指定,預設為:8192,注:建立資料庫後不能修改預設資料區塊大小
db_create_file_dest 在未指定資料檔案路徑時,資料檔案預設建立位置
3.啟動執行個體到nomount狀態建立資料庫
$ sqlplus / as sysdba
SQL> create spfile from pfile='/disk2/oradata/mandb/datafile/mandb.ora';
SQL> startup nomount
SQL> create database mandb
2 user sys identified by oracle
3 user system identified by oracle
4 logfile group 1 '/disk2/oradata/mandb/logfile/redo01.log' size 50m blocksize 512,
5 group 2 '/disk2/oradata/mandb/logfile/redo02.log' size 50m blocksize 512,
6 group 3 '/disk2/oradata/mandb/logfile/redo03.log' size 50m blocksize 512
7 maxlogfiles 10
8 maxlogmembers 5
9 maxloghistory 5
10 maxdatafiles 200
11 character set al32UTF8
12 National character set al16UTF16
13 extent management local
14 datafile '/disk2/oradata/mandb/datafile/system01.dbf' size 500m reuse
15 sysaux
16 datafile '/disk2/oradata/mandb/datafile/sysaux01.dbf' size 500m reuse
17 default tablespace users
18 datafile '/disk2/oradata/mandb/datafile/user01.dbf' size 100m reuse
19 default temporary tablespace tempfile
20 tempfile '/disk2/oradata/mandb/datafile/temp01.dbf' size 20m autoextend on
21 undo tablespace undotbs01
22 datafile '/disk2/oradata/mandb/datafile/undotbs01.dbf' size 20m autoextend on
23 maxsize unlimited;
記錄檔的塊大小為:512bytes,可以設定1024bytes、4096bytes,控制檔案的塊大小為:16k;
注:如果中途出錯或意外停止,要刪除非指定reuse或不能指定reuse 的檔案(如:控制檔案、tempfile、undofile),然後在運行:
rm /disk2/oradata/mandb/datafile/mandb.ora
rm /disk2/oradata/mandb/datafile/undotbs01.dbf
rm /disk2/oradata/mandb/datafile/undotbs01.dbf
4.運行指令碼建立字典、視圖、包、角色、許可權、同義字
SQL>@?/rdbms/admin/catalog.sql ####字典、視圖、公用同義字、角色、許可權
SQL>@?/rdbms/admin/catproc.sql ####系統所需的pl/sql包
官方文檔說還要登陸到system使用者執行@?/sqlplus/admin/pupbld.sql指令碼,但在安裝的11.2.0.1.0版本上並未找到。至此資料庫建立完畢;
5.檢查資料庫相關資訊
SQL> column name format a10
SQL> select DBID,name,DB_UNIQUE_NAME,CURRENT_SCN,open_mode from v$database; --資料庫資訊
DBID NAME DB_UNIQUE_NAME CURRENT_SCN OPEN_MODE
---------- ---------- ------------------------------ ----------- --------------------
3530583721 MANDB 385901 READ WRITE
SQL> column name format a50
SQL> select file#,name,block_size from v$datafile; --資料檔案資訊
FILE# NAME BLOCK_SIZE
---------- -------------------------------------------------- ----------
1 /disk2/oradata/mandb/datafile/system01.dbf 32768
2 /disk2/oradata/mandb/datafile/sysaux01.dbf 32768
3 /disk2/oradata/mandb/datafile/undotbs01.dbf 32768
4 /disk2/oradata/mandb/datafile/user01.dbf 32768
SQL> column member format a40
SQL> select * from v$Logfile; --記錄檔資訊
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- ---------------------------------------- ---
1 ONLINE /disk2/oradata/mandb/logfile/redo01.log NO
2 ONLINE /disk2/oradata/mandb/logfile/redo02.log NO
3 ONLINE /disk2/oradata/mandb/logfile/redo03.log NO
SQL> column name format a60
SQL> select * from v$controlfile; --控制檔案資訊
STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS
------- ------------------------------------------------------------ --- ---------- --------------
/disk2/oradata/mandb/datafile/mandb_control01.ctl NO 16384 668
SQL> column window_name format a17
SQL>select WINDOW_NAME,WINDOW_NEXT_TIME,WINDOW_ACTIVE,AUTOTASK_STATUS from DBA_AUTOTASK_WINDOW_CLIENTS; --視窗資訊
WINDOW_NAME WINDOW_NEXT_TIME WINDO AUTOTASK
----------------- --------------------------------------------------------------------------- ----- --------
WEDNESDAY_WINDOW 08-APR-15 10.00.00.000000 PM PRC FALSE ENABLED
FRIDAY_WINDOW 10-APR-15 10.00.00.000000 PM PRC FALSE ENABLED
TUESDAY_WINDOW 07-APR-15 10.00.00.000000 PM PRC FALSE ENABLED
SATURDAY_WINDOW 11-APR-15 06.00.00.000000 AM PRC FALSE ENABLED
SUNDAY_WINDOW 05-APR-15 06.00.00.000000 AM PRC FALSE ENABLED
MONDAY_WINDOW 06-APR-15 10.00.00.000000 PM PRC FALSE ENABLED
THURSDAY_WINDOW 09-APR-15 10.00.00.000000 PM PRC FALSE ENABLED
檢查是否有對象錯誤:
SQL> select COUNT(*) "OBJECTS WITH ERRORS" from obj$ where status = 3;
如果有包、java code錯誤,可以通過oracle提供的utlrp.sql重新編譯
SQL> @?/rdbms/admin/utlrp.sql
6.啟用歸檔日誌
$ sqlplus / as sysdba <<EOF
alter system checkpoint;
alter system checkpoint;
alter system checkpoint;
shutdown immediate;
startup mount
alter database archivelog;
alter database open;
EOF
--The end