Oracle11g RAC常用操作 (維護及管理)

達芬奇的夢發表於2017-03-17


1. 檢視各資源狀態(nodeapps節點應用程式,ASM例項,資料庫例項等):

[root@rac01 u01]# su - grid 
[grid@rac01 ~]$ crs_stat -t   (命令相容10g)
Name           Type           Target    State     Host       
------------------------------------------------------------
ora....ER.lsnr ora....er.type ONLINE    ONLINE    rac01      
ora....N1.lsnr ora....er.type ONLINE    ONLINE    rac01      
ora....VOTE.dg ora....up.type ONLINE    ONLINE    rac01      
ora.ORADATA.dg ora....up.type ONLINE    ONLINE    rac01      
ora....LASH.dg ora....up.type ONLINE    ONLINE    rac01      
ora.asm        ora.asm.type   ONLINE    ONLINE    rac01      
ora.eons       ora.eons.type  ONLINE    ONLINE    rac01      
ora.gsd        ora.gsd.type   OFFLINE   OFFLINE              
ora....network ora....rk.type ONLINE    ONLINE    rac01      
ora.oc4j       ora.oc4j.type  OFFLINE   OFFLINE              
ora.ons        ora.ons.type   ONLINE    ONLINE    rac01      
ora....SM1.asm application    ONLINE    ONLINE    rac01      
ora....01.lsnr application    ONLINE    ONLINE    rac01      
ora.rac01.gsd  application    OFFLINE   OFFLINE              
ora.rac01.ons  application    ONLINE    ONLINE    rac01      
ora.rac01.vip  ora....t1.type ONLINE    ONLINE    rac01      
ora....SM2.asm application    ONLINE    ONLINE    rac02      
ora....02.lsnr application    ONLINE    ONLINE    rac02      
ora.rac02.gsd  application    OFFLINE   OFFLINE              
ora.rac02.ons  application    ONLINE    ONLINE    rac02      
ora.rac02.vip  ora....t1.type ONLINE    ONLINE    rac02      
ora.racdb.db   ora....se.type ONLINE    ONLINE    rac01      
ora....ry.acfs ora....fs.type ONLINE    ONLINE    rac01      
ora.scan1.vip  ora....ip.type ONLINE    ONLINE    rac01      


在11g R2中,預設 oc4j和gsd資源是 disable 的;oc4j  是用於WLM 的一個
資源, WLM在 11.2.0.2 才可用;gsd 是 CRS 用於跟 9i RAC 進行通訊的一
個模組,是為了向後相容才保留的,不影響效能;建議不要刪除, 也不要嘗試開
啟他們,  忽略即可。   

11g RAC 常用的是下面的命令:crsctl stat  resource -t .

[root@rac01 u01]# su - grid 
[grid@rac01 ~]$ crsctl stat  resource -t

如果後面不帶 -t , 那麼可以看到相對詳細的資源資訊 。
[grid@rac01 ~]$ crsctl stat  resource

 

2. 常用開關機命令

注意, 11g RAC 開啟資源相對比較慢(即使命令後面顯示的資源都start succeeded,
透過crs_stat -t檢視都不一定online), 請注意命令操作後觀察crs log變化,以免出
現還沒有開啟就懷疑啟動有異常而採取重複動作 。  


以下命令供參考:
---------------------------------------------------
在本地伺服器上停止Oracle Clusterware 系統:

[root@rac01 ~]# /u01/grid/11.2.0/bin/crsctl   stop  cluster
注:在執行“crsctl stop cluster”命令之後,如果 Oracle Clusterware 管理的
資源中有任何一個還在執行,則整個命令失敗。使用 -f 選項無條件地停止所有資源
並停止 Oracle Clusterware 系統。

[root@rac02 ~]# /u01/grid/11.2.0/bin/crsctl  stop  cluster  -all
停止所有節點上的clusterware系統。

在本地伺服器上啟動oralce clusterware系統:
[root@rac01 ~]# /u01/grid/11.2.0/bin/crsctl start cluster

注:可透過指定 -all 選項在叢集中所有伺服器上啟動 Oracle Clusterware 系統。
[root@rac02 ~]# /u01/grid/11.2.0/bin/crsctl start cluster –all

還可以透過列出伺服器(各伺服器之間以空格分隔)在叢集中一個或多個指定的伺服器上啟動 Oracle Clusterware 系

統:
[root@rac01 ~]# /u01/grid/11.2.0/bin/crsctl start cluster -n rac01 rac02

使用 SRVCTL 啟動/停止所有例項:

[oracle@rac01 ~]# srvctl stop database -d racdb
[oracle@rac01 ~]# srvctl start database -d racdb


參考順序

關機順序: 先關閉Oracle例項(或資料庫),然後關閉ASM例項,最後關閉節點應用
程式(虛擬 IP、GSD、TNS 監聽器和 ONS) .

手工開機順序: 先啟動節點應用程式(虛擬 IP、GSD、TNS 監聽器和 ONS)。當成功
啟動節點應用程式後,啟動 ASM 例項。最後,啟動 Oracle 例項(相關服務)以及
企業管理器資料庫控制檯。

 

例子:

關閉:

在節點1上關閉所有節點的clusterware(如果有資源不能被關閉,使用-f).
[root@rac01 bin]# /u01/grid/11.2.0/bin/crsctl  stop cluster  -all

節點1,2上都關閉後我們檢視
[grid@rac02 rac02]$ crsctl stat resource -t 
CRS-4535: Cannot communicate with Cluster Ready Services
CRS-4000: Command Status failed, or completed with errors.

開啟:
[root@rac01 bin]# /u01/grid/11.2.0/bin/crsctl  start  cluster  -all


一般來說,開啟上面一個命令就夠用了,但是如果發現有異常,比如db等很長
時間都沒有onine, 我們也可以手工開啟資料庫(任何一個節點執行):
[root@rac02 ~]# /u01/grid/11.2.0/bin/srvctl  start  database  -d  racdb  

備註:
如果有需要也可以一個一個例項開啟。
[root@rac02 ~]# /u01/grid/11.2.0/bin/srvctl start instance -d racdb -i racdb1
[root@rac02 ~]# /u01/grid/11.2.0/bin/srvctl start instance -d racdb -i racdb2

 

3.  常用建立表空間及加入資料檔案 


參考 : http://space.itpub.net/?uid-7607759-action-viewspace-itemid-670722  

[root@rac01 bin]# su - oracle  
[oracle@rac01 ~]$ sqlplus / as sysdba 
SQL> create tablespace test  datafile '+oradata/racdb/datafile/test01.dbf'  size 50m ;
Tablespace created.

[root@rac02 ~]# su - grid
[grid@rac02 ~]$ asmcmd
ASMCMD>
ASMCMD> pwd
+oradata/racdb/datafile
ASMCMD>
ASMCMD> ls
SYSAUX.261.739387301
SYSTEM.260.739387283
TEST.340.740166807
UNDOTBS1.262.739387315
UNDOTBS2.264.739387351
USERS.265.739387361
test01.dbf

SQL> alter tablespace test add datafile  '+oradata/racdb/datafile/test02.dbf' size 50m ; 
Tablespace altered.

SQL>

ASMCMD> ls
SYSAUX.261.739387301
SYSTEM.260.739387283
TEST.340.740166807
TEST.341.740166937
UNDOTBS1.262.739387315
UNDOTBS2.264.739387351
USERS.265.739387361
test01.dbf
test02.dbf
ASMCMD>


ASMCMD> ls  -al
Type      Redund  Striped  Time             Sys  Name
DATAFILE  UNPROT  COARSE   JAN 11 17:00:00  Y    none => SYSAUX.261.739387301
DATAFILE  UNPROT  COARSE   JAN 11 17:00:00  Y    none => SYSTEM.260.739387283
DATAFILE  UNPROT  COARSE   JAN 11 17:00:00  Y    +ORADATA/RACDB/DATAFILE/test01.dbf =>

TEST.340.740166807
DATAFILE  UNPROT  COARSE   JAN 11 17:00:00  Y    +ORADATA/RACDB/DATAFILE/test02.dbf =>

TEST.341.740166937
DATAFILE  UNPROT  COARSE   JAN 11 17:00:00  Y    none => UNDOTBS1.262.739387315
DATAFILE  UNPROT  COARSE   JAN 11 17:00:00  Y    none => UNDOTBS2.264.739387351
DATAFILE  UNPROT  COARSE   JAN 11 17:00:00  Y    none => USERS.265.739387361
                                            N    test01.dbf =>

+ORADATA/RACDB/DATAFILE/TEST.340.740166807
                                            N    test02.dbf =>

+ORADATA/RACDB/DATAFILE/TEST.341.740166937
ASMCMD>

 

4. 檢視ASM例項及使用者資料庫例項(注意分別是grid及oracle使用者):


檢視ASM例項(以grid使用者登入,透過檢視初始引數可以看到instance_name=+ASM1):

[grid@rac01 ~]$ id
uid=501(grid) gid=501(oinstall) groups=501(oinstall),504(asmadmin),506(asmdba),507(asmoper)
[grid@rac01 ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Tue Jan 4 00:58:52 2011
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Real Application Clusters and Automatic Storage Management options

SQL> show parameter

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
asm_diskgroups                       string      ORADATA, ORAFLASH
asm_diskstring                       string
asm_power_limit                      integer     1
asm_preferred_read_failure_groups    string
audit_file_dest                      string      /u01/grid/11.2.0/rdbms/audit
.....

 

檢視使用者資料庫例項(以oracle使用者登入,檢視instance_name=racdb2,顯然是使用者例項): 

[root@rac02 u01]# su - oracle
[oracle@rac02 ~]$
[oracle@rac02 ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Tue Jan 4 01:01:04 2011

Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> show parameter

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
O7_DICTIONARY_ACCESSIBILITY          boolean     FALSE
active_instance_count                integer
aq_tm_processes                      integer     0
archive_lag_target                   integer     0
asm_diskgroups                       string
asm_diskstring                       string
asm_power_limit                      integer     1
.......

 

5. 檢視11g 資料庫例項的alert log及trace : 

[oracle@rac01 trace]$ pwd
/u01/product/oracle/diag/rdbms/racdb/racdb1/trace
[oracle@rac01 trace]$
[oracle@rac01 trace]$ vi  alert_racdb1.log

 

6. 檢視11g RAC Clusterware的log :

[root@rac01 sbin]# su - grid
[grid@rac01 ~]$
[grid@rac01 rac01]$ pwd
/u01/grid/11.2.0/log/rac01


[grid@rac01 trace]$ pwd
/u01/grid/11.2.0/log/diag/tnslsnr/rac01/listener_scan1/trace
[grid@rac01 trace]$ ls
listener_scan1.log


[grid@rac01 rac01]$ pwd
/u01/grid/11.2.0/log/rac01
[grid@rac01 rac01]$ ls
admin/  alertrac01.log  crsd/  ctssd/    evmd/   gnsd/   mdnsd/  racg/
agent/  client/         cssd/  diskmon/  gipcd/  gpnpd/  ohasd/  srvm/

 

7. 常用叢集命令


[grid@rac02 ~]$ crs_stat -t 


檢查Oracle Clusterware 是否線上

[grid@rac02 ~]$ crsctl check crs
CRS-4638: Oracle High Availability Services is online
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online


檢查cssd (Cluster Synchronization Services) 是否線上

[grid@rac02 ~]$ crsctl check cssd
CRS-272: This command remains for backward compatibility only
Cluster Synchronization Services is online


檢查crsd (Cluster Ready Services) 是否線上

[grid@rac02 ~]$ crsctl check crsd  
CRS-272: This command remains for backward compatibility only
Cluster Ready Services is online


檢查evmd (Event Mananger)是否線上

[grid@rac02 ~]$ crsctl check evmd
CRS-272: This command remains for backward compatibility only
Event Manager is online


在節點間檢查CSS的存活

[grid@rac02 ~]$ crsctl check cluster -n  rac01
**************************************************************
rac01:
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
**************************************************************

[grid@rac02 ~]$ crsctl check cluster -n  rac02
**************************************************************
rac02:
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
**************************************************************


開啟資料庫

[grid@rac02 ~]$ srvctl start database -d racdb

開啟oc4j :

[grid@rac02 ~]$ ./srvctl enable oc4j
[grid@rac02 ~]$ ./srvctl start oc4j
[grid@rac02 ~]$ ./crs_stat -t

 


8.  vote disk 管理 

[grid@rac01 ~]$ ocrcheck    
Status of Oracle Cluster Registry is as follows :
         Version                  :          3
         Total space (kbytes)     :     262120
         Used space (kbytes)      :       2720
         Available space (kbytes) :     259400
         ID                       :  132900461
         Device/File Name         :  +OCR_VOTE
                                    Device/File integrity check succeeded

                                    Device/File not configured

                                    Device/File not configured

                                    Device/File not configured

                                    Device/File not configured

         Cluster registry integrity check succeeded

         Logical corruption check bypassed due to non-privileged user


在Oracle11g R2中,不必備份voting disk, 當任何配置發生改變,voting disk
資料會自動備份在OCR中,並自動恢復到任何加入的voting disk中。 從下面可以看
到OCR和VotingDisk是一個檔案。


[grid@rac01 ~]$ crsctl  query css votedisk
##  STATE    File Universal Id                File Name Disk group
--  -----    -----------------                --------- ---------
 1. ONLINE   095112005ec24f57bf98f6148818cc53 (ORCL:OCR_VOTE01) [OCR_VOTE]
Located 1 voting disk(s).
[grid@rac01 ~]$


[grid@rac01 ~]$ asmcmd
ASMCMD> ls
OCR_VOTE/
ORADATA/
ORAFLASH/
ASMCMD> cd ocr_vote
ASMCMD> cd rac
ASMCMD> ls
ASMPARAMETERFILE/
OCRFILE/
ASMCMD> cd ocrfile
ASMCMD> ls
REGISTRY.255.739337635


OCR 管理

[grid@rac01 ~]$ crsctl query crs activeversion
Oracle Clusterware active version on the cluster is [11.2.0.1.0]


[grid@rac01 ~]$ ocrcheck
Status of Oracle Cluster Registry is as follows :
         Version                  :          3
         Total space (kbytes)     :     262120
         Used space (kbytes)      :       2720
         Available space (kbytes) :     259400
         ID                       :  132900461
         Device/File Name         :  +OCR_VOTE
                                    Device/File integrity check succeeded

                                    Device/File not configured

                                    Device/File not configured

                                    Device/File not configured

                                    Device/File not configured

         Cluster registry integrity check succeeded

         Logical corruption check bypassed due to non-privileged user


使用下面命令(root登陸)使用 destination_file 或者 +ASM_disk_group取代現在的OCR Location:

# ocrconfig -replace current_OCR_location -replacement new_OCR_location

如果只有一個OCR Location, 那麼使用下面的命令:
# ocrconfig -add  +new_storage_disk_group
# ocrconfig -delete  +current_disk_group


執行下面的命令顯示備份:

[grid@rac01 ~]$ ocrconfig   -showbackup 
rac01     2011/01/08 17:54:51     /u01/grid/11.2.0/cdata/rac/backup00.ocr
rac01     2011/01/08 13:54:49     /u01/grid/11.2.0/cdata/rac/backup01.ocr
rac02     2011/01/08 06:34:46     /u01/grid/11.2.0/cdata/rac/backup02.ocr
rac01     2011/01/07 02:15:37     /u01/grid/11.2.0/cdata/rac/day.ocr
rac01     2011/01/02 07:51:43     /u01/grid/11.2.0/cdata/rac/week.ocr
PROT-25: Manual backups for the Oracle Cluster Registry are not available

 

當Oracle Clusterware起來的時候,在一個節點上執行ocrconfig -manualbackup命令

[grid@rac01 ~]$ ocrconfig   -manualbackup
在 /u01/grid/11.2.0/cdata/rac/day.ocr下生成備份檔案 backup_20100112_141900.ocr

然後使用 $ ocrconfig -showbackup 可以檢視到備份資訊。

執行下面的命令檢驗備份檔案內容及完整性。
$ ocrdump -backupfile backup_file_name   

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31444259/viewspace-2135531/,如需轉載,請註明出處,否則將追究法律責任。

相關文章