ORACLE-19C DataGuard配置

一、安装数据库

参考文章ORACLE-19C 静默安装

IP

主机名

数据库名称

主库

xx.xx.xx.180

dbpri

orcl

备库

xx.xx.xx.181

dbstd

orcldg

二、操作配置

1、查看主库归档和附加日志配置

如下图,均未开启

sqlplus / as sysdba
SQL> selectlog_mode,force_logging from v$database;
ORACLE-19C DataGuard配置_第1张图片

2、开启归档模式

SQL> shutdown immediate; (立即关闭数据库)
SQL> startup mount; (启动实例并加载数据库,但不打开)
SQL> alter database archivelog; (更改数据库为归档模式)
SQL> alter database open; (打开数据库)
SQL> alter system archive log start; (启用自动归档)
SQL> select log_mode,force_logging from v$database; (查看)
ORACLE-19C DataGuard配置_第2张图片

3、开启主库附加日志

SQL> alter database force logging;
SQL> select log_mode,force_logging from v$database; (查看)
ORACLE-19C DataGuard配置_第3张图片

从Oracle Database 18c开始,引入了以下两个新的nologging子句,它们可以执行非日志记录操作,同时可以使ActiveData Guard备用数据库接收到所有数据,从而防止FORCE 方式生成大量重做日志导致性能下降。

STANDBY NOLOGGING FOR DATA AVAILABILITY 模式使批量加载操作通过其自身与备用数据库的连接将加载的数据发送到每个备用数据库。提交会延迟,直到所有ActiveData Guard备用数据库通过 recover 方式将数据应用完成。

SQL> alterdatabase set standby nologging for data availability;
SQL> selectlog_mode,force_logging from v$database;
ORACLE-19C DataGuard配置_第4张图片

STANDBY NOLOGGING FOR LOAD PERFORMANCE模式与先前的模式类似,不同之处在于,如果网络无法跟上数据加载到主数据库的速度,则加载过程可以停止将数据发送到备用数据库。在此模式下,备用数据库可能缺少数据,但每个Active Data Guard备用数据库都会在recover过程中自动从主数据库中提取数据。

SQL> alterdatabase set standby nologging for load performance;
SQL> selectlog_mode,force_logging from v$database;
ORACLE-19C DataGuard配置_第5张图片

4、查看主库归档目的地

SQL> archivelog list;
ORACLE-19C DataGuard配置_第6张图片

Archivedestination 归档目的地是一个路径,而非快速恢复区 USE_DB_RECOVERY_FILE_DEST

5、在主库中添加附加日志

# 查看日志路径
SQL> select group#,status,type,member from V$logfile order by 1;
ORACLE-19C DataGuard配置_第7张图片
# 添加附加日志
SQL> alterdatabase add standby logfile group 4 ('/u01/oradata/ORCL/stredo04.log') size200m;
SQL> alterdatabase add standby logfile group 5 ('/u01/oradata/ORCL/stredo05.log') size200m;
SQL> alterdatabase add standby logfile group 6 ('/u01/oradata/ORCL/stredo06.log') size200m;
SQL> alterdatabase add standby logfile group 7 ('/u01/oradata/ORCL/stredo07.log') size200m;
# 再次查询
SQL> select group#,status,type,member from V$logfile order by 1;
ORACLE-19C DataGuard配置_第8张图片

6、修改主库参数

# 列出主备库的DB_UNIQUE_NAME参数,默认情况下,定义该参数能确保主备库数据库能够互相识别对方 (通过show parameter name查询)
SQL> altersystem set LOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL,ORCLDG)';
SQL> alter system setLOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/product/19.3.0/dbhome_1/dbs/archVALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCL';   (因为archive log list;命令显示的是这个路径)
SQL> altersystem set LOG_ARCHIVE_DEST_2='SERVICE=ORCLDG ASYNCVALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLDG';
SQL> altersystem set REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE' scope=spfile;
SQL> altersystem set FAL_SERVER=ORCLDG;
SQL> altersystem set FAL_CLIENT=ORCL;
SQL> altersystem set DB_FILE_NAME_CONVERT='ORCLDG','ORCL' scope=spfile;
SQL> altersystem set LOG_FILE_NAME_CONVERT='ORCLDG','ORCL' scope=spfile;
SQL> altersystem set STANDBY_FILE_MANAGEMENT=AUTO;
SQL> quit

7、编辑主库 listener.ora 网络配置文件,添加连接主库点静态注册;

cd $ORACLE_HOME/network/admin
vi listener.ora
 
# listener.oraNetwork Configuration File:u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
# Generated byOracle configuration tools.
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST =dbpri)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
       (GLOBAL_DBNAME = orcl)
       (SID_NAME = orcl)
       (ORACLE_HOME =/u01/app/oracle/product/19.3.0/dbhome_1)
     )
   )

编辑 tnsnames.ora 文件

vi tnsnames.ora
 
# tnsnames.oraNetwork Configuration File:/u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora 
# Generated byOracle configuration tools.
LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST =dbpri)(PORT = 1521))
 
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =dbpri)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
 
ORCLDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =xxx.xxx.xxx.181)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcldg)
    )
  )

8、将主库中的网络文件输到备库

scp listener.ora tnsnames.ora [email protected]:/$ORACLE_HOME/network/admin

9、重建密码文件

orapwd file=$ORACLE_HOME/dbs/orapworcl password=Ora_19c1234 entries=10 ignoreCase=Y force=y

将密码文件传到备库

scp orapworcl [email protected]:/$ORACLE_HOME/dbs
:使用orapwd创建密码文件时,不必重启数据库,即可使用新密码以sysdba身份远程登陆数据库,且新密码可以不同于原来的sys密码。在忘记sys密码时,一种可行的方法是以操作系统方式登陆数据库,用alter user命令重新设置密码,也可以可以使用orapwd命令重置sys密码,这两种方法。

10、备库中创建对应路径: oracle 用户下

cd  /u01/app/oracle/
mkdir -p admin/ORCLDG/adump
mkdir -p oradata/ORCLDG
mkdir -p fast_recovery_area/ORCLDG

11、创建备库的参数文件

cd /u01/app/oracle/product/19.3.0/dbhome_1/dbs/
vi initORCLDG.ora
DB_NAME=ORCLDG

12、修改备库的listener.ora

# listener.oraNetwork Configuration File:u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
# Generated byOracle configuration tools.
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST =dbstd)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))
    )
  )
 
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
       (GLOBAL_DBNAME = orcloracle)
       (SID_NAME = orcldg)
       (ORACLE_HOME =/u01/app/oracle/product/19.3.0/dbhome_1)
     )
   )

13、修改备库的tnsnamaes.ora

# tnsnames.oraNetwork Configuration File:/u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora
# Generated byOracle configuration tools.
LISTENER_ORCLDG =
  (ADDRESS = (PROTOCOL = TCP)(HOST =dbstd)(PORT = 1521))
 
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =10.112.50.180)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
 
ORCLDG =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =dbstd)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcldg)
    )
  )

14、备库-启动辅助实例

[oracle@dbstd admin]$ export ORACLE_SID=orcldg    # 小写的,与 initorcldg.ora名称保持一致
[oracle@dbstdadmin]$ sqlplus / as sysdba
SQL> startup nomount;
SQL> quit;
ORACLE-19C DataGuard配置_第9张图片

15、使用复制数据库技术搭建备库

由于备库的文件路径包含ORCLDG,因此需要写明audit_file_dest,control_files参数(使用单引号也可以)

***备库执行**A*

rman targetsys/1%qw2azxs@ORCL auxiliary sys/1%qw2azxs
RMAN> 
2> DUPLICATE TARGETDATABASE
3> FOR STANDBY
4> FROM ACTIVE DATABASE
5> DORECOVER
6> SPFILE
7> SETDB_UNIQUE_NAME="ORCLDG" COMMENT "Is a dbstyle duplicate"
8> SETAUDIT_FILE_DEST="/u01/app/oracle/admin/ORCLDG/adump"
9> SETCONTROL_FILES='/u01/app/oracle/oradata/ORCLDG/control01.ctl','/u01/app/oracle/fast_recovery_area/SS19S/control02.ctl'
10> SETLOG_ARCHIVE_CONFIG="DG_CONFIG=(ORCLDG,ORCL)"
11> SETLOG_ARCHIVE_DEST_1="LOCATION=/u01/app/oracle/product/19.3.0/dbhome_1/dbs/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES)DB_UNIQUE_NAME=ORCLDG"
12> SETLOG_ARCHIVE_DEST_2="SERVICE=ORCL ASYNCVALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL"
13> SETDB_FILE_NAME_CONVERT="ORCL","ORCLDG" 
14> SETLOG_FILE_NAME_CONVERT="ORCL","ORCLDG" 
15> SETFAL_SERVER="ORCL" COMMENT "Is primary"
16> SETFAL_CLIENT="ORCLDG" COMMENT "Is standy"
17> SETSTANDBY_FILE_MANAGEMENT="AUTO"
18> NOFILENAMECHECK;

部分截图

ORACLE-19C DataGuard配置_第10张图片
ORACLE-19C DataGuard配置_第11张图片
ORACLE-19C DataGuard配置_第12张图片

16、进入备库验证角色信息

sqlplus / as sysdba
SQL> select database_role from v$database;
SQL> select instance_name from v$instance;
ORACLE-19C DataGuard配置_第13张图片

17、备库启动recover过程,应用主库传过来的日志(默认已经是real-time apply模式,因此省略using current logfile)

SQL> recovermanaged standby database disconnect from session;

18、查询v$dataguard_process视图,验证来自主库传输过来的日志过程和备库应用日志的情况(v$dataguard_process视图在12.2版本出现,取代了v$managed_standby);

SQL> selectrole,thread#,sequence#,action from v$dataguard_process;
ORACLE-19C DataGuard配置_第14张图片

19、 查询 v$archived_log视图,验证来自主库传输过来的日志变化情况,下面输出可以看到主库传输过来的日志在增加;多执行几次,看日志变化。

SQL> selectsequence#,applied from v$archived_log;

20、验证同步

方法一:最简单的方法,备库查看最新的归档日志是否apply,如果applied是yes则正常同步

主库 sqlplus>alter system switch logfile;
备库 sqlplus>select SEQUENCE#,applied,FIRST_TIME,NEXT_TIME  from v$archived_log order by 1 desc;
ORACLE-19C DataGuard配置_第15张图片

三、常见问题

  1. plsql 客户端连接备库报错 ORA-28040没有匹配的验证协议

解决办法:

# 备库配置文件
$ORACLE_HOME/network/admin/sqlnet.ora 
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
  1. 将从库执行alterd atabase open到打开状态 报错:ORA-10456:cannotopen standby database;media recovery session may be in progress

解决办法:

#1、先在从库停止standby
SQL>alter database recovermanaged standby database cancel;
SQL>alter database open;
#2、然后再启动日志应用
SQL>alter database recovermanaged standby database using current logfile disconnect;
  1. 备库执行查询操作时报错:ORA-01219:数据库或可插入数据库未打开: 仅允许在固定表或视图中查询

解决办法:

sqlplus  / as sysdba
alter session setcontainer=orclpdb1;   #切换到pdb
select open_mode from v$database;
alter database open;    # 执行该步骤的时候,可能报错ora-10456
select con_id,dbid,NAME,OPEN_MODEfromv$pdbs;
ORACLE-19C DataGuard配置_第16张图片

你可能感兴趣的:(oracle基础知识,dba,oracle,linux,数据库开发,数据库)