oracle 對一個資料庫開啟多個執行個體 __Python

來源:互聯網
上載者:User
    對於Oracle資料庫來說,db_name和instance_name可以不同。 我們來看一下Oracle文檔中對於db_name的定義:   DB_NAME必須是一個不超過8個字元的文本串.在資料庫建立過程中,db_name被記錄在資料檔案,記錄檔和控制檔案中。如果資料庫執行個體啟動過程中參數檔案中的db_name和控制檔案中的資料庫名稱不一致,則資料庫不能啟動。   一個執行個體可以mount並開啟任何資料庫,但是同一時間一個執行個體只能開啟一個資料庫。 一個資料庫可以被一個或多個執行個體所mount並開啟(在OPS/RAC環境下,一個資料庫可以被多個執行個體所開啟).   我們看一下我的資料庫:   [oracle@jumper dbs]$ grep name initeygle.ora *.db_name='eygle' *.instance_name='eygle'     當前參數設定下的資料庫:       SQL> select name from v$datafile;   NAME ----------------------------------------------------- /opt/oracle/oradata/eygle/system01.dbf /opt/oracle/oradata/eygle/undotbs01.dbf /opt/oracle/oradata/eygle/users01.dbf /opt/oracle/oradata/eygle/eygle01.dbf   SQL> show parameter db_name   NAME                                  TYPE        VALUE ------------------------------------ ----------- ----------- db_name                               string      eygle SQL> show parameter instance_name   NAME                                  TYPE        VALUE ------------------------------------ ----------- ----------- instance_name                         string      eygle SQL> create pfile from spfile;   File created.   SQL> exit Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production With the Partitioning option JServer Release 9.2.0.4.0 - Production       我們建立一個新的pfile為julia這個新的執行個體使用:       [oracle@jumper oracle]$ cd $ORACLE_HOME/dbs [oracle@jumper dbs]$ cp initeygle.ora initjulia.ora [oracle@jumper dbs]$ ll init* -rw-r--r--     1 oracle   dba           982 Jul 25 14:03 initeygle.ora -rw-r--r--     1 oracle   dba           982 Jul 25 14:04 initjulia.ora -rw-r--r--     1 oracle   dba          8385 Mar 9 2002 init.ora     修改這個檔案更改: instance_name = julia   修改後的參數設定:       [oracle@jumper dbs]$ grep name initjulia.ora *.db_name='eygle' *.instance_name='julia'     然後我們啟動執行個體名稱為julia的instance:       [oracle@jumper dbs]$ export ORACLE_SID=julia [oracle@jumper dbs]$ sqlplus "/ as sysdba"   SQL*Plus: Release 9.2.0.4.0 - Production on Tue Jul 25 14:04:15 2006   Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.   Connected to an idle instance.   SQL> startup mount; ORACLE instance started.   Total System Global Area 139531744 bytes Fixed Size                    452064 bytes Variable Size              121634816 bytes Database Buffers            16777216 bytes Redo Buffers                  667648 bytes ORA-01102: cannot mount database in EXCLUSIVE mode   SQL> exit Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production With the Partitioning option JServer Release 9.2.0.4.0 - Production       注意,此時試圖載入資料庫時出現錯誤,因為當前資料庫被另外一個執行個體(instance)載入。在非並行模式(Ops/RAC)下,一個資料庫同時只能被一個執行個體載入。   此時已經啟動了兩個資料庫執行個體,從後台進程可以看出:       [oracle@jumper dbs]$ ps -ef|grep ora oracle    27321     1 0 Jul14 ?        00:00:00 ora_pmon_eygle oracle    27323     1 0 Jul14 ?        00:00:00 ora_dbw0_eygle oracle    27325     1 0 Jul14 ?        00:00:00 ora_lgwr_eygle oracle    27327     1 0 Jul14 ?        00:00:00 ora_ckpt_eygle oracle    27329     1 0 Jul14 ?        00:00:32 ora_smon_eygle oracle    27331     1 0 Jul14 ?        00:00:00 ora_reco_eygle oracle    27333     1 0 Jul14 ?        00:00:00 ora_cjq0_eygle root      15388   656 0 14:02 ?        00:00:00 sshd: oracle [priv] oracle    15390 15388 0 14:02 ?        00:00:00 sshd: oracle@pts/2 oracle    15391 15390 0 14:02 pts/2    00:00:00 -bash oracle    15445     1 0 14:04 ?        00:00:00 ora_pmon_julia oracle    15447     1 0 14:04 ?        00:00:00 ora_dbw0_julia oracle    15449     1 0 14:04 ?        00:00:00 ora_lgwr_julia oracle    15451     1 0 14:04 ?        00:00:00 ora_ckpt_julia oracle  15453      1 0 14:04 ?        00:00:00 ora_smon_julia oracle    15455     1 0 14:04 ?        00:00:00 ora_reco_julia oracle    15457     1 0 14:04 ?        00:00:00 ora_cjq0_julia oracle    15459 15391 0 14:04 pts/2    00:00:00 ps -ef oracle    15460 15391 0 14:04 pts/2    00:00:00 grep ora     我們關閉eygle這個資料庫執行個體:       [oracle@jumper dbs]$ export ORACLE_SID=eygle [oracle@jumper dbs]$ sqlplus "/ as sysdba"   SQL*Plus: Release 9.2.0.4.0 - Production on Tue Jul 25 14:04:39 2006   Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.     Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production With the Partitioning option JServer Release 9.2.0.4.0 - Production   SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> exit Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production With the Partitioning option JServer Release 9.2.0.4.0 - Production       此時就可以通過執行個體julia載入並開啟db_name=eygle的資料庫了:       [oracle@jumper dbs]$ export ORACLE_SID=julia [oracle@jumper dbs]$ sqlplus "/ as sysdba"   SQL*Plus: Release 9.2.0.4.0 - Production on Tue Jul 25 14:05:06 2006   Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.     Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production With the Partitioning option JServer Release 9.2.0.4.0 - Production   SQL> alter database mount; alter database mount * ERROR at line 1: ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw' ORA-27037: unable to obtain file status Linux Error: 2: No such file or directory Additional information: 3     SQL> alter database open;   Database altered.   SQL> select name from v$datafile;   NAME ---------------------------------------------------------------------------- /opt/oracle/oradata/eygle/system01.dbf /opt/oracle/oradata/eygle/undotbs01.dbf /opt/oracle/oradata/eygle/users01.dbf /opt/oracle/oradata/eygle/eygle01.dbf   SQL> ! ps -ef|grep ora root      15388   656 0 14:02 ?        00:00:00 sshd: oracle [priv] oracle    15390 15388 0 14:02 ?        00:00:00 sshd: oracle@pts/2 oracle    15391 15390 0 14:02 pts/2    00:00:00 -bash oracle    15445     1 0 14:04 ?        00:00:00 ora_pmon_julia oracle    15447     1 0 14:04 ?        00:00:00 ora_dbw0_julia oracle    15449     1 0 14:04 ?        00:00:00 ora_lgwr_julia oracle    15451     1 0 14:04 ?        00:00:00 ora_ckpt_julia oracle    15453     1 0 14:04 ?        00:00:00 ora_smon_julia oracle    15455     1 0 14:04 ?        00:00:00 ora_reco_julia oracle    15457     1 0 14:04 ?        00:00:00 ora_cjq0_julia oracle    15513 15391 0 14:05 pts/2    00:00:00 sqlplus            oracle    15514 15513 3 14:05 ?        00:00:01 oraclejulia (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle    15515 15513 0 14:05 pts/2    00:00:00 /bin/bash -c ps -ef|grep ora oracle    15516 15515 0 14:05 pts/2    00:00:00 ps -ef   SQL> show parameter instance_name   NAME                                  TYPE       VALUE ------------------------------------ ----------- ------------------------------ instance_name                         string      julia SQL> show parameter db_name   NAME                                  TYPE        VALUE ------------------------------------ ----------- ------------------------------ db_name                               string      eygle       我們再看看如果參數檔案中的db_name和控制檔案中的db_name不一致會出現什麼錯誤. 修改參數db_name:       [oracle@jumper dbs]$ grep name initjulia.ora *.db_name='julia' *.instance_name='julia'     在啟動過程中,我們看到,在mount階段,資料庫會對參數檔案和控制檔案進行比較,如果兩者記錄的db_name不一致,則資料庫無法啟動:       SQL> startup nomount; ORACLE instance started.   Total System Global Area 139531744 bytes Fixed Size                    452064 bytes Variable Size              121634816 bytes Database Buffers            16777216 bytes Redo Buffers                  667648 bytes SQL> alter database mount; alter database mount * ERROR at line 1: ORA-01103: database name 'EYGLE' in controlfile is not 'JULIA'         另外的一個區別是,db_name通常限制在8個字元之內;instance_name最多應該支援21個字元。通常我們都是設定db_name和instance_name一致。需要注意的是如果db_name設定過長,則會被Oracle截斷為8個字元,而instance_name仍然會保留在21個字元之內,如果你的環境變數設定的instance_name=db_name,則啟動時就會出現問題,你需要重建pfile/spfile並且修改環境變數才能啟動執行個體,載入資料庫。   這個問題可以參考Itpub曾經出現的案例:   http://www.itpub.net/showthread.php?threadid=604507   本文通過執行個體來介紹instance_name和db_name的區別,希望大家能對這兩個參數以及instance和database有進一步的認識。       個人補充:   對於Windows 使用者來說,在為eygle資料庫建立新執行個體julia是參照下面的動作。(針對oracle 9i)   1.    拷貝eygle資料庫的參數檔案 INITeygle.ORA 為 INITjulia.ORA,並設定 instancename = julia,也可以動態產生 spfile 檔案,啟動的時候使用該spfile。       2.    為執行個體 julia 產生新的 password file, 可以拷貝 PWDEYGLE.ora 然後改名為 PWDJULIA.ora,或者使用 orapwd命令:   orapwd file=%ORACLE_HOME%datebase¥PWDJULIA.ora password={password} entries=10     3.    為執行個體 julia 產生Windows Service   oradim -new -sid JULIA -intpwd password -startmode a -pfile %ORACLE_HOME%database¥INITjulia.ORA     4.    將執行個體添加到 TNS Listener 位於%ORALCE_HOME%¥network¥admin下的設定檔 listener.ora 和 tnsnames.ora 中       5.    reload TNS listener   lsnrctl reload      

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.