您的位置:首页 > 数据库 > Oracle

第一次 Oracle 单实例DG搭建(个人记录以纪念,文章中错误很多,来者三思)

2018-01-06 04:25 656 查看
教程参阅 http://blog.csdn.net/shiyu1157758655/article/details/72878249
测试环境:

 

 

主机1(主库)

主机2(备库)

操作系统

Centos6.5 64位

Rhel 5.8 64位

主机名

sannetocp

gyl

IP

192.168.152.133

192.168.152.88

数据库软件版本

oracle 11.2.0.4

oracle 11.2.0.4

ORACLE_BASE

/u01/app/oracle

/u01/app/oracle

ORACLE_HOME

/u01/app/oracle/product/11.2.0/dbhome_1

/u01/app/oracle/product/11.2.0/db

ORACLE_SID

ocp

 

闪回区

开启

 

归档

开启

 

 

 

 

 

 

1.1更改为强制日志切换

在DataGuard环境中,为了减少故障时数据损失,我们可以设置ARCHIVE_LAG_TARGET参数,强制进行日志切换。

SYS@ocp> selectlog_mode,force_logging from v$database;

 

LOG_MODE     FOR

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

ARCHIVELOG   NO

 

SYS@ocp> ALTERDATABASE FORCE LOGGING;

 

Database altered.

 

SYS@ocp> selectlog_mode,force_logging from v$database;

 

LOG_MODE     FOR

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

ARCHIVELOG   YES

 

 

1.2 创建备库日志文件

首先查询主库的

SYS@ocp> selectgroup#,bytes/1024/1024 from v$log;

 

    GROUP# BYTES/1024/1024

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

 1                50

 2                50

 3                50

 

SYS@ocp> selectmember from v$logfile;

 

MEMBER

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

/database/ocp/redo03.log

/database/ocp/redo02.log

/database/ocp/redo01.log

 

创建standby日志组的个数是原日志组个数+1再与thread的积,size不能小于原日志文件的大小。

alter database addstandby logfile '/database/ocp/standby01.log' size 50m;

alter database addstandby logfile '/database/ocp/standby02.log' size 50m;

alter database addstandby logfile '/database/ocp/standby03.log' size 50m;

alter database addstandby logfile '/database/ocp/standby04.log' size 50m;

 

具体步骤:

SYS@ocp> alterdatabase add standby logfile '/database/ocp/standby01.log' size 50m;

 

Database altered.

 

SYS@ocp> alterdatabase add standby logfile '/database/ocp/standby02.log' size 50m;

 

Database altered.

 

SYS@ocp> alterdatabase add standby logfile '/database/ocp/standby03.log' size 50m;

 

Database altered.

 

SYS@ocp> alterdatabase add standby logfile '/database/ocp/standby04.log' size 50m;

 

Database altered.

 

SYS@ocp> selectmember from v$logfile;

 

MEMBER

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

/database/ocp/redo03.log

/database/ocp/redo02.log

/database/ocp/redo01.log

/database/ocp/standby01.log

/database/ocp/standby02.log

/database/ocp/standby03.log

/database/ocp/standby04.log

 

7 rows selected.

 

1.3 确认已经开启数据库闪回

SYS@ocp> selectlog_mode,open_mode,flashback_on from v$database;

 

LOG_MODE    OPEN_MODE                  FLASHBACK_ON

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

ARCHIVELOG   READ WRITE          NO

 

 

1.4修改参数文件

SYS@ocp>alter system set log_archive_config='DG_CONFIG=(ocp,oca)';

 

System altered.

 

SYS@ocp>altersystem set log_archive_dest_2='SERVICE=ocaVALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=oca' scope=spfile;

 

 

SYS@ocp> altersystem set log_archive_dest_state_1='enable';

 

System altered.

 

SYS@ocp> altersystem set log_archive_dest_state_2='enable';

 

System altered.

 

SYS@ocp>altersystem set db_file_name_convert='/database/ocp','/database/ocp' scope=spfile;

 

System altered.

 

SYS@ocp> altersystem set log_file_name_convert='/database/ocp','/database/ocp'scope=spfile;

 

System altered.

 

SYS@ocp>alter system set fal_server='ocp';

 

System altered.

 

SYS@ocp>alter system set fal_client='oca';

 

System altered.

 

SYS@ocp> altersystem set standby_file_management='AUTO';

 

System altered.

 

 

由于上述生效需要重启,所以重启数据库

SYS@ocp> shutdownimmediate

Database closed.

Database dismounted.

ORACLE instance shutdown.

SYS@ocp>

SYS@ocp>

SYS@ocp> startup

ORACLE instancestarted.

 

Total System GlobalArea 1235959808 bytes

FixedSize                    2252784 bytes

VariableSize                  419430416 bytes

DatabaseBuffers          805306368 bytes

RedoBuffers                    8970240 bytes

Database mounted.

Database opened.

 

 

修改监听文件

oracle@sannetocp ~]$vim /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

 

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

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

      (ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))

    )

  )

 

 

SID_LIST_LISTENER =

 (SID_LIST =

   (SID_DESC =

     (GLOBAL_DBNAME = ocp)

     (ORACLE_HOME =/u01/app/oracle/product/11.2.0/dbhome_1)

     (SID_NAME = ocp)

    )

   )

 

 

修改TNS配置文件:

[root@sannetocporacle]# vim /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

 

 

 

OCP =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ocp)

    )

  )

 

 

oca =

  (DESCRIPTION =

   
4000
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.152.88)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = oca)

    )

  )

 

 

重启监听:

[oracle@sannetocporadata]$ lsnrctl stop

 

LSNRCTL for Linux:Version 11.2.0.4.0 - Production on 05-JAN-2018 15:42:40

 

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

 

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

The commandcompleted successfully

[oracle@sannetocporadata]$ lsnrctl start

 

LSNRCTL for Linux:Version 11.2.0.4.0 - Production on 05-JAN-2018 15:42:45

 

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

 

Starting/u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...

 

TNSLSNR for Linux:Version 11.2.0.4.0 - Production

System parameterfile is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

Log messages writtento /u01/app/oracle/diag/tnslsnr/sannetocp/listener/alert/log.xml

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

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

 

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

STATUS of theLISTENER

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

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version11.2.0.4.0 - Production

Start Date                05-JAN-2018 15:42:45

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener ParameterFile  /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

Listener LogFile        /u01/app/oracle/diag/tnslsnr/sannetocp/listener/alert/log.xml

Listening EndpointsSummary...

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

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

Services Summary...

Service"ocp" has 1 instance(s).

  Instance "ocp", status UNKNOWN, has1 handler(s) for this service...

The commandcompleted successfully

 

 

 

 

File created.

 

拷贝参数文件和密码文件

SYS@ocp>create pfile from  spfile;

 

File created.

 

scp /tmp/initocp.ora192.168.182.88:/u01/app/oracle/product/11.2.0/db/dbs

 

 

 修改参数文件

[oracle@gyl dbs]$vim initocp.ora

 

 

 

ocp.__db_cache_size=889192448

ocp.__java_pool_size=16777216

ocp.__large_pool_size=33554432

ocp.__oracle_base='/u01/app/oracle'#ORACLE_BASEset from environment

ocp.__pga_aggregate_target=419430400

ocp.__sga_target=1241513984

ocp.__shared_io_pool_size=0

ocp.__shared_pool_size=285212672

ocp.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/oca/adump'

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='/database/ocp/control01.ctl','/u01/app/oracle/fast_recovery_area/oca/control02.ctl'#RestoreControlfile

*.db_block_size=8192

*.db_domain=''

*.db_file_name_convert='/database/ocp','/database/oca'

*.db_name='ocp'

*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'

*.db_recovery_file_dest_size=4385144832

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP)(SERVICE=ocaXDB)'

*.fal_client='oca'

*.fal_server='ocp'

*.job_queue_processes=1000

*.log_archive_config='DG_CONFIG=(oca,ocp)'

*.log_archive_dest_1='location=/home/oracle/arch'

*.log_archive_dest_2='SERVICE=ocpVALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ocp'

*.log_archive_dest_3='location=/home/oracle/arch2'

*.log_archive_dest_state_1='enable'

*.log_archive_dest_state_2='enable'

*.log_file_name_convert='/database/oca','/database/ocp'

*.open_cursors=300

*.pga_aggregate_target=411041792

*.processes=200

*.remote_login_passwordfile='EXCLUSIVE'

*.resource_manager_plan='PLAN2'

ocp.resource_manager_plan='FORCE:DEFAULT_MAINTENANCE_PLAN'

*.resumable_timeout=200

*.service_names='aaa'

*.sga_target=1241513984

*.standby_file_management='AUTO'

*.undo_tablespace='UNDOTBS1'

 

配置备库监听:

[oracle@gyl dbs]$vim /u01/app/oracle/product/11.2.0/db/network/admin/listener.ora

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

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

      (ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))

    )

  )

 

 

SID_LIST_LISTENER =

 (SID_LIST =

   (SID_DESC =

     (GLOBAL_DBNAME = oca)

     (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db)

     (SID_NAME = oca)

    )

   )

 

ADR_BASE_LISTENER =/u01/app/oracle

 

[oracle@gyl dbs]$vim /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora

# tnsnames.oraNetwork Configuration File:/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

# Generated byOracle configuration tools.

 

OCP =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ocp)

    )

  )

 

 

oca =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = oca)

    )

  )

~

 

 

 启动数据库到nomount状态

[oracle@gyl dbs]$sqlplus / as sysdba

 

SQL*Plus: Release11.2.0.4.0 Production on Fri Dec 15 21:57:46 2017

 

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

 

Connected to an idleinstance.

 

SQL> startupnomount pfile='/u01/app/oracle/product/11.2.0/db/dbs/initoca.ora';

ORACLE instancestarted.

 

Total System GlobalArea 1235959808 bytes

FixedSize                    2252784 bytes

VariableSize                  419430416 bytes

DatabaseBuffers          805306368 bytes

RedoBuffers                    8970240 bytes

SQL>

 

 

createspfile from pfile;  #创建spfile

 

 

 

验证监听和TNS配置:

[oracle@sannetocpdbs]$ sqlplus sys/oracle@ocp as sysdba

 

SQL*Plus: Release11.2.0.4.0 Production on Fri Jan 5 18:47:42 2018

 

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

 

 

Connected to:

Oracle Database 11gEnterprise Edition Release 11.2.0.4.0 - 64bit Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

 

SP2-0103: Nothing inSQL buffer to run.

 

 

[oracle@sannetocpadmin]$ sqlplus sys/oracle@oca as sysdba

 

SQL*Plus: Release11.2.0.4.0 Production on Sat Jan 6 02:08:09 2018

 

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

 

 

Connected to:

Oracle Database 11gEnterprise Edition Release 11.2.0.4.0 - 64bit Production

With thePartitioning, OLAP, Data Mining and Real Application Testing options

 

SP2-0103: Nothing inSQL buffer to run.

 

 

 

 

恢复数据库

[oracle@gyl ~]$ rmantarget sys/oracle@ocp auxiliary sys/oracle@oca

 

Recovery Manager:Release 11.2.0.4.0 - Production on Sat Dec 16 00:47:13 2017

 

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

 

connected to targetdatabase: OCP (DBID=2840536669)

connected toauxiliary database: OCP (not mounted)

 

RMAN> duplicatetarget database for standby from active database;

 

Starting DuplicateDb at 16-DEC-17

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_AUX_DISK_1

channelORA_AUX_DISK_1: SID=167 device type=DISK

 

contents of MemoryScript:

{

   backup as copy reuse

   targetfile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwocp' auxiliary format

 '/u01/app/oracle/product/11.2.0/db/dbs/orapwoca'   ;

}

executing MemoryScript

 

Starting backup at16-DEC-17

allocated channel:ORA_DISK_1

channel ORA_DISK_1:SID=171 device type=DISK

Finished backup at16-DEC-17

 

contents of MemoryScript:

{

   backup as copy current controlfile forstandby auxiliary format '/database/ocp/control01.ctl';

   restore clone controlfile to '/u01/app/oracle/fast_recovery_area/oca/control02.ctl' from

 '/database/ocp/control01.ctl';

}

executing MemoryScript

 

Starting backup at16-DEC-17

using channelORA_DISK_1

channel ORA_DISK_1:starting datafile copy

copying standbycontrol file

output filename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_ocp.ftag=TAG20180106T032346 RECID=6 STAMP=964668226

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

Finished backup at16-DEC-17

 

Starting restore at16-DEC-17

using channelORA_AUX_DISK_1

 

channelORA_AUX_DISK_1: copied control file copy

Finished restore at16-DEC-17

 

contents of MemoryScript:

{

   sql clone 'alter database mount standbydatabase';

}

executing MemoryScript

 

sql statement: alterdatabase mount standby database

 

contents of MemoryScript:

{

   set newname for tempfile  1 to

 "/database/oca/temp01.dbf";

   switch clone tempfile all;

   set newname for datafile  1 to

 "/database/oca/system01.dbf";

   set newname for datafile  2 to

 "/database/oca/sysaux01.dbf";

   set newname for datafile  3 to

 "/database/oca/undotbs01.dbf";

   set newname for datafile  4 to

 "/database/oca/users01.dbf";

   set newname for datafile  5 to

 "/database/oca/example01.dbf";

   set newname for datafile  6 to

 "/database/oca/block01.dbf";

   backup as copy reuse

   datafile 1 auxiliary format

 "/database/oca/system01.dbf"   datafile

 2 auxiliary format

 "/database/oca/sysaux01.dbf"   datafile

 3 auxiliary format

 "/database/oca/undotbs01.dbf"   datafile

 4 auxiliary format

 "/database/oca/users01.dbf"   datafile

 5 auxiliary format

 "/database/oca/example01.dbf"   datafile

 6 auxiliary format

 "/database/oca/block01.dbf"   ;

   sql 'alter system archive log current';

}

executing MemoryScript

 

executing command:SET NEWNAME

 

renamed tempfile 1to /database/oca/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 at16-DEC-17

using channelORA_DISK_1

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00001 name=/database/ocp/system01.dbf

output filename=/database/oca/system01.dbf tag=TAG20180106T032354

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00002 name=/database/ocp/sysaux01.dbf

output filename=/database/oca/sysaux01.dbf tag=TAG20180106T032354

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00005 name=/database/ocp/example01.dbf

output filename=/database/oca/example01.dbf tag=TAG20180106T032354

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00003 name=/database/ocp/undotbs01.dbf

output filename=/database/oca/undotbs01.dbf tag=TAG20180106T032354

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00004 name=/database/ocp/users01.dbf

output filename=/database/oca/users01.dbf tag=TAG20180106T032354

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00006 name=/database/ocp/block01.dbf

output filename=/database/oca/block01.dbf tag=TAG20180106T032354

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

Finished backup at16-DEC-17

 

sql statement: altersystem archive log current

 

contents of MemoryScript:

{

   switch clone datafile all;

}

executing MemoryScript

 

datafile 1 switchedto datafile copy

input datafile copyRECID=6 STAMP=962844619 file name=/database/oca/system01.dbf

datafile 2 switchedto datafile copy

input datafile copyRECID=7 STAMP=962844619 file name=/database/oca/sysaux01.dbf

datafile 3 switchedto datafile copy

input datafile copyRECID=8 STAMP=962844619 file name=/database/oca/undotbs01.dbf

datafile 4 switchedto datafile copy

input datafile copyRECID=9 STAMP=962844619 file name=/database/oca/users01.dbf

datafile 5 switchedto datafile copy

input datafile copyRECID=10 STAMP=962844619 file name=/database/oca/example01.dbf

datafile 6 switchedto datafile copy

input datafile copyRECID=11 STAMP=962844619 file name=/database/oca/block01.dbf

RMAN-05535: WARNING:All redo log files were not defined properly.

RMAN-05535: WARNING:All redo log files were not defined properly.

RMAN-05535: WARNING:All redo log files were not defined properly.

RMAN-05535: WARNING:All redo log files were not defined properly.

RMAN-05535: WARNING:All redo log files were not defined properly.

RMAN-05535: WARNING:All redo log files were not defined properly.

RMAN-05535: WARNING:All redo log files were not defined properly.

Finished DuplicateDb at 16-DEC-17

 

RMAN> exit

 

RMAN-06900: WARNING:unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row

RMAN-06901: WARNING:disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows

ORACLE error fromtarget database:

ORA-03113:end-of-file on communication channel

Process ID: 9744

Session ID: 9 Serialnumber: 17

 

 

Recovery Managercomplete.

[oracle@gyl ~]$ rmantarget sys/oracle@ocp auxiliary sys/oracle@oca

 

Recovery Manager:Release 11.2.0.4.0 - Production on Sat Dec 16 01:05:59 2017

 

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

 

connected to targetdatabase: OC
d27e
P (DBID=2840536669)

connected toauxiliary database: OCP (not mounted)

 

RMAN> duplicatetarget database for standby from active database;

 

Starting DuplicateDb at 16-DEC-17

using targetdatabase control file instead of recovery catalog

allocated channel:ORA_AUX_DISK_1

channelORA_AUX_DISK_1: SID=167 device type=DISK

 

contents of MemoryScript:

{

   backup as copy reuse

   targetfile '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwocp' auxiliary format

 '/u01/app/oracle/product/11.2.0/db/dbs/orapwoca'   ;

}

executing MemoryScript

 

Starting backup at16-DEC-17

allocated channel:ORA_DISK_1

channel ORA_DISK_1:SID=256 device type=DISK

Finished backup at16-DEC-17

 

contents of MemoryScript:

{

   backup as copy current controlfile forstandby auxiliary format '/database/ocp/control01.ctl';

   restore clone controlfile to '/u01/app/oracle/fast_recovery_area/oca/control02.ctl' from

 '/database/ocp/control01.ctl';

}

executing MemoryScript

 

Starting backup at16-DEC-17

using channelORA_DISK_1

channel ORA_DISK_1:starting datafile copy

copying standbycontrol file

output filename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_ocp.ftag=TAG20180106T034235 RECID=7 STAMP=964669355

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

Finished backup at16-DEC-17

 

Starting restore at16-DEC-17

using channelORA_AUX_DISK_1

 

channelORA_AUX_DISK_1: copied control file copy

Finished restore at16-DEC-17

 

contents of MemoryScript:

{

   sql clone 'alter database mount standbydatabase';

}

executing MemoryScript

 

sql statement: alterdatabase mount standby database

 

contents of MemoryScript:

{

   set newname for tempfile  1 to

 "/database/oca/temp01.dbf";

   switch clone tempfile all;

   set newname for datafile  1 to

 "/database/oca/system01.dbf";

   set newname for datafile  2 to

 "/database/oca/sysaux01.dbf";

   set newname for datafile  3 to

 "/database/oca/undotbs01.dbf";

   set newname for datafile  4 to

 "/database/oca/users01.dbf";

   set newname for datafile  5 to

 "/database/oca/example01.dbf";

   set newname for datafile  6 to

 "/database/oca/block01.dbf";

   backup as copy reuse

   datafile 1 auxiliary format

 "/database/oca/system01.dbf"   datafile

 2 auxiliary format

 "/database/oca/sysaux01.dbf"   datafile

 3 auxiliary format

 "/database/oca/undotbs01.dbf"   datafile

 4 auxiliary format

 "/database/oca/users01.dbf"   datafile

 5 auxiliary format

 "/database/oca/example01.dbf"   datafile

 6 auxiliary format

 "/database/oca/block01.dbf"   ;

   sql 'alter system archive log current';

}

executing MemoryScript

 

executing command:SET NEWNAME

 

renamed tempfile 1to /database/oca/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 at16-DEC-17

using channelORA_DISK_1

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00001 name=/database/ocp/system01.dbf

output filename=/database/oca/system01.dbf tag=TAG20180106T034244

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00002 name=/database/ocp/sysaux01.dbf

output filename=/database/oca/sysaux01.dbf tag=TAG20180106T034244

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00005 name=/database/ocp/example01.dbf

output filename=/database/oca/example01.dbf tag=TAG20180106T034244

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00003 name=/database/ocp/undotbs01.dbf

output filename=/database/oca/undotbs01.dbf tag=TAG20180106T034244

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00004 name=/database/ocp/users01.dbf

output filename=/database/oca/users01.dbf tag=TAG20180106T034244

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

channel ORA_DISK_1:starting datafile copy

input datafile filenumber=00006 name=/database/ocp/block01.dbf

output filename=/database/oca/block01.dbf tag=TAG20180106T034244

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

Finished backup at16-DEC-17

 

sql statement: altersystem archive log current

 

contents of MemoryScript:

{

   switch clone datafile all;

}

executing MemoryScript

 

datafile 1 switchedto datafile copy

input datafile copyRECID=7 STAMP=962845740 file name=/database/oca/system01.dbf

datafile 2 switchedto datafile copy

input datafile copyRECID=8 STAMP=962845740 file name=/database/oca/sysaux01.dbf

datafile 3 switchedto datafile copy

input datafile copyRECID=9 STAMP=962845740 file name=/database/oca/undotbs01.dbf

datafile 4 switchedto datafile copy

input datafile copyRECID=10 STAMP=962845740 file name=/database/oca/users01.dbf

datafile 5 switchedto datafile copy

input datafile copyRECID=11 STAMP=962845740 file name=/database/oca/example01.dbf

datafile 6 switchedto datafile copy

input datafile copyRECID=12 STAMP=962845740 file name=/database/oca/block01.dbf

Finished DuplicateDb at 16-DEC-17

 

 

 

开启实时同步

备库开启:

SQL> alterdatabase recover managed standby database using current logfile disconnect fromsession;

 

Database altered.

 

 

开启flashback

 

SQL> alterdatabase recover managed standby database cancel;

 

Database altered.

 

SQL> shutdownimmediate;

ORA-01109: databasenot open

 

 

Database dismounted.

ORACLE instance shutdown.

SQL> startupmount

ORACLE instancestarted.

 

Total System GlobalArea 1235959808 bytes

FixedSize                    2252784 bytes

VariableSize                  419430416 bytes

DatabaseBuffers          805306368 bytes

RedoBuffers                    8970240 bytes

Database mounted.

SQL> alteratabase flashback on;

alter atabaseflashback on

      *

ERROR at line 1:

ORA-00940: invalidALTER command

 

 

SQL> alterdatabase flashback on;

 

Database altered.

 

SQL> alterdatabase open;

 

Database altered.

 

SQL> alterdatabase recover managed standby database using current logfile disconnect fromsession;

 

 

Database altered.

 
 
 
验证DG同步

查询主库最大归档序号,一致即归档同步成功。

SYS@ocp> selectdest_name,error from v$archive_dest;

 

DEST_NAME

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

ERROR

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

LOG_ARCHIVE_DEST_1

 

 

LOG_ARCHIVE_DEST_2

ORA-16047: DGIDmismatch between destination setting and target

database

 

LOG_ARCHIVE_DEST_3

 

 

LOG_ARCHIVE_DEST_4

 

 

LOG_ARCHIVE_DEST_5

 

 

LOG_ARCHIVE_DEST_6

 

 

LOG_ARCHIVE_DEST_7

 

 

LOG_ARCHIVE_DEST_8

 

 

LOG_ARCHIVE_DEST_9

 

 

LOG_ARCHIVE_DEST_10

 

 

LOG_ARCHIVE_DEST_11

 

 

LOG_ARCHIVE_DEST_12

 

 

LOG_ARCHIVE_DEST_13

 

 

LOG_ARCHIVE_DEST_14

 

 

LOG_ARCHIVE_DEST_15

 

 

LOG_ARCHIVE_DEST_16

 

 

LOG_ARCHIVE_DEST_17

 

 

LOG_ARCHIVE_DEST_18

 

 

LOG_ARCHIVE_DEST_19

 

 

LOG_ARCHIVE_DEST_20

 

 

LOG_ARCHIVE_DEST_21

 

 

LOG_ARCHIVE_DEST_22

 

 

LOG_ARCHIVE_DEST_23

 

 

LOG_ARCHIVE_DEST_24

 

 

LOG_ARCHIVE_DEST_25

 

 

LOG_ARCHIVE_DEST_26

 

 

LOG_ARCHIVE_DEST_27

 

 

LOG_ARCHIVE_DEST_28

 

 

LOG_ARCHIVE_DEST_29

 

 

LOG_ARCHIVE_DEST_30

 

 

LOG_ARCHIVE_DEST_31

 

 

 

31 rows selected.

 

SYS@ocp> selectmax(sequence#) from v$archived_log;

 

MAX(SEQUENCE#)

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

    84

 
 
 
SQL> selectdest_name,error from v$archive_dest;

 

DEST_NAME                       ERROR

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

LOG_ARCHIVE_DEST_1

LOG_ARCHIVE_DEST_2

LOG_ARCHIVE_DEST_3

LOG_ARCHIVE_DEST_4

LOG_ARCHIVE_DEST_5

LOG_ARCHIVE_DEST_6

LOG_ARCHIVE_DEST_7

LOG_ARCHIVE_DEST_8

LOG_ARCHIVE_DEST_9

LOG_ARCHIVE_DEST_10

LOG_ARCHIVE_DEST_11

 

DEST_NAME                       ERROR

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

LOG_ARCHIVE_DEST_12

LOG_ARCHIVE_DEST_13

LOG_ARCHIVE_DEST_14

LOG_ARCHIVE_DEST_15

LOG_ARCHIVE_DEST_16

LOG_ARCHIVE_DEST_17

LOG_ARCHIVE_DEST_18

LOG_ARCHIVE_DEST_19

LOG_ARCHIVE_DEST_20

LOG_ARCHIVE_DEST_21

LOG_ARCHIVE_DEST_22

 

DEST_NAME                       ERROR

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

LOG_ARCHIVE_DEST_23

LOG_ARCHIVE_DEST_24

LOG_ARCHIVE_DEST_25

LOG_ARCHIVE_DEST_26

LOG_ARCHIVE_DEST_27

LOG_ARCHIVE_DEST_28

LOG_ARCHIVE_DEST_29

LOG_ARCHIVE_DEST_30

LOG_ARCHIVE_DEST_31

STANDBY_ARCHIVE_DEST

 

32 rows selected.

 

SQL> selectmax(sequence#) from v$archived_log;

 

MAX(SEQUENCE#)

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

    84

 
 
确认状态

SYS@ocp> selectswitchover_status,database_role from v$database;

 

SWITCHOVER_STATUS    DATABASE_ROLE

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

NOTALLOWED             PRIMARY

 

SYS@ocp>

SQL> selectswitchover_status,database_role from v$database;

 

SWITCHOVER_STATUS    DATABASE_ROLE

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

NOTALLOWED             PHYSICAL STANDBY

 
主库测试创建一个表:

SYS@ocp> createtable dg(id number);

 

Table created.

 

SYS@ocp> insertinto dg values(1);

 

1 row created.

 

SYS@ocp> commit;

 

Commit complete.

SYS@ocp> select *from dg;

 

ID

----------

 1

 
备库测试

SQL> select *from dg;

 

ID

----------

 1

 

总结:第一次安装dg,错误不断,不过总算磕磕巴巴完成了。目前先完成那么多。不早了,睡了。

———2018.1.6   4:20
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息