Oracle筆記(5)Oracle RAC維護
阿新 • • 發佈:2021-01-12
1.Voting檔案
1.Voting檔案中儲存了節點程以資訊,每個節點準備啟動並且試圖加入RAC叢集時,都需要讀取Voting檔案。 2.Voting檔案需要通過冗餘保證其安全。 3.從11.2開始,Clusterware被修改後,Voting檔案會自動被備份到OCR檔案中。 4.當votedisk屬於asm磁碟組時,無法通過crsctl命令進行新增、刪除、移動操作 #檢視 SQL> select a.name,b.name,b.path,b.voting_file from v$asm_disk b,v$asm_diskgroup a where a.group_number=b.group_number; [grid@rac1 ~]$ crsctl query css votedisk ## STATE File Universal Id File Name Disk group -- ----- ----------------- --------- --------- 1. ONLINE f161b94a350a4ff2bfecd933b9def84b (/dev/mapper/crs1) [CRS] 2. ONLINE 1572413690204f69bfcff159c9798cde (/dev/mapper/crs2) [CRS] 3. ONLINE a26dfe04ab4b4f5ebf89e362d897cd91 (/dev/mapper/crs3) [CRS] #刪除 [grid@rac1 ~]$ crsctl delete css votedisk a26dfe04ab4b4f5ebf89e362d897cd91 CRS-4258: Addition and deletion of voting files are not allowed because the voting files are on ASM (儲存在+ASM上,因此這裡刪不掉!) #新增 [grid@rac1 ~]$ crsctl add css votedisk +DATA CRS-4671: This command is not supported for ASM diskgroups. CRS-4000: Command Add failed, or completed with errors.
2.OCR檔案
1.OCR檔案用於純粹Clusterware及資料庫配置資訊 #檢視 OCR位置 [root@rac1 bin]# cat /etc/oracle/ocr.loc #Device/file +crs getting replaced by device +CRS/rac-cluster/OCRFILE/registry.255.1036255215 ocrconfig_loc=+CRS/rac-cluster/OCRFILE/registry.255.1036255215 #新增一個OCR [root@rac1 bin]# ./ocrconfig -add +DATA [root@rac1 bin]# cat /etc/oracle/ocr.loc #Device/file getting replaced by device +DATA/rac-cluster/OCRFILE/registry.255.1041202749 ocrconfig_loc=+CRS/rac-cluster/OCRFILE/registry.255.1036255215 ocrmirrorconfig_loc=+DATA/rac-cluster/OCRFILE/registry.255.104120274 #刪除一個OCR [root@rac1 bin]# ./ocrconfig -delete +DATA [root@rac1 bin]# cat /etc/oracle/ocr.loc #Device/file +DATA/rac-cluster/OCRFILE/registry.255.1041202749 being deleted ocrconfig_loc=+CRS/rac-cluster/OCRFILE/registry.255.1036255215 local_only=false[root@rac1 bin]# #遷移OCR [root@rac1 bin]# ./ocrconfig -replace +DATA -replacement +OCR #備份 #還原
3.管理叢集
https://www.cnblogs.com/-abm/p/9253594.html 1.srvctl srvctl status instance -d racdb -i racdb1 srvctl stop instance -d racdb -i racdb1,racdb2 srvctl start instance -d racdb -i racdb1,racdb2 srvctl status database -d racdb srvctl stop database -d racdb srvctl stop database -d racdb -o abort srvctl start database -d racdb srvctl start database -d racdb -o mount srvctl status listener srvctl start listener -n server1 srvctl start listener -n server1,server1 srvctl stop listener -n server1 srvctl stop listener -n server1,server1 srvctl status asm srvctl start asm -n server1 srvctl start asm -n server1,server1 srvctl stop asm -n server1 srvctl stop asm -n server1,server1 srvctl status diskgroup -g DATA srvctl status diskgroup -g DATA -n rac1 srvctl status diskgroup -g DATA -n rac1,rac2 srvctl stop diskgroup -g DATA -n rac1,rac2 srvctl stop diskgroup -g DATA -n rac1,rac2 -f #正在訪問的無法關閉 需要 -f 強制關閉 srvctl start diskgroup -g DATA -n rac1,rac2 srvctl status scan -i 1 srvctl status vip -i rac1-vip 通過enable、disable、remove、add等子命令可以對各種自由進行啟用、禁止、刪除、新增等操作 srvctl enable listener -l LISTENER -n rac1 srvctl disable listener -l LISTENER -n rac1 srvctl remove listener -l LISTENER srvctl add listener -l LISTENER -p 1521 -o /u01/app/oracle #檢視RAC網路配置中的網路配置 oifcfg getif #重啟叢集 在root下執行 # crsctl stop crs # crsctl start crs #檢查狀態 [root@rac1 bin]# ./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 [root@rac1 bin]# ./crsctl stop cluster -all [root@rac1 bin]# ./crsctl start cluster -all [root@swnode1 ]# crsctl stop cluster -all -----停止所有節點叢集服務 [root@swnode1 ]# crsctl stop cluster -------停止本節點叢集服務
4.asm
1.rac叢集中ASM例項有多個,但是引數檔案只有一個
#檢視磁碟組名稱、狀態、冗餘級別、空間情況
SQL> select name,state,type,total_mb,free_mb from v$asm_diskgroup;
#檢視磁碟組資訊
SQL> select group_number,path,state,total_mb,free_mb from v$asm_disk;
GROUP_NUMBER PATH STATE TOTAL_MB FREE_MB
------------ ------------------------------ -------- ---------- ----------
2 /dev/mapper/data1 NORMAL 512000 507456
1 /dev/mapper/crs3 NORMAL 102400 102092
3 /dev/mapper/data2 NORMAL 157344 157212
1 /dev/mapper/crs1 NORMAL 102400 102096
1 /dev/mapper/crs2 NORMAL 102400 102096
#查詢ASM例項對磁碟組訪問情況
SQL> select group_number,instance_name,db_name,status from v$asm_client;
GROUP_NUMBER INSTANCE_NAME DB_NAME STATUS
------------ ------------------------------ -------- ------------
0 +ASM1 racdb CONNECTED
2 +ASM1 racdb CONNECTED
#磁碟組中的磁碟數目發生改變時,asm將自動對其執行重新平衡。
#平衡能力從0~11分為12級別,0代表停止平衡。
SQL> alter diskgroup DATA rebalance power 3;
SQL> alter diskgroup DATA rebalance power 3 wait;
https://www.cnblogs.com/-abm/p/9253594.html
5.asmcmd
1.asmcmd可以管理ASM例項、ASM磁碟組、ASM磁碟組檔案及許可權
#ASM例項啟動關閉
ASMCMD> startup --nomount --pfile asm_init.ora
ASMCMD> shutdown
ASMCMD> shutdown --abort
#檢視引數檔案位置
ASMCMD> spget
+CRS/rac-cluster/ASMPARAMETERFILE/registry.253.1036255205
ASMCMD> spset +CRS/rac-cluster/ASMPARAMETERFILE/registry.253.1036255205
ASMCMD> spbackup +CRS/rac-cluster/ASMPARAMETERFILE/asmspfile.ora /u01/bakspfile,ora
ASMCMD> spcopy -u /u01/bakspfile,ora +DATA/testspfileASM.ora
ASMCMD> spmove /u01/bakspfile,ora +DATA/testspfileASM.ora
#通過ASMCMD管理ASM磁碟組
ASMCMD> lsdg
ASMCMD> lsdg DATA
ASMCMD> lsdg -G DATA
ASMCMD> lsdsk -G DATA
Path
/dev/mapper/data1
ASMCMD> lsdsk
Path
/dev/mapper/crs1
/dev/mapper/crs2
/dev/mapper/crs3
/dev/mapper/data1
/dev/mapper/data2
#擦看磁碟組磁碟的I/O資訊
ASMCMD> lsdsk --statistics -G DATA
ASMCMD> lsdsk --statistics
Reads Write Read_Errs Write_Errs Read_time Write_Time Bytes_Read Bytes_Written Voting_File Path
17 1 0 0 .034234 .012722 69632 4096 Y /dev/mapper/crs1
20 1 0 0 .02673 .012722 81920 4096 Y /dev/mapper/crs2
1178 1 0 0 1.254718 .012722 5713920 4096 Y /dev/mapper/crs3
25035 4094 0 0 81.738371 55.008746 424436736 64561152 N /dev/mapper/data1
1191 1 0 0 1.496498 .004282 5767168 4096 N /dev/mapper/data2
#解除安裝掛在磁碟
ASMCMD> mount -a #掛載所有
ASMCMD> mount DATA #掛載DATA
ASMCMD> unmount -a #解除安裝所有
ASMCMD> ummount DATA #解除安裝載DATA
#離線聯機
ASMCMD> offline -G DATA -D data_001 -t 2h 使磁碟組DATA中的 磁碟data_001離線
ASMCMD> online -G data -a
ASMCMD> online -G data -D data_001
#重新平衡
ASMCMD> rebal --power 4 data -w #-w 完成後返回提示符
ASMCMD> lsop #檢視當前進行的操作
#檢視磁碟IO情況(讀寫次數、資料量、時間、錯誤次數等)
ASMCMD> iostat -G DATA
Group_Name Dsk_Name Reads Writes
DATA DATA_0000 461677568 68122624
ASMCMD> iostat -t -G DATA
Group_Name Dsk_Name Reads Writes Read_Time Write_Time
DATA DATA_0000 463594496 68292096 89.275765 60.175445
ASMCMD> iostat -e -G DATA
Group_Name Dsk_Name Reads Writes Read_Err Write_Err
DATA DATA_0000 465019904 68466688 0 0
ASMCMD> iostat --io -G DATA
Group_Name Dsk_Name Reads Writes
DATA DATA_0000 27629 4374
#檔案操作
ASMCMD> alter diskgroup DATA drop file '+DATA/myfile.ora'
ASMCMD> find +DATA TEMP21.DBF
ASMCMD> find --type controlfile +data/oracl *
ASMCMD> cp +data/oracle.ora /u01/app/oracle/oracle.ora
ASMCMD> ls -lt +DATA
ASMCMD> ls --permission +DATA
User Group Permission Name
RACDB/
#檢視檔案被開啟的情況
ASMCMD> lsof -G DATA
DB_Name Instance_Name Path
racdb racdb1 +DATA/RACDB/86B637B62FE07A65E053F706E80A27CA/DATAFILE/sysaux.266.1036260421
racdb racdb1 +DATA/RACDB/86B637B62FE07A65E053F706E80A27CA/DATAFILE/system.265.1036260421
racdb racdb1 +DATA/RACDB/86B637B62FE07A65E053F706E80A27CA/DATAFILE/undotbs1.267.1036260421
racdb racdb1 +DATA/RACDB/A1E860D121B4CB2EE0538D01A8C0C35F/TEMPFILE/temp.268.1036260441
racdb racdb1 +DATA/RACDB/CONTROLFILE/current.261.1036260231
racdb racdb1 +DATA/RACDB/DATAFILE/sysaux.258.1036260147
racdb racdb1 +DATA/RACDB/DATAFILE/system.257.1036260113
racdb racdb1 +DATA/RACDB/DATAFILE/undotbs1.259.1036260161
racdb racdb1 +DATA/RACDB/DATAFILE/undotbs2.269.1036260699
racdb racdb1 +DATA/RACDB/DATAFILE/users.260.1036260163
racdb racdb1 +DATA/RACDB/ONLINELOG/group_1.262.1036260233
racdb racdb1 +DATA/RACDB/ONLINELOG/group_2.263.1036260233
racdb racdb1 +DATA/RACDB/ONLINELOG/group_3.270.1036260983
racdb racdb1 +DATA/RACDB/ONLINELOG/group_4.271.1036260985
racdb racdb1 +DATA/RACDB/TEMPFILE/temp.264.1036260243
叢集資料庫維護
6.叢集會話
#查詢當前連線例項
select instance_name,status,host_name from v$instance;
select * from v$active_instances;
#查詢會話
select * from v$session --查詢當前例項會話
alter system kill session '112,442' immediate;
select * from gv$session --查詢叢集會話
alter system kill session '112,442,@2' immediate; --刪除例項id為2的例項會話。
7.歸檔日誌
select a.group#,a.thread#, a.status,b.MEMBER from v$log a ,v$logfile b where a."GROUP#"=b."GROUP#"
alter database add logfile group 5; --當前例項
alter database add logfile instance 'racdb1' group 5;
alter database add logfile instance 'racdb2' group 6;
alter system switch logfile;
8.修改為歸檔模式
#1.設定歸檔路徑
alter system set log_archive_dest_1='location=+RECO/RACDB/ARCHIVE' scope=spfile sid='*';
#alter system set log_archive_format='arch%t_%s.%r'; # 設定歸檔檔案格式
#2.停止資料庫
srvctl stop database -d racdb
#3.檢查後臺狀態
crsctl stat res -t
#4.將一個節點資料庫啟動到mount狀態
srvctl start instance -d racdb -i racdb1 -o mount
#5.修改資料庫的歸檔模式並啟動資料庫
alter database archivelog;
alter database open;
#6.檢查狀態
archive log list;
#7.歸檔
alter system archive log current;
#8.啟動2節點資料庫
srvctl start instance -d racdb -i racdb2
9.立即歸檔
SQL> alter system archive log current;
SQL> alter system archive log instance 'racdb1' current;
SQL> alter system archive log instance 'racdb2' current;
SQL> alter system switch logfile;
SQL> alter system checkpoint local; # 當前例項資料庫發出檢查點
SQL> alter system checkpoint; # 所有例項資料庫發出檢查點
SQL> alter system checkpoint global; # 所有例項資料庫發出檢查點
10.表空間
SQL> select tablespace_name ,file_name from dba_data_files;
SQL> create tablespace TBS01;
SQL> create bigfile tablespace TBS02 datafile '+DATA';
SQL> create tablespace TBS03 datafile '+DATA' size 100M autoextend on next 10M maxsize 1024M;
SQL> select * from database_properties where property_name='DEFAULT_TBS_TYPE';
SQL> alter database set default bigfile tablespace; #修改為預設大檔案表空間
SQL> alter database set default smallfile tablespace; #修改為預設小檔案表空間
SQL> alter database default tablespace tbs01;
SQL> alter user scott default tablespace tbs02;
臨時表空間是多例項共享的,為了降低磁碟I/O衝突,提高資料庫效能,可以建立多個臨時表空間,把表空間放到一個表空間組,然後把這個表空間組作為資料庫預設臨時表空間。
SQL> alter tablespace temp tablespace group tmpgroup TMPG01;
SQL> create temporary tablespace temp1 tablespace group TMPG01;
SQL> create temporary tablespace temp2 tablespace group TMPG01;
SQL> alter database default temporary tablespace TMPG01;
在資料庫中,如果某個使用者資料庫使用者對資料進行類似排序的操作比較多,可以為這個使用者指定不同的預設臨時表空間,如果不指定,所有使用者都使用預設的臨時表空間。
SQL> create temporary tablespace temp04;
SQL> alter database default temporary tablespace temp04;
在資料庫中undo,每個例項都需要一個undo表空間。檢視當前例項使用的undo表空間
SQL> show parameter undo_tablespace;
SQL> create undo tablespace undotbs02;
SQL> alert system set undo_tablespace=undowtbs02;
*注意,初始化引數undo_tablespace引數修改只在當前例項起作用。
11.控制檔案
SQL> show parameter control_files;
SQL> select name, status from v$controlfile;
SQL> alter database backup controlfile to '/tmp/controlfileback.ctl';
SQL> alter database backup controlfile to trace;
# 新增一個控制檔案
# 需要在nomount狀態
SQL>select name,status from v$controlfile;
[root@rac1 bin]# ./srvctlstop database -d rac
[root@rac1 bin]# ./srvctl start database -d racdb -o nomount
[oracle@rac1~]$ rman target /
RAMN> restore controlfile to '+DATA' from '+DATA/RACDB/CONTROLFILE/Current.261.1036260231'
SQL> alter system set control_files='+DATA/RACDB/CONTROLFILE/Current.261.1036260231','+DATA/RACDB/CONTROLFILE/current.281.1041273331' scope=spfile;
SQL> shutdown immediate
[root@rac1 bin]# ./srvctl stop database -d racdb
[root@rac1 bin]# ./srvctl start database -d racdb
12.rman備份
RMAN>
run {
allocate channel ch1 device type disk format '/backup/%d_%U_%T_%s';
allocate channel ch2 device type disk format '/backup/%d_%U_%T_%s';
backup database plus archivelog;
sql 'alter system arhive log current';
release channel ch1;
release channel ch2;
}
RMAN> backup archivelog from time 'sysdate-30' until time 'sysdate-7';
RMAN> backup archivelog from sequence 121 until sqquence 125;
RMAN> backup archivelog from scn 1000 until scn 2000;
RMAN> backup archivelog all delete input; # 備份歸檔日誌,備份完成後刪除用於備份的複製
RMAN> backup archivelog all delete all input; # 備份歸檔日誌,備份完成後刪除所有的歸檔複製
RMAN>