Oracle並行伺服器(OPS)
--------------------------
http://doc.linuxpk.com/49010.html
本文以問答的方式闡述了Oracle並行伺服器的相關概念。
1、什麼是OPS
OPS(Oracle Parallel Server)可以讓位於不同系統的多個執行個體同時訪問同一個資料庫。並行伺服器可以有效地提高系統的可用性和對多系統的訪問效能,但是,如果你的資料沒有做很好的分割,效能可能還會下降。
安裝OPS時,多個執行個體mount同一資料庫檔案,執行個體間的通訊由分布式鎖管理器(DLM)來管理。需要注意的是分布式鎖管理器與你所使用的硬體和* 作系統有著密切的關係。為了確定多個企圖同時修改同一資料的執行個體,Oracle使用了十個後台進程:LCK0-LCK9,來鎖定某一執行個體所使用的資源。
OPS主要用於UNIX/LINUX叢集環境中。
2、OPS的優點
1)高可用性
2)加快事務回應時間 - 可用於決策支援系統
3)增大交易串連數 - 可用於聯機交易處理系統
3、所有的應用都是適合OPS嗎?
可以根據功能或資料進行分割的應用最適合OPS。那些有"熱資料"(經常被多執行個體同時訪問的資料)的應用並不適合使用OPS。
4、OPS需要特殊的硬體嗎?
OPS要求伺服器之間互連並共用磁碟子系統。所有可以做成叢集的系統都可以,常用的有UNIX/LINUX和NT等。
5、如何設定OPS?
1)關閉資料庫
2)啟用OPS選項,在UNIX中通過重新串連Oracle軟體的方式來完成。
3)使Oracle軟體在所有節點上都有效,可以通過複製軟體到其他節點或共用磁碟的方式來完成。
4)每個執行個體要有自己的Redo log file,所以要增加必要的log檔案:
ALTER DATABASE ADD LOGFILE THREAD 2
GROUP G4 ('RAW_FILE1') SIZE 500k,
GROUP G5 ('RAW_FILE2') SIZE 500k,
GROUP G6 ('RAW_FILE3') SIZE 500k;
ALTER DATABASE ENABLE PUBLIC THREAD 2;
5)每個執行個體要有自己的復原段,所以要增加必要的復原段:
CREATE ROLLBACK SEGMENT RB2 TABLESPACE RBS;
6)編輯初始化參數檔案initSID.ora檔案,添加如下幾項:
PARALLEL_SERVER = TRUE
INSTANCE_NUMBER = 1
THREAD = 1
ROLLBACK_SEGMENTS = (r01, r02, r03, r04)
7)建立OPS所需的資料字典,即運行CATPARR.SQL。
8)在所有的節點上啟動執行個體。
6、如何確定一個資料庫是運行在並行狀態?
show parameter parallel_server
7、如何跟蹤活動的執行個體?
SELECT * FROM SYS.V_$ACTIVE_INSTANCES;
SELECT * FROM SYS.V_$THREAD;
8、如何確定每個執行個體使用了多少個PCM鎖?
select count(*) "Number of hashed PCM locks"
from v$lock_element where bitand(flags, 4) != 0
/
select count(*) "Number of fine grain PCM locks"
from v$lock_element where bitand(flags, 4) = 0
/
9、如何查看每個資料檔案分配了多少個PCM鎖以及ping率?
col file_name format a29
col tablespace format a12
col blocking format 9999999
col nlocks format 99999
col start_lk format 9999999
select l.file_id ¦ ¦ ' ' ¦ ¦ l.file_name file_name,
l.ts_name "TABLESPACE",
start_lk, nlocks, blocking, frequency "PING COUNT"
from sys.file_ping p, sys.file_lock l
where l.file_id = p.file_id
order by l.file_id
/
10、什麼是pinging?
Pinging是進程,用於協調多執行個體對同一資料區塊的讀寫*作。OPS效能最佳化的一個挑戰就是要最小化pinging。
11、如何監控PCM鎖的活動情況?
查看當前執行個體活動PCM鎖的總數:select * from sys.v$lock_activity;
查看每個資料庫物件的PCM鎖活動狀況:
col table format a40
select file#, kind ¦ ¦' ' ¦ ¦username ¦ ¦'.' ¦ ¦name "TABLE", sum(xnc) pings
from sys.v$false_ping p, sys.dba_users u
where u.user_id = p.owner#
group by file#, kind ¦ ¦' ' ¦ ¦username ¦ ¦'.' ¦ ¦name, xnc
order by xnc desc
/
12、如何設定一個對所有OPS執行個體通用的SQL*Net串連串?
1)首先要求所有節點上的SID相同,如果不相同可以按如下*作變更:
關閉資料庫的所有執行個體
將ORACLE_SID環境變數設成一致
複製原來的初始設定檔案initOLDSID.ora為initCOMMON.ora
重起所有執行個體
2)編輯本地TNSNAMES.ora,如下例:
PHOENIX =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.1.50)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.1.51)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ora8)
)
)
ps:
設定並行查詢,提高CPU利用率:
http://www.oracle.com.cn/archiver/?tid-120936.html
-------------------------
Parallel query is the most commonly used of Oracle's parallel execution features. It was the first parallel execution feature to be developed by Oracle and was introduced in Oracle Release 7.1 as the Oracle Parallel Query Option (PQO). Parallel execution can significantly reduce the elapsed time for large queries, but it doesn't apply to every query.
To parallelize a SELECT statement, the following conditions must be met:
1、 At least one of the tables is accessed through a full table scan, or an index is accessed through a range scan involving multiple partitions.
2、 If the execution involves a full table scan, the statement must contain a PARALLEL hint specifying the corresponding table, or the corresponding table must have a parallel declaration in its definition.
3、 If the execution involves an index range scan spanning multiple partitions, the statement must contain a PARALLEL_INDEX hint specifying the corresponding index, or the corresponding index must have a parallel declaration in its definition.
The following two sections explain how the degree of parallelism is chosen for a SELECT statement and discuss restrictions on the use of the parallel query feature.
Setting the Degree of Parallelism
Once Oracle decides to execute a SELECT statement in parallel, the degree of parallelism is determined by following precedence rules:
Oracle retrieves the DEGREE and INSTANCES specifications from the definition of all tables and indexes involved in the query and chooses the highest values found for those settings.
Oracle checks the statement for a parallel hint. If such a hint is found, the hint overrides the degree of parallelism obtained as a result of the previous step.
You can use the PARALLEL and PARALLEL_INDEX hints to specify the degree of parallelism for a SELECT statement. You can use the NOPARALLEL and NOPARALLEL_INDEX hints to ensure that parallel execution is not performed.
Example
alter table emp parallel (degree 4);
select degree from user_tables where table_name = 'EMP';
select count(*) from emp;
alter table emp noparallel;
SELECT /*+ PARALLEL(emp,4) */ COUNT(*)
FROM emp;