ADG搭建 基本款(主备完全一致)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ADG搭建 基本款(主备完全一致)相关的知识,希望对你有一定的参考价值。

参考技术A 主库:192.168.204.101

备库:192.168.204.109

软件安装路径主备库一样

SID主备库一样

主库已安装软件+实例

备库已安装软件

******************************

1.主库

强制归档模式

SQL> alter database force logging;

Database altered.

-----------------------------------------------------------------

创建standby redolog日志组:

首先查看有多少日志组:

SQL> select thread#,group#,bytes/1024/1024 from v$log;

  THREAD#    GROUP# BYTES/1024/1024

---------- ---------- ---------------

        1          1              50

        1          2              50

        1          3              50

SQL> select * from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                                                                              IS_

---------- ------- ------- ---------------------------------------------------------------------------------------------------- ---

        1        ONLINE  /home/oracle/oracleData/oracle/oradata/hrdb/redo01.log                                              NO

        2        ONLINE  /home/oracle/oracleData/oracle/oradata/hrdb/redo02.log                                              NO

        3        ONLINE  /home/oracle/oracleData/oracle/oradata/hrdb/redo03.log                                              NO

其次添加日志组:

SQL> alter database add standby logfile group 4('/home/oracle/oracleData/oracle/oradata/hrdb/redo04.log') size 50m;

alter database add standby logfile group 5('/home/oracle/oracleData/oracle/oradata/hrdb/redo05.log') size 50m;

alter database add standby logfile group 6('/home/oracle/oracleData/oracle/oradata/hrdb/redo06.log') size 50m;

alter database add standby logfile group 7('/home/oracle/oracleData/oracle/oradata/hrdb/redo07.log') size 50m;

Database altered.

SQL>

Database altered.

SQL>

Database altered.

SQL>

Database altered.

--------------------------------------------------------------

密码文件创建

orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle force=y

---------------------------------------------------------------

修改LISTENER和TNSNAMES

LISTENER添加静态监听

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = hrdb)

      (ORACLE_HOME = /home/oracle/oracleData/oracle/product/11.2.0/db_1)

      (SID_NAME = hrdb)

    )

  )

TNSNAME

HRPRI =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.204.101)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = hrdb)

    )

  )

HRSTY =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.204.109)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = hrdb)

    )

  )

LISTENER和TNSNAMES和密码文件SCP至备库

listener因为主备库是完全一样的路径,可以不用修改

TNSNAMES,也不用修改

---------------------------------------------

备库:

启动监听

[oracle@localhost admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-FEB-2021 18:20:12

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

Starting /home/oracle/oracleData/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production

System parameter file is /home/oracle/oracleData/oracle/product/11.2.0/db_1/network/admin/listener.ora

Log messages written to /home/oracle/oracleData/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                    LISTENER

Version                  TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                24-FEB-2021 18:20:13

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level              off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File  /home/oracle/oracleData/oracle/product/11.2.0/db_1/network/admin/listener.ora

Listener Log File        /home/oracle/oracleData/oracle/diag/tnslsnr/localhost/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Services Summary...

Service "hrdb" has 1 instance(s).

  Instance "hrdb", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

**************************************************

2.验证联通性

主备库都做

主库:

[oracle@localhost admin]$ tnsping hrdb   自己!

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 24-FEB-2021 18:21:55

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

Used parameter files:

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdb)))

OK (0 msec)

[oracle@localhost admin]$ tnsping hrpri    还是自己!

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 24-FEB-2021 18:22:01

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

Used parameter files:

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.204.101)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdb)))

OK (0 msec)

[oracle@localhost admin]$ tnsping hrsty    对方!

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 24-FEB-2021 18:22:06

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

Used parameter files:

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.204.109)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdb)))

OK (10 msec)

备库:

[oracle@localhost admin]$ tnsping hrdb  自己!

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 24-FEB-2021 18:23:00

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

Used parameter files:

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdb)))

OK (0 msec)

[oracle@localhost admin]$ tnsping hrpri  对方!

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 24-FEB-2021 18:23:08

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

Used parameter files:

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.204.101)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdb)))

OK (0 msec)

[oracle@localhost admin]$ tnsping hrsty  自己!

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 24-FEB-2021 18:23:14

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

Used parameter files:

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.204.109)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hrdb)))

OK (0 msec)

************************************

3.PFILE修改

SQL> show parameter spfile

NAME                                TYPE        VALUE

------------------------------------ ----------- ------------------------------

spfile                              string      /home/oracle/oracleData/oracle

                                                /product/11.2.0/db_1/dbs/spfil

                                                ehrdb.ora

SQL> create pfile from spfile;

File created.

pfile增加以下内容:

*.db_unique_name='hr_pri'

*.fal_server='hr_sty'

*.fal_client='hr_pri'

*.log_archive_config='dg_config=(hr_pri,hr_sty)'

*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=hr_pri'

*.log_archive_dest_2='service=hrsty LGWR ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=hr_sty'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='ENABLE'

修改后要应用PFILE,一般是要重启

--------------

将修改后的pfile scp至备库,并进行以下修改

*.db_unique_name='hr_sty'

*.fal_server='hr_pri'

*.fal_client='hr_sty'

*.log_archive_config='dg_config=(hr_pri,hr_sty)'

*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=hr_sty'

*.log_archive_dest_2='service=hrsty LGWR ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=hr_pri'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='ENABLE'

-----------

再根据pfile文件中的各路径进行mkdir

mkdir -p /home/oracle/oracleData/oracle/admin/hrdb/adump

mkdir -p /home/oracle/oracleData/oracle/oradata/hrdb/

mkdir -p /home/oracle/oracleData/oracle/fast_recovery_area/hrdb/

********************************

开始进行数据复制

rman target sys/oracle@hrpri auxiliary sys/oracle@hrsty

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Feb 24 19:03:27 2021

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

connected to target database: HRDB (DBID=2567911892)

connected to auxiliary database: HRDB (not mounted)

一定要是not mounted

****************

duplicate target database for standby from active database nofilenamecheck;

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

Starting Duplicate Db at 24-FEB-21

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=19 device type=DISK

contents of Memory Script:



  backup as copy reuse

  targetfile  '/home/oracle/oracleData/oracle/product/11.2.0/db_1/dbs/orapwhrdb' auxiliary format

'/home/oracle/oracleData/oracle/product/11.2.0/db_1/dbs/orapwhrdb'  ;



executing Memory Script

Starting backup at 24-FEB-21

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=39 device type=DISK

Finished backup at 24-FEB-21

contents of Memory Script:



  backup as copy current controlfile for standby auxiliary format  '/home/oracle/oracleData/oracle/oradata/hrdb/control01.ctl';

  restore clone controlfile to  '/home/oracle/oracleData/oracle/fast_recovery_area/hrdb/control02.ctl' from

'/home/oracle/oracleData/oracle/oradata/hrdb/control01.ctl';



executing Memory Script

Starting backup at 24-FEB-21

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

copying standby control file

output file name=/home/oracle/oracleData/oracle/product/11.2.0/db_1/dbs/snapcf_hrdb.f tag=TAG20210224T190415 RECID=1 STAMP=1065380656

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 24-FEB-21

Starting restore at 24-FEB-21

using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: copied control file copy

Finished restore at 24-FEB-21

contents of Memory Script:



  sql clone 'alter database mount standby database';



executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:



  set newname for tempfile  1 to

"/home/oracle/oracleData/oracle/oradata/hrdb/temp01.dbf";

  switch clone tempfile all;

  set newname for datafile  1 to

"/home/oracle/oracleData/oracle/oradata/hrdb/system01.dbf";

  set newname for datafile  2 to

"/home/oracle/oracleData/oracle/oradata/hrdb/sysaux01.dbf";

  set newname for datafile  3 to

"/home/oracle/oracleData/oracle/oradata/hrdb/undotbs01.dbf";

  set newname for datafile  4 to

"/home/oracle/oracleData/oracle/oradata/hrdb/users01.dbf";

  set newname for datafile  5 to

"/home/oracle/oracleData/oracle/oradata/hrdb/t01.dbf";

  set newname for datafile  6 to

"/home/oracle/oracleData/oracle/oradata/hrdb/hrtbs01.dbf";

  backup as copy reuse

  datafile  1 auxiliary format

"/home/oracle/oracleData/oracle/oradata/hrdb/system01.dbf"  datafile

2 auxiliary format

"/home/oracle/oracleData/oracle/oradata/hrdb/sysaux01.dbf"  datafile

3 auxiliary format

"/home/oracle/oracleData/oracle/oradata/hrdb/undotbs01.dbf"  datafile

4 auxiliary format

"/home/oracle/oracleData/oracle/oradata/hrdb/users01.dbf"  datafile

5 auxiliary format

"/home/oracle/oracleData/oracle/oradata/hrdb/t01.dbf"  datafile

6 auxiliary format

"/home/oracle/oracleData/oracle/oradata/hrdb/hrtbs01.dbf"  ;

  sql 'alter system archive log current';



executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /home/oracle/oracleData/oracle/oradata/hrdb/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 24-FEB-21

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001 name=/home/oracle/oracleData/oracle/oradata/hrdb/system01.dbf

output file name=/home/oracle/oracleData/oracle/oradata/hrdb/system01.dbf tag=TAG20210224T190423

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/home/oracle/oracleData/oracle/oradata/hrdb/sysaux01.dbf

output file name=/home/oracle/oracleData/oracle/oradata/hrdb/sysaux01.dbf tag=TAG20210224T190423

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/home/oracle/oracleData/oracle/oradata/hrdb/undotbs01.dbf

output file name=/home/oracle/oracleData/oracle/oradata/hrdb/undotbs01.dbf tag=TAG20210224T190423

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15

channel ORA_DISK_1: starting datafile copy

input datafile file number=00005 name=/home/oracle/oracleData/oracle/oradata/hrdb/t01.dbf

output file name=/home/oracle/oracleData/oracle/oradata/hrdb/t01.dbf tag=TAG20210224T190423

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03

channel ORA_DISK_1: starting datafile copy

input datafile file number=00006 name=/home/oracle/oracleData/oracle/oradata/hrdb/hrtbs01.dbf

output file name=/home/oracle/oracleData/oracle/oradata/hrdb/hrtbs01.dbf tag=TAG20210224T190423

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/home/oracle/oracleData/oracle/oradata/hrdb/users01.dbf

output file name=/home/oracle/oracleData/oracle/oradata/hrdb/users01.dbf tag=TAG20210224T190423

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 24-FEB-21

sql statement: alter system archive log current

contents of Memory Script:



  switch clone datafile all;



executing Memory Script

datafile 1 switched to datafile copy

input datafile copy RECID=1 STAMP=1065380737 file name=/home/oracle/oracleData/oracle/oradata/hrdb/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=2 STAMP=1065380737 file name=/home/oracle/oracleData/oracle/oradata/hrdb/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=3 STAMP=1065380737 file name=/home/oracle/oracleData/oracle/oradata/hrdb/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=4 STAMP=1065380737 file name=/home/oracle/oracleData/oracle/oradata/hrdb/users01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=5 STAMP=1065380737 file name=/home/oracle/oracleData/oracle/oradata/hrdb/t01.dbf

datafile 6 switched to datafile copy

input datafile copy RECID=6 STAMP=1065380737 file name=/home/oracle/oracleData/oracle/oradata/hrdb/hrtbs01.dbf

Finished Duplicate Db at 24-FEB-21

********

alter database recover managed standby database disconnect from session;

ADG 误删除system01.dbf故障处理

一、描述
11.2.0.4单实例主备库,主库system01.dbf误删除,导致数据库启动失败。

二、现象
SQL> startup
ORACLE instance started.

Total System Global Area 3089920000 bytes
Fixed Size 2257232 bytes
Variable Size 654315184 bytes
Database Buffers 2415919104 bytes
Redo Buffers 17428480 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: ‘/oradata/devdb/system01.dbf‘

三、处理过程

  1. 停备库,传输数据文件
    scp system01.dbf 1xx.55.3.xx:/oradata/devdb/
  2. 启动主库、恢复数据文件
    SQL> startup
    ORACLE instance started.

Total System Global Area 3089920000 bytes
Fixed Size 2257232 bytes
Variable Size 654315184 bytes
Database Buffers 2415919104 bytes
Redo Buffers 17428480 bytes
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: ‘/oradata/devdb/system01.dbf‘

SQL> recover database;
Media recovery complete.
SQL> alter database open;

Database altered.

3.启动备库、启用恢复进程
SQL> startup
SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

SQL> select process,status from v$managed_standby;

PROCESS STATUS


ARCH CLOSING
ARCH CONNECTED
ARCH CONNECTED
ARCH CLOSING
RFS IDLE
RFS IDLE
RFS IDLE
MRP0 APPLYING_LOG

8 rows selected.

以上是关于ADG搭建 基本款(主备完全一致)的主要内容,如果未能解决你的问题,请参考以下文章

ORA-01110 ORA-01111 ORA-01157主备库数据文件路径路径不一致,备库开启ADG应用报错(一切都是套路)

Oracle公有云上的ADG配置(单实例)

Oracle 11g R2 ADG 搭建

11g adg 环境搭建实施手册-0824

Oracle11g ADG 搭建

oracle11g ADG主备切换