Oracle搭建一主两备dataguard环境的详细步骤

news2024/12/24 9:56:54

​ 上一篇文章介绍了Oracle一主两备的DG环境,如何进行switchover切换,也许你会问Oracle一主两备dataguard环境要怎么搭建,本篇文章将为你讲述一主两备dataguard详细搭建步骤。

环境说明

主机名IP地址db_unique_name数据库角色
ora11g10.10.10.160ora11g主库
ora11gdg10.10.10.41dgora11g备库1
ora11gdg210.10.10.47sbora11g备库2

说明:10.10.10.160为主库,10.10.10.41和10.10.10.47都是它的备库。

主库配置

主库打开归档

–确认数据库开启归档,如未开启归档,请开启归档。

sys@ora11g> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       /u01/oradata/archivelog
Oldest online log sequence     307
Next log sequence to archive   313
Current log sequence	       313

--如未开启归档,请打开
startup mount;
alter system set log_archive_dest_1='location=/u01/oradata/archivelog' scope=both;
alter database archivelog;
alter database open;

主库打开数据强制日志

--开启强制日志
alter database force logging;
--查询实例的归档模式和附加日志
sys@ora11g> select log_mode,force_logging from v$database;

LOG_MODE     FOR
------------ ---
ARCHIVELOG   YES

添加standby log

standby redolog的组数参考公式:(online redolog组数 + 1) * 数据库线程数;单机线程数为1,RAC一般为2。

--主库查出大小
select  group#,thread#,bytes/1024/1024 M from  v$log;

--添加standby log
alter database add standby logfile thread 1 group 4 '/u01/oradata/ora11g/stdredo01.log' size 50M; 
alter database add standby logfile thread 1 group 5 '/u01/oradata/ora11g/stdredo02.log' size 50M;
alter database add standby logfile thread 1 group 6 '/u01/oradata/ora11g/stdredo03.log' size 50M; 
alter database add standby logfile thread 1 group 7 '/u01/oradata/ora11g/stdredo04.log' size 50M; 

sys@ora11g> select group#,thread#,sequence#,archived,status from v$standby_log;

    GROUP#    THREAD#  SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------
	 4	    1	       0 YES UNASSIGNED
	 5	    1	       0 YES UNASSIGNED
	 6	    1	       0 YES UNASSIGNED
	 7	    1	       0 YES UNASSIGNED


主库配置tnsnames.ora

主库:
vi tnsnames.ora
ORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.160)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ora11g)
    )
  )

DGORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.41)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dgora11g)
    )
  )

SBORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.47)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sbora11g)
    )
  )

主库配置DG相关参数

alter system set log_archive_config='DG_CONFIG=(ora11g,dgora11g,sbora11g)' scope=both sid='*';
alter system set log_archive_dest_1='location=/u01/oradata/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=ora11g' scope=both sid='*';
alter system set log_archive_dest_2='SERVICE=dgora11g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=dgora11g' scope=both sid='*';
alter system set log_archive_dest_3='SERVICE=sbora11g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=sbora11g' scope=both sid='*';
alter system set fal_server='dgora11g','sbora11g' scope=both sid='*';
alter system set fal_client='ora11g' scope=both sid='*';
alter system set standby_file_management=auto scope=both sid='*';
--alter system set log_archive_dest_state_2=defer scope=both sid='*';
alter system set log_archive_dest_state_2=enable scope=both sid='*';
--alter system set log_archive_dest_state_3=defer scope=both sid='*';
alter system set log_archive_dest_state_3=enable scope=both sid='*';
alter system set db_file_name_convert='/u01/oradata/dgora11g','/u01/oradata/ora11g','/u01/oradata/sbora11g','/u01/oradata/ora11g' scope=spfile sid='*';
alter system set log_file_name_convert='/u01/oradata/dgora11g','/u01/oradata/ora11g','/u01/oradata/sbora11g','/u01/oradata/ora11g' scope=spfile sid='*';

#db_file_name_convert、log_file_name_convert需要重启数据库才能生效,若生产不能马上重启,需要找停机窗口重启,不影响后续的dg同步。

#####查看修改是否生效
set linesize 500 pages 1000
col value for a100
col name for a50
select name, value
from v$parameter
where name in ('db_name','db_unique_name',
'log_archive_config',
'log_archive_dest_1',
'log_archive_dest_2',
'log_archive_dest_3',
'log_archive_dest_state_1',
'log_archive_dest_state_2',
'log_archive_dest_state_3',
'remote_login_passwordfile',
'log_archive_format',
'log_archive_max_processes',
'fal_server',
'fal_client',
'db_file_name_convert',
'log_file_name_convert',
'standby_file_management')
/


NAME						   VALUE
-------------------------------------------------- ----------------------------------------------------------------------------------------------------
db_file_name_convert				   /u01/oradata/dgora11g, /u01/oradata/ora11g, /u01/oradata/sbora11g, /u01/oradata/ora11g
log_file_name_convert				   /u01/oradata/dgora11g, /u01/oradata/ora11g, /u01/oradata/sbora11g, /u01/oradata/ora11g
log_archive_dest_1				   location=/u01/oradata/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=ora11g
log_archive_dest_2				   SERVICE=dgora11g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=dgora11g
log_archive_dest_3				   SERVICE=sbora11g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=sbora11g
log_archive_dest_state_1			   ENABLE
log_archive_dest_state_2			   ENABLE
log_archive_dest_state_3			   ENABLE
fal_client					   ora11g
fal_server					   dgora11g, sbora11g
log_archive_config				   DG_CONFIG=(ora11g,dgora11g,sbora11g)
log_archive_format				   %t_%s_%r.dbf
log_archive_max_processes			   4
standby_file_management 			   AUTO
remote_login_passwordfile			   EXCLUSIVE
db_name 					   ora11g
db_unique_name					   ora11g

17 rows selected.

拷贝主库的pfile文件和密码文件到备库

创建主库pfil文件,并将pfile文件和密码文件复制到备1和备2

create pfile='/home/oracle/initbak0808.bak' from spfile;

$ scp orapwora11g 10.10.10.41:/u01/app/oracle/product/11.2.0/db/dbs/orapwdgora11g
$ scp orapwora11g 10.10.10.47:/u01/app/oracle/product/11.2.0/db/dbs/orapwsbora11g

备库1配置

第一个备库(10.10.10.41)

静态监听配置

$ cat listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER=
(SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = dgora11g)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
      (SID_NAME = dgora11g)
    )
)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = ora11gdg)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

启动监听

$ lsnrctl start
$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 12-AUG-2024 14:57:07

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                12-AUG-2024 10:49:21
Uptime                    0 days 4 hr. 7 min. 46 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/ora11gdg/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gdg)(PORT=1521)))
Services Summary...
Service "dgora11g" has 2 instance(s).
  Instance "dgora11g", status UNKNOWN, has 1 handler(s) for this service...
  Instance "dgora11g", status READY, has 1 handler(s) for this service...
Service "ora11g" has 1 instance(s).
  Instance "dgora11g", status READY, has 1 handler(s) for this service...
Service "ora11gXDB" has 1 instance(s).
  Instance "dgora11g", status READY, has 1 handler(s) for this service...
The command completed successfully

tnsnames.ora配置

$ cat tnsnames.ora 
ORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.160)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ora11g)
    )
  )

DGORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.41)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dgora11g)
    )
  )
  
SBORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.47)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sbora11g)
    )
  )

修改pfile

$ cat ora11gdg.txt 
*.audit_file_dest='/u01/app/oracle/admin/dgora11g/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_file_record_keep_time=31
*.control_files='/u01/oradata/dgora11g/control01.ctl','/u01/app/oracle/fast_recovery_area/dgora11g/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='/u01/oradata/ora11g','/u01/oradata/dgora11g'
*.db_files=5000
*.db_name='ora11g'
*.db_recovery_file_dest_size=5368709120
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_unique_name='dgora11g'
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ora11gXDB)'
*.enable_ddl_logging=TRUE
*.event='28401 trace name context forever,level 1','10949 trace name context forever,level 1'
*.fal_client='dgora11g'
*.fal_server='ora11g'
*.log_archive_config='DG_CONFIG=(ora11g,dgora11g)'
*.log_archive_dest_1='location=/u01/oradata/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=dgora11g'
*.log_archive_dest_2='SERVICE=ora11g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=ora11g'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s_%r.dbf'
*.log_file_name_convert='/u01/oradata/ora11g','/u01/oradata/dgora11g'
*.open_cursors=1000
*.parallel_max_servers=64
*.pga_aggregate_target=924844032
*.processes=2000
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_limit=TRUE
*.resource_manager_plan='force:'
*.sec_case_sensitive_logon=FALSE
*.service_names='ora11g'
*.session_cached_cursors=300
*.sga_max_size=3700424704
*.sga_target=3700424704
*.standby_file_management='AUTO'
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'

##主要修改DG相关的参数,及添加db_unique_name、service_names

启动到nomount状态

--创建相关目录
[oracle@ora11gdg:~]$ mkdir -p /u01/app/oracle/admin/dgora11g/adump
[oracle@ora11gdg:~]$ mkdir -p /u01/oradata/dgora11g
[oracle@ora11gdg:~]$ mkdir -p /u01/app/oracle/fast_recovery_area/dgora11g
[oracle@ora11gdg:~]$ mkdir -p /u01/oradata/dgora11g
[oracle@ora11gdg:~]$ mkdir -p /u01/oradata/archivelog

--启动到nomount状态
[oracle@ora11gdg:~]$ export ORACLE_SID=dgora11g
[oracle@ora11gdg:~]$ env|grep SID
ORACLE_SID=dgora11g
[oracle@ora11gdg:~]$ sqlplus / as sysdba
SQL> startup nomount pfile='/home/oracle/ora11gdg.txt';
ORACLE instance started.

Total System Global Area 3691200512 bytes
Fixed Size		    2258680 bytes
Variable Size		 1392511240 bytes
Database Buffers	 2281701376 bytes
Redo Buffers		   14729216 bytes
SQL> create spfile from pfile='/home/oracle/ora11gdg.txt';

rman duplicate创建备库

rman target sys/oracle@ORA11G auxiliary sys/oracle@DGORA11G
RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;

需要限速时,用以下命令:
run {
allocate channel c1 type disk rate 200M;
allocate channel c2 type disk rate 200M;
allocate channel c3 type disk rate 200M;
allocate auxiliary channel st1 type disk rate 200M;
allocate auxiliary channel st2 type disk rate 200M;
allocate auxiliary channel st3 type disk rate 200M;
duplicate target database for standby from active database nofilenamecheck dorecover;
release channel c1;
release channel c2;
release channel c3;
release channel st1;
release channel st2;
release channel st3;
}

开启同步

SQL> select open_mode from v$database;

OPEN_MODE
------------------------------------------------------------
MOUNTED

SQL> alter database open;

Database altered.


SQL> select log_mode,open_mode ,database_role from v$database;

LOG_MODE OPEN_MODE DATABASE_ROLE
--------------- --------------- --------------------
ARCHIVELOG READ ONLY PHYSICAL STANDBY

SQL>alter database recover managed standby database using current logfile disconnect from session;

sys@dgora11g> select log_mode,open_mode ,database_role from v$database;

LOG_MODE     OPEN_MODE		  DATABASE_ROLE
------------ -------------------- ----------------
ARCHIVELOG   READ ONLY WITH APPLY PHYSICAL STANDBY

--查看同步情况
col error for a50;
set linesize 400;
select status,error,gap_status from v$archive_dest_status;

select severity,error_code,to_char(timestamp,'DD-MON-YYYY HH24:MI:SS') "timestamp" , message from v$dataguard_status where dest_id=2;

set linesize 400;
select 'thread:' || a.thread# || ',primary sequence:' || b.max_available || ',primary sequence:' ||
       a.max_applied , b.max_available - a.max_applied log_gap 
  from (select thread#, max(sequence#) max_applied
          from gv$archived_log
         where applied = 'YES'
         group by thread#) a,
       (select thread#, max(sequence#) max_available
          from gv$archived_log
         group by thread#) b
 where a.thread# = b.thread#;

备库2配置

第二个备库(10.10.10.47)

静态监听配置

$ cat listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER=
(SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = sbora11g)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
      (SID_NAME = sbora11g)
    )
)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = ora11gdg2)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

启动监听

$ lsnrctl start
$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 08-AUG-2024 16:54:52

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))

STATUS of the LISTENER

Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                08-AUG-2024 16:37:43
Uptime                    0 days 0 hr. 17 min. 8 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/ora11gdg2/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gdg2)(PORT=1521)))
Services Summary...
Service "ora11g" has 1 instance(s).
  Instance "sbora11g", status BLOCKED, has 1 handler(s) for this service...
Service "sbora11g" has 2 instance(s).
  Instance "sbora11g", status UNKNOWN, has 1 handler(s) for this service...
  Instance "sbora11g", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully

tnsnames.ora 配置

$ cat tnsnames.ora 
ORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.160)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ora11g)
    )
  )

DGORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.41)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dgora11g)
    )
  )
  
SBORA11G =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.47)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sbora11g)
    )
  )

修改pfile

$ cat sbora11g.txt 
*.audit_file_dest='/u01/app/oracle/admin/sbora11g/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_file_record_keep_time=31
*.control_files='/u01/oradata/sbora11g/control01.ctl','/u01/app/oracle/fast_recovery_area/sbora11g/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_file_name_convert='/u01/oradata/ora11g','/u01/oradata/sbora11g'
*.db_files=5000
*.db_name='ora11g'
*.db_recovery_file_dest_size=5368709120
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_unique_name='sbora11g'
*.deferred_segment_creation=FALSE
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ora11gXDB)'
*.enable_ddl_logging=TRUE
*.event='28401 trace name context forever,level 1','10949 trace name context forever,level 1'
*.fal_client='sbora11g'
*.fal_server='ora11g'
*.log_archive_config='DG_CONFIG=(ora11g,sbora11g)'
*.log_archive_dest_1='location=/u01/oradata/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=sbora11g'
*.log_archive_dest_2='SERVICE=ora11g LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=ora11g'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_format='%t_%s_%r.dbf'
*.log_file_name_convert='/u01/oradata/ora11g','/u01/oradata/sbora11g'
*.open_cursors=1000
*.parallel_max_servers=64
*.pga_aggregate_target=924844032
*.processes=2000
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_limit=TRUE
*.resource_manager_plan='force:'
*.sec_case_sensitive_logon=FALSE
*.service_names='ora11g'
*.session_cached_cursors=300
*.sga_max_size=3700424704
*.sga_target=3700424704
*.standby_file_management='AUTO'
*.undo_retention=10800
*.undo_tablespace='UNDOTBS1'

##主要修改DG相关的参数,及添加db_unique_name、service_names

启动到nomount状态

--创建相关目录
[oracle@ora11gdg2:~]$ mkdir -p /u01/app/oracle/admin/sbora11g/adump
[oracle@ora11gdg2:~]$ mkdir -p /u01/oradata/sbora11g
[oracle@ora11gdg2:~]$ mkdir -p /u01/app/oracle/fast_recovery_area/sbora11g
[oracle@ora11gdg2:~]$ mkdir -p /u01/oradata/sbora11g
[oracle@ora11gdg2:~]$ mkdir -p /u01/oradata/archivelog

--启动到nomount状态
[oracle@ora11gdg2:~]$ export ORACLE_SID=sbora11g
[oracle@ora11gdg2:~]$ env|grep SID
ORACLE_SID=sbora11g
[oracle@ora11gdg2:~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 8 16:51:37 2024

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile='/home/oracle/sbora11g.txt';
ORACLE instance started.

Total System Global Area 3691200512 bytes
Fixed Size		    2258680 bytes
Variable Size		 1392511240 bytes
Database Buffers	 2281701376 bytes
Redo Buffers		   14729216 bytes
SQL> create spfile from pfile='/home/oracle/sbora11g.txt';

rman duplicate创建备库

$ rman target sys/oracle@ORA11G auxiliary sys/oracle@SBORA11G

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Aug 8 16:58:17 2024

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORA11G (DBID=260591189)
connected to auxiliary database: ORA11G (not mounted)

RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;

需要限速时,用以下命令:
run {
allocate channel c1 type disk rate 200M;
allocate channel c2 type disk rate 200M;
allocate channel c3 type disk rate 200M;
allocate auxiliary channel st1 type disk rate 200M;
allocate auxiliary channel st2 type disk rate 200M;
allocate auxiliary channel st3 type disk rate 200M;
duplicate target database for standby from active database nofilenamecheck dorecover;
release channel c1;
release channel c2;
release channel c3;
release channel st1;
release channel st2;
release channel st3;
}

开启同步

SQL> select open_mode from v$database;

OPEN_MODE
------------------------------------------------------------
MOUNTED

SQL> alter database open;

Database altered.


SQL> select log_mode,open_mode ,database_role from v$database;

LOG_MODE OPEN_MODE DATABASE_ROLE
--------------- --------------- --------------------
ARCHIVELOG READ ONLY PHYSICAL STANDBY

SQL>alter database recover managed standby database using current logfile disconnect from session;

sys@sbora11g > select log_mode,open_mode ,database_role from v$database;

LOG_MODE     OPEN_MODE		  DATABASE_ROLE
------------ -------------------- ----------------
ARCHIVELOG   READ ONLY WITH APPLY PHYSICAL STANDBY

--查看同步情况
col error for a50;
set linesize 400;
select status,error,gap_status from v$archive_dest_status;

select severity,error_code,to_char(timestamp,'DD-MON-YYYY HH24:MI:SS') "timestamp" , message from v$dataguard_status where dest_id=2;

set linesize 400;
select 'thread:' || a.thread# || ',primary sequence:' || b.max_available || ',primary sequence:' ||
       a.max_applied , b.max_available - a.max_applied log_gap 
  from (select thread#, max(sequence#) max_applied
          from gv$archived_log
         where applied = 'YES'
         group by thread#) a,
       (select thread#, max(sequence#) max_available
          from gv$archived_log
         group by thread#) b
 where a.thread# = b.thread#;

同步测试

–主库创建表插入测试数据

sys@sbora11g > create table tt0812 as select * from dba_objects;

Table created.

–两备库查询

sys@dgora11g> select count(*) from tt0812;  

  COUNT(*)
----------
     86269
 sys@sbora11g >  select count(*) from tt0812;

  COUNT(*)
----------
     86269
  

至此主从切换已完成,新主库应与两从库正常同步。

后续工作

–创建数据库启动服务

# cat /etc/oratab
# cat /etc/init.d/oracle 
#!/bin/bash
#
#################FUNCTION#############
#
# AutoStart Oracle and listener Using dbstart
# AutoStop Oracle and listener Using dbstop
#
#####################################
#
#chkconfig: 345 99 10
#description: script for the Oracle Instance, Listener 


source /home/oracle/.bash_profile
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db
LOG=/var/log/oracle.log


case "$1" in
start)
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> $LOG 2>&1
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> $LOG 2>&1
su - oracle -c "$ORACLE_HOME/bin/dbstart" >> $LOG 2>&1
echo "Done."
date +" %T %a %D : Finished." >> $LOG 2>&1
echo "-------------------------------------------------" >> $LOG 2>&1
touch /var/lock/subsys/oracle
echo "Recovering Oracle Databases ... "
su - oracle -c 'sqlplus -s / as sysdba <<EOF
   whenever sqlerror exit sql.sqlcode;
   set echo off
   set heading off
   host echo "Database open mode is:" 
   select open_mode from v\$database;
   host echo "Recovering Oracle Databases......"
   ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
   host echo "Database open mode is:"
   select open_mode from v\$database;


   exit;
EOF
'
;;
stop)
echo "Stopping Oracle Databases ... "
echo "-------------------------------------------------" >> $LOG 2>&1
date +" %T %a %D : Stopping Oracle Databases as part of system down." >> $LOG 2>&1
su - oracle -c "$ORACLE_HOME/bin/dbshut" >> $LOG 2>&1
echo "Done."
date +" %T %a %D : Finished." >> $LOG 2>&1
echo "-------------------------------------------------" >> $LOG 2>&1
rm -f /var/lock/subsys/oracle


;;
restart)
$0 stop
$0 start


;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac

# chmod +x /etc/init.d/oracle
# chkconfig --add oracle
cat /etc/oratab

sbora11g:/u01/app/oracle/product/11.2.0/db:Y

cat /etc/init.d/oracle 

#!/bin/bash
#
#################FUNCTION#############
#

AutoStart Oracle and listener Using dbstart

AutoStop Oracle and listener Using dbstop

#
#####################################

#
#chkconfig: 345 99 10
#description: script for the Oracle Instance, Listener 


source /home/oracle/.bash_profile
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db
LOG=/var/log/oracle.log


case "$1" in
start)
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> $LOG 2>&1
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> $LOG 2>&1
su - oracle -c "$ORACLE_HOME/bin/dbstart" >> $LOG 2>&1
echo "Done."
date +" %T %a %D : Finished." >> $LOG 2>&1
echo "-------------------------------------------------" >> $LOG 2>&1
touch /var/lock/subsys/oracle
echo "Recovering Oracle Databases ... "
su - oracle -c 'sqlplus -s / as sysdba <<EOF
   whenever sqlerror exit sql.sqlcode;
   set echo off
   set heading off
   host echo "Database open mode is:" 
   select open_mode from v\$database;
   host echo "Recovering Oracle Databases......"
   ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
   host echo "Database open mode is:"
   select open_mode from v\$database;


   exit;
EOF
'
;;
stop)
echo "Stopping Oracle Databases ... "
echo "-------------------------------------------------" >> $LOG 2>&1
date +" %T %a %D : Stopping Oracle Databases as part of system down." >> $LOG 2>&1
su - oracle -c "$ORACLE_HOME/bin/dbshut" >> $LOG 2>&1
echo "Done."
date +" %T %a %D : Finished." >> $LOG 2>&1
echo "-------------------------------------------------" >> $LOG 2>&1
rm -f /var/lock/subsys/oracle


;;
restart)
$0 stop
$0 start

;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac

# chmod +x /etc/init.d/oracle
# chkconfig --add oracle

–备库配置归档删除脚本

$ cat /home/oracle/scripts/del_arch.sh 
#!/bin/bash
source ~/.bash_profile
deltime=$(date +"20%y%m%d%H%M%S")
rman target / nocatalog msglog /home/oracle/scripts/del_arch_$deltime.log <<-EOF
crosscheck archivelog all;
delete noprompt archivelog until time 'sysdate-7';
delete noprompt force archivelog until time 'SYSDATE-10';
EOF

关注我,学习更多的数据库知识!
请添加图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2036429.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

驱动数智化升级,AI大模型准备好了吗?

大数据产业创新服务媒体 ——聚焦数据 改变商业 AI大模型的快速崛起&#xff0c;为企业带来了前所未有的变革机遇。从自然语言处理到图像识别&#xff0c;从精准营销到智能制造&#xff0c;AI大模型正逐步渗透到各行各业的核心业务中。然而&#xff0c;随着技术的不断演进&…

力扣刷题-循环队列

&#x1f308;个人主页&#xff1a;羽晨同学 &#x1f4ab;个人格言:“成为自己未来的主人~” 思路&#xff1a; 我们在这里采用的是用数组的形式实现循环链表&#xff0c;我认为这个用数组是更为简单的&#xff0c;我们只需要控制下标就可以实现循环链表的效果。具体实现代…

Python数据可视化案例——折线图

目录 json介绍&#xff1a; Pyecharts介绍 安装pyecharts包 构建一个基础的折线图 配置全局配置项 综合案例&#xff1a; 使用工具对数据进行查看 &#xff1a; 数据处理 json介绍&#xff1a; json是一种轻量级的数据交互格式&#xff0c;采用完全独立于编程语言的文…

2024 该学前端还是学后端?

2024 该学前端还是学后端&#xff1f; 现状分析pragmatic-drag-and-drop后端开发 现状分析 对于这个问题&#xff0c;个人作为Java后端开发者&#xff0c;那么当然是比较熟悉Java后端开发&#xff0c;从这么久的工作体验来说&#xff0c;因为个人也是比较熟悉Java后端&#xf…

【第19章】Spring Cloud之Gateway自定义Logback配置

文章目录 前言一、内置配置1. 关联依赖2. 内置配置 二、自定义配置1. 日志级别2. 彩色日志3. 自定义配置4. 增加打印语句5. 效果展示 总结 前言 网关层作为我们程序的主入口&#xff0c;有着至关重要的作用&#xff0c;下面我们通过自定义Logback配置增强网关层的日志输出&…

【实用工具】Stirling-PDF入门安装教程: 优质开源的PDF处理工具/编辑工具

文章目录 项目简介功能展示Page Operations 页面操作Conversion Operations 转换操作Security & Permissions 安全与权限Other Operations 其他业务 如何安装并使用Docker RunDocker Compose 项目简介 这是一款使用 Docker 的基于本地托管网络的强大 PDF 操作工具。它能让…

2024年翻译工具新风尚:实时翻译与精准度并进

语言交流的障碍随着全球化的不断深入日益成为连接不同文化和国家的挑战。然而&#xff0c;在科技日新月异的今天&#xff0c;类似谷歌翻译这样的工具正在高速发展这。这次我们来一起探讨深受用户喜欢的翻译工具有哪些。 1.福昕在线翻译 链接直达&#xff1a;https://fanyi.pd…

贷齐乐系统最新版SQL注入(绕过WAF可union select跨表查询)

目录 标题&#xff1a;贷齐乐系统最新版SQL注入&#xff08;绕过WAF可union select跨表查询&#xff09; 内容&#xff1a; 一&#xff0c;环境部署 二&#xff0c;源码分析 三&#xff0c;sql注入 总结&#xff1a; [回到顶部]&#xff08;#article_top&#xff09; 一&am…

Linux使用学习笔记1到2 命令行与shell 基础运维命令

在学习使用ubuntu等各种喜他构建服务器的过程中遇到很多问题&#xff0c;意识到只是跟着网络的教程没办法管理好一个完整的应用部署和运行。遂开始学习linux基本知识&#xff0c;以应对服务器常见问题和软件的使用和维护。 shell 望文生义&#xff0c;大概意思是一个外壳&…

交错字符串[中等]

优质博文&#xff1a;IT-BLOG-CN 一、题目 给定三个字符串s1、s2、s3&#xff0c;请你帮忙验证s3是否是由s1 和s2交错 组成的。 两个字符串s和t交错 的定义与过程如下&#xff0c;其中每个字符串都会被分割成若干 非空 子字符串&#xff1a; s s1 s2 ... sn t t1 t2 …

数据结构---单链表实现

单链表是什么 我的理解是“特殊的数组”&#xff0c;通过访问地址来连接起来 1怎么创建链表 ----通过结构体&#xff08;成员有存入数据的data和指向下一个节点的地址的指针&#xff08;结构体指针&#xff09;next 初始架构---DataType 对应存入数据类型&#xff0c;此处的N…

一款基于Java外卖配送系统,专为多商户入驻设计,包含用户端、商家端、配送端以及总管理后台(附源码)

前言 在当前的外卖配送市场中&#xff0c;软件系统的状态常常面临一些挑战&#xff0c;例如多商户管理复杂性、用户体验不一致、后端服务的稳定性和安全性等。这些痛点不仅影响了商户和用户的满意度&#xff0c;也限制了平台的扩展性和发展潜力。 为了解决这些现状&#xff0…

B站搜索建库架构优化实践

前言 搜索是B站的重要基础功能&#xff0c;需要对包括视频、评论、图文等海量的站内优质资源建立索引&#xff0c;处理来自用户每日数亿的检索请求。离线索引数据的正确、高效产出是搜索业务的基础。我们在这里分享搜索离线架构整体的改造实践&#xff1a;从周期长&#xff0c;…

【论文阅读】BoT-SORT: Robust Associations Multi-Pedestrian Tracking

题目&#xff1a;BoT-SORT: Robust Associations Multi-Pedestrian Tracking 作者&#xff1a;Nir Aharon* Roy Orfaig Ben-Zion Bobrovsky motivation: 作者来得很直接&#xff0c;就说他们用相机运动模型和优化卡尔曼做了个可以解决具有挑战的跟踪问题的算法:BOT-SORT;说他们…

工程数学线性代数(同济大学数学系)第六版(更新中)

第1章 行列式 2 全排列和对换 一、排列及其逆序数 全排列 1个逆序、逆序数 奇排列&#xff0c;偶排列 二、对换 对换&#xff1a;排列中任意两个元素对调 相邻对换&#xff1a;相邻两个元素对换 对换改变排列的奇偶性。 4 行列式的性质 5 行列式按行&#xff08;列&…

有趣的的rce漏洞复现分析

目录 无字母数字绕过正则表达式 解读代码 解题思路 异或 或 取反 无字母数字绕过正则表达式 首先我们依然是搭建环境&#xff08;环境依然是Ubuntu下部署&#xff0c;和之前的漏洞环境一样&#xff09; <?php error_reporting(0); highlight_file(__FILE__); $code…

<数据集>车间工人、安全帽、安全背心识别<目标检测>

数据集格式&#xff1a;VOCYOLO格式 图片数量&#xff1a;3465张 标注数量(xml文件个数)&#xff1a;3465 标注数量(txt文件个数)&#xff1a;3465 标注类别数&#xff1a;3 标注类别名称&#xff1a;[person, helmet, vest] 序号类别名称图片数框数1person346594732helm…

Android 13 GMS 内置壁纸

如图&#xff0c;原生系统上&#xff0c;设备上的壁纸 显示系统内置壁纸。如果没有添加内置壁纸&#xff0c;就显示默认的壁纸。点击进去就是预览页面 扩展下&#xff0c;默认壁纸在 frameworks/base/core/res/res/drawable-sw720dp-nodpi/default_wallpaper.png frameworks/b…

云开发微信小程序--即时聊天(单人聊天,多人聊天室)

云开发微信小程序–即时聊天 介绍&#xff1a;本小程序包含欢迎界面&#xff0c;注册&#xff0c;登录&#xff0c;一对一聊天&#xff0c;群聊&#xff0c;好友添加请求验证过程&#xff0c;修改好友备注以及删除好友&#xff0c;退出群聊&#xff0c;特殊角色卡片展示&#…

Android中的EventBus的用法

1. EventBus简介 EventBus是一个优化了的事件发布/订阅模式实现的库&#xff0c;常用于Android程序组件间的通信。它可以简化不同组件之间的通信工作&#xff0c;避免复杂和耦合的依赖关系。EventBus通过事件驱动来降低代码耦合度&#xff0c;提高开发效率和代码清晰性。 2. …