閱讀
Oracle 11gR2 Administrator‘s Guide(
文件編號E25494-01)時,簡單描述了
DDL_LOCK_TIMEOUT引數。在
Oracle 11gR2 Administrator‘s Guide文件的
chapter 2 Creating and Configuring an Oracle Database章節時,提到手工建庫,
本文簡單記錄一下,如何在OEL 5.5 X86_64位環境下,手工建立及刪除11.2.0.1.0的資料庫,將檔案放到檔案系統上存放。當然,利用DBCA來建庫、刪庫比較簡單,就不再贅述了。具體操作步驟如下:
1 前提條件,作業系統上已經安裝好Oracle 11gR2 的軟體,其中環境變數ORACLE_BASE=/u01/app/oracle,ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1;
1 | [root@OCM11g ~]# su - oracle |
3 | ORACLE_BASE=/u01/app/oracle |
4 | ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 |
2 確認環境變數,本例中選擇ORACLE_SID=manualdb,ORACLE_HOME選用原有的/u01/app/oracle/product/11.2.0/db_1;
02 | uid=1101(oracle) gid=1000(oinstall) groups=1000(oinstall),1201(asmdba),1300(dba),1301(oper) |
05 | OCM11g-> export ORACLE_SID=manualdb |
06 | OCM11g-> env | grep ORA |
08 | ORACLE_BASE=/u01/app/oracle |
09 | ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 |
3 建立初始化引數檔案,這裡將引數檔案放到系統預設的路徑下,即$ORACLE_HOME/dbs,命名為initmanualdb.ora,其內容如下:
1 | OCM11g-> cat /u01/app/oracle/product/11.2.0/db_1/dbs/initmanualdb.ora |
簡單起見,我們只在初始化引數檔案中指定了db_name,memory_target這兩個引數。我們知道,啟動資料庫例項的最少引數只需要一個db_name即可,這裡選擇db_name=manualdb,附加一個memory_target=600m,這個是11g的新引數,用於控制SGA+PGA的總大小。當然,也可以在引數檔案中指定control_files,如果該引數被忽略的話,那麼Oracle會自動在$ORACLE_HOME/dbs路徑下建立一個名為cntrl$ORACLE_SID.dbf的控制檔案。
4 準備將來存放資料檔案、日誌檔案的路徑。這兩類檔案的路徑如下:
datafile:
1 | OCM11g-> mkdir -p /u02/manualdb/oradata |
online log:
1 | OCM11g-> mkdir -p /u02/manualdb/onlinelog |
2 | OCM11g-> ll /u02/manualdb/ |
4 | drwxr-xr-x 2 oracle oinstall 4096 Mar 30 10:56 onlinelog |
5 | drwxr-xr-x 2 oracle oinstall 4096 Mar 30 10:56 oradata |
5 啟動manualdb例項到NOMOUNT狀態,其實,在該環境下,我們的控制檔案尚未生成,例項至多也只能載入到NOMOUNT狀態:
02 | uid=1101(oracle) gid=1000(oinstall) groups=1000(oinstall),1201(asmdba),1300(dba),1301(oper) |
03 | OCM11g-> env | grep ORA |
05 | ORACLE_BASE=/u01/app/oracle |
06 | ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 |
09 | SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 30 10:59:32 2012 |
11 | Copyright (c) 1982, 2009, Oracle. All rights reserved. |
13 | Connected to an idle instance. |
16 | ORACLE instance started. |
18 | Total System Global Area 626327552 bytes |
19 | Fixed Size 2215944 bytes |
20 | Variable Size 373297144 bytes |
21 | Database Buffers 243269632 bytes |
22 | Redo Buffers 7544832 bytes |
23 | ORA-00205: error in identifying control file, check alert log for more info |
上述報錯ORA-00205提示控制檔案找不到,正是我們所預見的,因為當前控制檔案還未生成,所以資料庫沒法MOUNT,說明資料庫是NOMOUNT狀態。這時,也可以看到相關的後臺程式已經啟動:
02 | OCM11g-> ps -ef | grep ora_|grep -v grep |
03 | oracle 14885 1 0 11:02 ? 00:00:00 ora_pmon_manualdb |
04 | oracle 14887 1 0 11:02 ? 00:00:00 ora_vktm_manualdb |
05 | oracle 14891 1 0 11:02 ? 00:00:00 ora_gen0_manualdb |
06 | oracle 14893 1 0 11:02 ? 00:00:00 ora_diag_manualdb |
07 | oracle 14895 1 0 11:02 ? 00:00:00 ora_dbrm_manualdb |
08 | oracle 14897 1 0 11:02 ? 00:00:00 ora_psp0_manualdb |
09 | oracle 14899 1 0 11:02 ? 00:00:00 ora_dia0_manualdb |
10 | oracle 14903 1 6 11:02 ? 00:00:27 ora_mman_manualdb |
11 | oracle 14905 1 0 11:02 ? 00:00:01 ora_dbw0_manualdb |
12 | oracle 14907 1 0 11:02 ? 00:00:00 ora_lgwr_manualdb |
13 | oracle 14909 1 0 11:02 ? 00:00:00 ora_ckpt_manualdb |
14 | oracle 14911 1 0 11:02 ? 00:00:00 ora_smon_manualdb |
15 | oracle 14913 1 0 11:03 ? 00:00:00 ora_reco_manualdb |
16 | oracle 14915 1 0 11:03 ? 00:00:00 ora_mmon_manualdb |
17 | oracle 14917 1 0 11:03 ? 00:00:00 ora_mmnl_manualdb |
6 執行下述CREATE DATABASE的命令,開始手工建立Oracle 資料庫:
03 | SQL> select open_mode from v$database; |
04 | select open_mode from v$database |
07 | ORA-01507: database not mounted |
10 | SQL> CREATE DATABASE manualdb |
11 | 2 USER SYS IDENTIFIED BY oracle |
12 | 3 USER SYSTEM IDENTIFIED BY oracle |
13 | 4 LOGFILE GROUP 1 ('/u02/manualdb/onlinelog/redo01a.log') SIZE 50M BLOCKSIZE 512, |
14 | 5 GROUP 2 ('/u02/manualdb/onlinelog/redo02a.log') SIZE 50M BLOCKSIZE 512 |
19 | 10 CHARACTER SET AL32UTF8 |
20 | 11 NATIONAL CHARACTER SET AL16UTF16 |
21 | 12 EXTENT MANAGEMENT LOCAL |
22 | 13 DATAFILE '/u02/manualdb/oradata/system01.dbf' SIZE 300M REUSE |
23 | SYSAUX DATAFILE '/u02/manualdb/oradata/sysaux01.dbf' SIZE 300M REUSE |
24 | DEFAULT TABLESPACE users |
25 | DATAFILE '/u02/manualdb/oradata/users01.dbf' |
26 | 17 SIZE 5M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED |
27 | 18 DEFAULT TEMPORARY TABLESPACE tempts1 |
28 | 19 TEMPFILE '/u02/manualdb/oradata/temp01.dbf' |
30 | 21 UNDO TABLESPACE undotbs |
31 | 22 DATAFILE '/u02/manualdb/oradata/undotbs01.dbf' |
32 | 23 SIZE 20M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED; |
36 | SQL> select name,open_mode from v$database; |
39 | --------- -------------------- |
7 建立資料字典檢視,分別執行下述指令碼來完成:
1 | SQL> @?/rdbms/admin/catalog.sql |
4 | SQL> @?/rdbms/admin/catproc.sql |
7 | SQL> @?/sqlplus/admin/pupbld.sql |
上述3個指令碼的說明見下表:
Script | Description |
The Scripts and descriptionsCATALOG.SQL | Creates the views of the data dictionary tables, the dynamic performance views, and public sy nonyms 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. |
8 至此,我們完成了手工建立Oracle 資料庫。
01 | SQL> select * from v$version; |
04 | -------------------------------------------------------------------------------- |
05 | Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production |
06 | PL/SQL Release 11.2.0.1.0 - Production |
07 | CORE 11.2.0.1.0 Production |
08 | TNS for Linux: Version 11.2.0.1.0 - Production |
09 | NLSRTL Version 11.2.0.1.0 - Production |
13 | SQL> select name,open_mode from v$database; |
16 | --------- -------------------- |
21 | SQL> select name from v$datafile |
23 | 3 select name from v$controlfile |
25 | 5 select member from v$logfile; |
28 | -------------------------------------------------------------------------------- |
29 | /u01/app/oracle/product/11.2.0/db_1/dbs/cntrlmanualdb.dbf |
30 | /u02/manualdb/onlinelog/redo01a.log |
31 | /u02/manualdb/onlinelog/redo02a.log |
32 | /u02/manualdb/oradata/sysaux01.dbf |
33 | /u02/manualdb/oradata/system01.dbf |
34 | /u02/manualdb/oradata/undotbs01.dbf |
35 | /u02/manualdb/oradata/users01.dbf |
9 最後,如果該資料庫不需要的話。我們可以執行手工刪除資料庫,當然必須要將資料庫啟動到MOUNT RESTRICT狀態來刪除:
如何確認例項是否是RESTRICTED MODE:
01 | SQL> select instance_name,status,startup_time,logins from v$instance; |
03 | INSTANCE_NAME STATUS STARTUP_TIME LOGINS |
04 | --------------- ------------ ------------------- ---------- |
05 | manualdb MOUNTED 2012/03/30 13:38:52 ALLOWED |
09 | SQL> alter system enable restricted session; |
13 | SQL> select instance_name,status,startup_time,logins from v$instance; |
15 | INSTANCE_NAME STATUS STARTUP_TIME LOGINS |
16 | --------------- ------------ ------------------- ---------- |
17 | manualdb MOUNTED 2012/03/30 13:38:52 RESTRICTED |
21 | SQL> alter system disable restricted session; |
25 | SQL> select instance_name,status,startup_time,logins from v$instance; |
27 | INSTANCE_NAME STATUS STARTUP_TIME LOGINS |
28 | --------------- ------------ ------------------- ---------- |
29 | manualdb MOUNTED 2012/03/30 13:38:52 ALLOWED |
通過檢視V$INSTANCE動態效能檢視的LOGINS欄位,如果該值為ALLOWED,說明例項是正常啟動,並未進入RESTRICTED MODE,普通使用者可以正常訪問;如果該值為RESTRICTED說明是RESTRICTED MODE,即需要具有RESTRICTED SESSION系統許可權的使用者方可訪問;
手工刪除資料庫:
01 | SQL> select instance_name,status,startup_time,logins from v$instance; |
03 | INSTANCE_NAME STATUS STARTUP_TIME LOGINS |
04 | --------------- ------------ ------------------- ---------- |
05 | manualdb MOUNTED 2012/03/30 13:38:52 ALLOWED |
13 | ORA-12719: operation requires database is in RESTRICTED mode |
16 | SQL> alter system enable restricted session; |
20 | SQL> select instance_name,status,startup_time,logins from v$instance; |
22 | INSTANCE_NAME STATUS STARTUP_TIME LOGINS |
23 | --------------- ------------ ------------------- ---------- |
24 | manualdb MOUNTED 2012/03/30 13:38:52 RESTRICTED |
32 | Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production |
33 | With the Partitioning, OLAP, Data Mining and Real Application Testing options |
此時,Oracle自動刪除該資料庫的所有資料檔案、聯機重做日誌檔案、控制檔案以及初始化引數檔案。從alert日誌檔案裡可以看到下述資訊:
01 | Fri Mar 30 13:45:33 2012 |
03 | Deleted file /u02/manualdb/oradata/system01.dbf |
04 | Deleted file /u02/manualdb/oradata/sysaux01.dbf |
05 | Deleted file /u02/manualdb/oradata/undotbs01.dbf |
06 | Deleted file /u02/manualdb/oradata/users01.dbf |
07 | Deleted file /u02/manualdb/onlinelog/redo01a.log |
08 | Deleted file /u02/manualdb/onlinelog/redo02a.log |
09 | Deleted file /u02/manualdb/oradata/temp01.dbf |
10 | Deleted file /u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_manualdb.f |
10 簡單總結,可見手工建立、刪除資料庫也很簡單。當然,在第6步中執行手工建庫的命令中還有諸多其它選項,比如選擇OMF,這時,只要在引數檔案中指定DB_CREATE_FILE_DEST引數,那麼建庫的命令將更加簡單。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24558279/viewspace-762368/,如需轉載,請註明出處,否則將追究法律責任。