search
HomeDatabaseMysql TutorialOracle11gDataGuard使用duplicatefromactivedatabase创建standby

用这种方式来搭建 DG ,主库的停机时间很少,只需要重启一下,使参数生效。也可以用这种方法进行 DB 迁移。 DG 搭建好,然后把备库激活就可以了。这样整个迁移中宕机时间也比较短。 Oracle 11g 的 pyhsical standby 支持 open read only 下的 apply 和 Real-

      用这种方式来搭建DG ,主库的停机时间很少,只需要重启一下,使参数生效。也可以用这种方法进行DB迁移。DG搭建好,然后把备库激活就可以了。 这样整个迁移中宕机时间也比较短。


 

       Oracle 11gpyhsical standby 支持open read only 下的applyReal-time query。 因此就有了physical standby 稳定和logical standby 的报表查询功能。

 

Oracle 11.2.0.1

OS redhat 5.5

Primary IP: 192.168.2.42

DB_NAME=sanfu

 

Standby IP: 192.168.2.43

DB_NAME=sanfu

 

.  Primary 端操作:

1. 设置归档模式

       这个生产库都是这种模式。

       SQL> archive log list;

       SQL> shutdown immediate

       SQL> startup mount

       SQL> alter database archivelog;

       SQL> archive log list;

      

2. Primary 设置force logging

SQL> alter database force logging;

SQL> select force_logging from v$database;

FORCE_LOG

---------

YES

 

3. 配置Oracle Net

       Primary 库和Standby 都要修改。也可以使用netca netmgr命令配置。

注意:修改完后记得重启listener

 

Listener.ora

[oracle@qs-dmm-rh1 admin]$ cat listener.ora

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost6.localdomain6)(PORT = 1521))

    )

  )

 

ADR_BASE_LISTENER = /u01/app/oracle

 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = orcl)

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

      (SID_NAME = orcl)

    )

  )

 -- 配置静态注册

 

tnsname.ora

[oracle@qs-dmm-rh1 admin]$ cat tnsnames.ora

sanfus =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl)

    )

  )

 

sanfup =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl)

    )

  )

 

 

4. 添加data guard 参数

       创建pfile, 添加如下文件:

SQL> create pfile from spfile;

*.db_name='orcl'

*.db_unique_name='sanfup'

*.log_archive_config='dg_config=(sanfup,sanfus)'

*.log_archive_dest_1='location=/u01/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=sanfup'

*.log_archive_dest_2='service=sanfus reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=sanfus'

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.standby_file_management='auto'

*.fal_server='sanfus'

*.fal_client='sanfup'

 

 

注意:

       Oracle 11gData Guard中,standby_archive_dest参数已经被取消了。

      

Standby归档文件的存放位置按如下规则来进行:

1)当LOG_ARCHIVE_DEST_n设置了valid_for=(all_logfiles,all_roles),那么在不定义standby_archive_dest参数时,Oracle就会选择LOG_ARCHIVE_DEST_n参数作为归档目标。

2)如果在第一步设置的同时,又独立设置LOG_ARCHIVE_DEST_n参数为 valid_for=(standby_logfile,*) 属性,那么当compatible参数大于10.0的时候,会自动的选择任意一个LOG_ARCHIVE_DEST_n的值。

3)如果LOG_ARCHIVE_DEST_n 没有设置的话,默认位置是:

       $ORACLE_HOME/dbs.

       不过valid_for参数的默认值就是all_logfilesall_roles. 所以只要设置了本地的归档位置,远程的归档文件也会放到这个目录下面。

 

5. 用新pfile重启主库

 

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora';

File created.

SQL> startup

ORACLE instance started.

 

Total System Global Area  422670336 bytes

Fixed Size                  1336960 bytes

Variable Size             310380928 bytes

Database Buffers          104857600 bytes

Redo Buffers                6094848 bytes

Database mounted.

Database opened.

SQL>

 

 

.  Standby 端设置:

 

1. 创建相关目录结构

[oracle@qs-dmm-rh2 trace]$ mkdir -p /u01/app/oracle/oradata/dave

--这里我们创建的目录和Target 库不同,我们在参数文件里需要转换一下。

 

2. 创建standby的口令文件

[oracle@qs-dmm-rh2 trace]$ orapwd file=?/dbs/orapwdave password=oracle

 

3. 创建standby的初始化参数:

*.compatible='11.2.0.4.0'

*db_name=orcl

*.control_files='/u01/app/oracle/oradata/dave/control01.ctl', '/u01/app/oracle/oradata/dave/control02.ctl',

'/u01/app/oracle/oradata/dave/control03.ctl'

*.db_unique_name='sanfus'

*.log_archive_config='dg_config=(sanfup,sanfus)'

*.log_archive_dest_1='location=/u01/archivelog valid_for=(standby_logfile, standby_role) db_unique_name=sanfus'

*.log_archive_dest_2='service=sanfup reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=sanfup'

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.standby_file_management='auto'

*.fal_server='sanfup'

*.fal_client='sanfus'

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dave'

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dave'

 

4. pfile standby 启动到nomount状态:

SQL> startup nomount pfile=?/dbs/initorcl.ora

ORACLE instance started.

 

Total System Global Area  146472960 bytes

Fixed Size                  1335080 bytes

Variable Size              92274904 bytes

Database Buffers           50331648 bytes

Redo Buffers                2531328 bytes

 

5. 开始duplicate

 

[oracle@qs-dmm-rh2 dbs]$ rman target sys/oracle@sanfup auxiliary sys/oracle@sanfus

 

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 8 16:10:25 2011

 

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

 

connected to target database: ORCL (DBID=1272955137)

connected to auxiliary database: ORCL (not mounted)

 

RMAN> duplicate target database for standby from active database;

 

Starting Duplicate Db at 08-MAR-11

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=20 device type=DISK

 

contents of Memory Script:

{

   backup as copy reuse

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

 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl'   ;

--duplicate 创建standby 时会复制口令文件

}

executing Memory Script

 

Starting backup at 08-MAR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=45 device type=DISK

Finished backup at 08-MAR-11

 

contents of Memory Script:

{

   backup as copy current controlfile for standby auxiliary format  '/u01/app/oracle/oradata/dave/control01.ctl';

   restore clone controlfile to  '/u01/app/oracle/oradata/dave/control02.ctl' from

 '/u01/app/oracle/oradata/dave/control01.ctl';

   restore clone controlfile to  '/u01

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

SQL Commands in MySQL: Practical ExamplesSQL Commands in MySQL: Practical ExamplesApr 14, 2025 am 12:09 AM

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

How does InnoDB handle ACID compliance?How does InnoDB handle ACID compliance?Apr 14, 2025 am 12:03 AM

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's Place: Databases and ProgrammingMySQL's Place: Databases and ProgrammingApr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL: From Small Businesses to Large EnterprisesMySQL: From Small Businesses to Large EnterprisesApr 13, 2025 am 12:17 AM

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?Apr 13, 2025 am 12:16 AM

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.