[root@primary ~]# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.5 (Final)
Release: 6.5
Codename: Final
2、DB Version:
SQL> select * from v$version;
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
PL/SQL Release 12.2.0.1.0 - Production 0
CORE 12.2.0.1.0 Production 0
TNS for Linux: Version 12.2.0.1.0 - Production 0
NLSRTL Version 12.2.0.1.0 - Production 0
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
3、实例名
Database DB_UNIQUE_NAME Oracle Net Service Name
Primariy orcl orcl
Primary standby orcls orcls
QL> col name for a10
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
---------- ----------
PDB$SEED READ ONLY
ORCLPDB READ WRITE
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
---------------------------------------
YES
2.启动归档模式
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/oracle/product/12.2.0/db_1/dbs/arch
Oldest online log sequence 23
Current log sequence 25
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 419430400 bytes
Fixed Size 8793496 bytes
Variable Size 297796200 bytes
Database Buffers 109051904 bytes
Redo Buffers 3788800 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/product/12.2.0/db_1/dbs/arch
Oldest online log sequence 23
Next log sequence to archive 25
Current log sequence 25
SQL> alter system set log_archive_dest_1='location=/data/oradata/orcl/archivelog';
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /data/oradata/orcl/archivelog
Oldest online log sequence 23
Next log sequence to archive 25
Current log sequence 25
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
---------- ----------
PDB$SEED READ ONLY
ORCLPDB MOUNTED
SQL> alter session set container=orclpdb;
Session altered.
SQL> alter database open;
Database altered.
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
---------- ----------
ORCLPDB READ WRITE
SQL> show parameter db_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_name string orcl
SQL> show parameter db_unique_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string orcl
SQL> show parameter log_archive_config
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_config string
SQL> alter system set log_archive_config='dg_config=(orcl,orcls)';
System altered.
SQL> alter system set log_archive_dest_2='service=orcls valid_for=(online_logfiles,primary_role) db_unique_name=orcls';
System altered.
SQL> alter system set log_archive_dest_state_1=enable;
System altered.
SQL> alter system set log_archive_dest_state_2=enable;
System altered.
SQL> alter system set standby_file_management='auto';
System altered.
SQL> alter system set fal_server='orcls';
System altered.
SQL> alter system set db_file_name_convert='/data/oradata/orcls','/data/oradata/orcl' scope=spfile;
System alterd
SQL> alter system set log_file_name_convert='/data/oradata/orcls','/data/oradata/orcl' scope=spfile;
System alterd
7.重启数据库使上面修改的参数生效
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 419430400 bytes
Fixed Size 8793496 bytes
Variable Size 297796200 bytes
Database Buffers 109051904 bytes
Redo Buffers 3788800 bytes
Database mounted.
Database opened.
SQL> alter session set container=orclpdb;
Session altered.
SQL> alter database open;
Database altered.
orcls:/home/oracle@standby>sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Mon Apr 9 14:49:50 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile='/u01/app/oracle/product/12.2.0/db_1/dbs/initorcls.ora'
7.验证监听和tns配置(一定要确保此步骤验证成功)
主库上执行:
orcl:/home/oracle@primary>sqlplus sys/oracle@orcl as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Mon Apr 9 15:48:26 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
orcl:/home/oracle@primary>sqlplus sys/oracle@orcls as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Mon Apr 9 15:48:30 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL>
备库上执行:
orcls:/home/oracle@standby>sqlplus sys/oracle@orcl as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Mon Apr 9 15:49:01 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
orcls:/home/oracle@standby>sqlplus sys/oracle@orcls as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Mon Apr 9 15:49:04 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Recovery Manager: Release 12.2.0.1.0 - Production on Mon Apr 9 14:51:49 2018
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1500334475)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby from active database;
Starting Duplicate Db at 2018/04/09 14:53:05
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=35 device type=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/12.2.0/db_1/dbs/orapworcl' auxiliary format
'/u01/app/oracle/product/12.2.0/db_1/dbs/orapworcls' ;
}
executing Memory Script
Starting backup at 2018/04/09 14:53:07
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=64 device type=DISK
Finished backup at 2018/04/09 14:53:09
contents of Memory Script:
{
restore clone from service 'orcl' standby controlfile;
}
executing Memory Script
Starting restore at 2018/04/09 14:53:09
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output file name=/data/oradata/orcls/control01.ctl
output file name=/data/oradata/orcls/control02.ctl
Finished restore at 2018/04/09 14:53:11
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
"/data/oradata/orcls/temp01.dbf";
set newname for tempfile 2 to
"/data/oradata/orcls/pdbseed/temp012018-04-04_09-49-41-872-AM.dbf";
set newname for tempfile 3 to
"/data/oradata/orcls/orclpdb/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/data/oradata/orcls/system01.dbf";
set newname for datafile 3 to
"/data/oradata/orcls/sysaux01.dbf";
set newname for datafile 4 to
"/data/oradata/orcls/undotbs01.dbf";
set newname for datafile 5 to
"/data/oradata/orcls/pdbseed/system01.dbf";
set newname for datafile 6 to
"/data/oradata/orcls/pdbseed/sysaux01.dbf";
set newname for datafile 7 to
"/data/oradata/orcls/users01.dbf";
set newname for datafile 8 to
"/data/oradata/orcls/pdbseed/undotbs01.dbf";
set newname for datafile 9 to
"/data/oradata/orcls/orclpdb/system01.dbf";
set newname for datafile 10 to
"/data/oradata/orcls/orclpdb/sysaux01.dbf";
set newname for datafile 11 to
"/data/oradata/orcls/orclpdb/undotbs01.dbf";
set newname for datafile 12 to
"/data/oradata/orcls/orclpdb/users01.dbf";
restore
from nonsparse from service
'orcl' clone database
;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /data/oradata/orcls/temp01.dbf in control file
renamed tempfile 2 to /data/oradata/orcls/pdbseed/temp012018-04-04_09-49-41-872-AM.dbf in control file
renamed tempfile 3 to /data/oradata/orcls/orclpdb/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
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 2018/04/09 14:53:17
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /data/oradata/orcls/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /data/oradata/orcls/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /data/oradata/orcls/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /data/oradata/orcls/pdbseed/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /data/oradata/orcls/pdbseed/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /data/oradata/orcls/users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /data/oradata/orcls/pdbseed/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /data/oradata/orcls/orclpdb/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /data/oradata/orcls/orclpdb/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:08
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /data/oradata/orcls/orclpdb/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orcl
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00012 to /data/oradata/orcls/orclpdb/users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2018/04/09 14:54:11
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=4 STAMP=973004052 file name=/data/oradata/orcls/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=973004052 file name=/data/oradata/orcls/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=973004052 file name=/data/oradata/orcls/undotbs01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=7 STAMP=973004052 file name=/data/oradata/orcls/pdbseed/system01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=8 STAMP=973004052 file name=/data/oradata/orcls/pdbseed/sysaux01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=9 STAMP=973004052 file name=/data/oradata/orcls/users01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=10 STAMP=973004052 file name=/data/oradata/orcls/pdbseed/undotbs01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=11 STAMP=973004052 file name=/data/oradata/orcls/orclpdb/system01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=12 STAMP=973004052 file name=/data/oradata/orcls/orclpdb/sysaux01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=13 STAMP=973004052 file name=/data/oradata/orcls/orclpdb/undotbs01.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=14 STAMP=973004052 file name=/data/oradata/orcls/orclpdb/users01.dbf
Finished Duplicate Db at 2018/04/09 14:54:21
9.打开备库并并启动apply
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED MOUNTED
3 ORCLPDB MOUNTED
SQL> alter database open;
Database altered.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB MOUNTED
SQL> alter pluggable database orclpdb open;
Pluggable database altered.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ ONLY NO
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;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
10.验证DG
在主库上创建一个table并插入一行数据
SQL> select log_mode,open_mode ,database_role from v$database;
LOG_MODE OPEN_MODE DATABASE_ROLE
------------ -------------------- ----------------
ARCHIVELOG READ ONLY WITH APPLY PHYSICAL STANDBY
QL> alter session set container=orclpdb;
Session altered.
SQL> create table test(id int);
Table created.
SQL> insert into test values(1);
1 row created.
SQL> commit;
Commit complete.
备库上查询
SQL> alter session set container=orclpdb;
Session altered.
SQL> select * from test;
ID
----------
1