1. 準備
安裝兩臺單實例11G,主庫安裝數據庫,備庫只安裝軟件。
實例名稱 orclpri orclsla
2. 配置hosts文件(主備庫都配置)
vi /etc/hosts
192.168.100.110 dg_pri
192.168.100.111 dg_sla
3. 主庫設置為force logging模式
SQL> alter database force logging;
SQL>select force_logging from v$database;
4. 主庫修改為歸檔模式
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog; //開啟歸檔模式
SQL> alter database noarchivelog; //關閉歸檔模式
SQL> alter system set log_archive_dest_1=location=/data/archive scope=spfile; //修改歸檔路徑
SQL> archive log list;
5. 添加主庫的standby redo log
主庫添加 standby redo log:大小和 online redo 相同,比 online redo group 多一組。
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 (/data/oracle/oradata/orclpri/redo04.log) size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 (/data/oracle/oradata/orclpri/redo05.log) size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 (/data/oracle/oradata/orclpri/redo06.log) size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 7 (/data/oracle/oradata/orclpri/redo07.log) size 50M;
SQL>select group#,type,member from v$logfile;
6. 創建 Listener 并配置靜態注冊(主備庫都做)
主庫:
[oracle@dg_pri dbs]$ cd /data/oracle/product/11.2.0/db_1/network/admin/
[oracle@dg_pri admin]$ vi listener.ora
# listener.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orclpri)
(ORACLE_HOME = /data/oracle/product/11.2.0/db_1)
(SID_NAME = orclpri)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.110)(PORT = 1521))
)
ADR_BASE_LISTENER = /data/oracle
[oracle@dg_pri admin]$ vi tnsnames.ora
ORCL_PRI=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.110)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orclpri)
)
)
ORCL_SLA=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.111)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orclsla)
)
)
備庫:
[oracle@dg_sla ~]$ cd /data/oracle/product/11.2.0/db_1/network/admin/
[oracle@dg_sla admin]$ vi listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orclsla)
(ORACLE_HOME = /data/oracle/product/11.2.0/db_1)
(SID_NAME = orclsla)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.111)(PORT = 1521))
)
ADR_BASE_LISTENER = /data/oracle
[oracle@dg_sla admin]$ vi tnsnames.ora
ORCL_PRI=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.110)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orclpri)
)
)
ORCL_SLA=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.111)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orclsla)
)
)
主備庫使用tnsping測試是否相同
[oracle@dg_pri admin]$tnsping ORCL_PRI
[oracle@dg_pri admin]$tnsping ORCL_SLA
重啟監聽
lsnrctl stop
lsnrctl start
7. 在備庫創建相關的目錄
oracle用戶創建:
mkdir -p /data/archive
mkdir -p /data/oracle/admin
mkdir -p /data/oracle/oradata
mkdir -p /data/oracle/fast_recovery_area/orclsla
mkdir -p /data/oracle/fast_recovery_area/orclsla/onlinelog
mkdir -p /data/oracle/oradata/orclsla
mkdir -p /data/oracle/admin/orclsla
mkdir -p /data/oracle/admin/adump
mkdir -p /data/oracle/admin/orclsla/adump
mkdir -p /data/oracle/admin/orclsla/dpdump
mkdir -p /data/oracle/admin/orclsla/pfile
mkdir -p /data/oracle/admin/orclsla/scripts
mkdir -p /data/oracle/admin/orclpri/adump
8. 在主庫創建 pfile 文件并修改pfile 內容
主庫:
SQL> create pfile=/home/oracle/pfile from spfile;
在/home/oracle/pfile新增下內容
*.db_unique_name=orclpri
*.log_archive_config=dg_config=(orclpri,orclsla)
*.log_archive_dest_1=location=/data/archive valid_for=(all_logfiles,all_roles) db_unique_name=orclpri
*.log_archive_dest_2=service=orcl_sla valid_for=(online_logfiles,primary_role) db_unique_name=orclsla
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
*.standby_file_management=auto
*.fal_server=orcl_sla
*.fal_client=orcl_pri
*.log_file_name_convert=/data/oracle/oradata/orclpri,/data/oracle/oradata/orclsla
*.db_file_name_convert= /data/oracle/oradata/orclpri,/data/oracle/oradata/orclsla
SQL> shutdown immediate
SQL>create spfile from pfile=/home/oracle/pfile;
SQL> shutdown abort;
SQL> startup
備庫:
將主庫的參數文件copy到備庫到修改
scp /home/oracle/pfile 192.168.100.111:/data/oracle/product/11.2.0/db_1/dbs
*.db_unique_name=orclsla
*.log_archive_config=dg_config=(orclpri,orclsla)
*.log_archive_dest_1=location=/data/archive valid_for=(all_logfiles,all_roles) db_unique_name=orclsla
*.log_archive_dest_2=service=orcl_pri valid_for=(online_logfiles,primary_role) db_unique_name=orclpri
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
*.standby_file_management=MANUAL
*.fal_server=orcl_pri
*.fal_client=orcl_sla
*.log_file_name_convert=/data/oracle/oradata/orclpri,/data/oracle/oradata/orclsla
*.db_file_name_convert= /data/oracle/oradata/orclpri,/data/oracle/oradata/orclsla
SQL> startup nomount; //可能會出現LRM-00109,根據提示的文件名修改剛才拷貝的參數文件名字
SQL> alter system set log_archive_dest_1 = location=/data/archive valid_for=(all_logfiles,all_roles) db_unique_name=orclsla scope=spfile; //nomount啟動報ORA-16024錯誤時用此方法修改,先注釋參數文件log_archive_dest_1這一行,然后nomount啟動執行此修改命令。nomount正常啟動則不需要執行
SQL> create spfile from pfile=/data/oracle/product/11.2.0/db_1/dbs/initorclsla.ora;
SQL> shutdown abort;
SQL> startup nomount;
9. 拷貝密碼文件
[root@dg_pri ~]# cd /data/oracle/product/11.2.0/db_1/dbs/
[root@dg_pri dbs]#scp orapworclpri 192.168.100.111:/data/oracle/product/11.2.0/db_1/dbs
修改密碼文件名:mv orapworclpri orapworclsla
10. 使用rman同步數據文件
[oracle@dg_pri dbs]$ rman target sys/123456@orcl_pri auxiliary sys/123456@orcl_sla;
RMAN>duplicate target database for standby from active database;
11. 開啟備庫并驗證 數據是否能同步
備庫:
SQL> alter database recover managed standby database cancel; #取消實時同步
SQL> shutdown immediate
SQL> startup mount
SQL> alter database flashback on; #開始flashback閃回
SQL> alter database open read only; #只讀open數據庫
SQL> alter database recover managed standby database using current logfile disconnect from session; #開始實時同步
主庫:
create table test(id int);
備庫:
select * from test;--有這邊就說明搭建成功
查看主備庫狀態
SQL>select switchover_status,database_role from v$database;
查看日志
[root@dg_sla ~]# cd /data/oracle/diag/rdbms/orclsla/orclsla/trace
[root@dg_sla trace]# cat alert_orclsla.log
[root@dg_sla trace]# ls -lrt *arc1*
備庫啟動步驟:先啟備庫再啟主庫
startup nomount;
掛載數據庫
alter database mount standby database;
啟用應用重做
alter database recover managed standby database disconnect from session;
取消備庫的自動恢復
alter database recover managed standby database cancel;
啟動到只讀狀態
alter database open read only;
在“READ ONLY”狀態下進一步啟動備庫的恢復,實時應用主庫日志。
alter database recover managed standby database using current logfile disconnect;
更多精彩干貨分享
點擊下方名片關注
IT那活兒
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/129766.html
摘要:最近工作中用到了作為測試的數據庫,在裝和折騰了很久,這篇文章就這兩點對大家分享一些我安裝過程中遇到的問題和注意點,暫時還未配置,稍后找時間補上現在網上找一篇好的文章好難,往往要在一個話題或技術上找多方資源東拼西湊,互相借鑒才能達成目的,原因 最近工作中用到了Oracle作為Intel測試的數據庫,在裝Oracle Linux和Oracle Database 11g R2折騰了很久,這...
閱讀 1347·2023-01-11 13:20
閱讀 1685·2023-01-11 13:20
閱讀 1133·2023-01-11 13:20
閱讀 1860·2023-01-11 13:20
閱讀 4101·2023-01-11 13:20
閱讀 2705·2023-01-11 13:20
閱讀 1386·2023-01-11 13:20
閱讀 3598·2023-01-11 13:20