oracle DG搭建

2024年 2月 23日 92.8k 0

1.配置监听

[oracle@oracle11 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.12)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

ORCL_DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.13)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl_dg)
)
)

[oracle@oracle11 admin]$

--验证
tnsping orcl
tnsping orcl_dg

2.主库生成standby controlfile 和 pfile

alter database create standby controlfile as '/backup/control01.ctl';
create pfile='/backup/pfile0920.ora' from spfile;

3.把生成的pfile 、 standby controlfile 、 pwdfile 拷贝到备库

orcl:
cd /backup
scp control01.ctl 192.168.59.13:/backup
scp pfile0920.ora 192.168.59.13:/backup

scp $ORACLE_HOME/dbs/orapworcl 192.168.59.13:$ORACLE_HOME/dbs

orcl_dg:
cd $ORACLE_HOME/dbs
mv orapwdorcl orapwdorcl_dg

4.备份主库,并传输备份文件到备库

rman target /

run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup database format '/backup/backup_%U';
release channel c1;
release channel c2;
release channel c3;
}

scp /backup/back* 192.168.59.13:/backup/

5.修改两边的pfile文件

添加相应的内容,分别如下:

orcl:
[oracle@oracle11 ~]$ cat pfile0920.ora
orcl.__db_cache_size=255852544
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=293601280
orcl.__sga_target=436207616
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=159383552
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/ORCL/controlfile/o1_mf_lhok7t70_.ctl','/u01/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_lhok7t7o_.ctl'
*.db_block_size=8192
*.db_create_file_dest='/u01/app/oracle/oradata'
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=40705720320
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.memory_target=729808896
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.DB_UNIQUE_NAME=orcl
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl_dg)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/flash_recovery_area/ORCL/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl'
*.LOG_ARCHIVE_DEST_2='SERVICE=orcl_dg ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_dg'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER=orcl_dg
*.STANDBY_FILE_MANAGEMENT=AUTO
[oracle@oracle11 ~]$

--主库使用修改过的pfile文件启动,并由新修改的pfile生成spfile,最后由spfile重新启动。

shutdown immediate;
startup pfile='/backup/pfile0920.ora';
create spfile from memory;
shutdown immediate;
startup;

orcl_dg:

[oracle@oracle_dg backup]$ cat pfile0920.ora
orcl.__db_cache_size=255852544
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=293601280
orcl.__sga_target=436207616
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=159383552
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/ORCL/controlfile/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='/u01/app/oracle/oradata'
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=40705720320
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.memory_target=729808896
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.DB_UNIQUE_NAME=orcl_dg
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl_dg)'
*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/flash_recovery_area/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_dg'
*.LOG_ARCHIVE_DEST_2='SERVICE=orcl ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER=orcl
*.STANDBY_FILE_MANAGEMENT=AUTO

[oracle@oracle_dg backup]$

6.启动备库到nomount、mount阶段

orcl_dg:
SQL> startup nomount pfile='/backup/pfile0920.ora';
ORACLE instance started.

Total System Global Area 726540288 bytes
Fixed Size 2216904 bytes
Variable Size 432016440 bytes
Database Buffers 285212672 bytes
Redo Buffers 7094272 bytes
SQL> select status from v$instance;

STATUS
------------------------
STARTED

SQL>

mv /backup/control01.ctl /u01/app/oracle/oradata/ORCL/controlfile/control01.ctl

SQL> alter database mount;

Database altered.

SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL>

7.restore database 恢复备库数据文件

orcl_dg:

[oracle@oracle_dg backup]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Wed Sep 20 16:32:48 2023

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

connected to target database: ORCL (DBID=1674794362, not open)

RMAN> catalog start with '/backup/';
(catalog start with '/backup/'; 这个命令可能是想要批量地将某个目录下的备份文件信息一次性注册到 RMAN 的恢复目录中。它会扫描指定目录下的备份文件,并将它们注册到 RMAN 中,以便备份管理和恢复操作。通常,这种命令用于初始化 RMAN 恢复目录。)

RMAN> crosscheck backup;

RMAN> delete expired backup;

RMAN> restore database;

8.recover database 应用日志备库数据文件,并打开备库

alter database recover managed standby database disconnect from session ;
查看日志看是否恢复成功,如何没有就要手动将归档日志scp到备库,并将备库的归档日志目录注册一下(rman里面使用catalog start with '文件路径'来注册)。

SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database open;

Database altered.

SQL>

9.创建standby logfile,并开启备库实时应用

alter database add standby logfile;
alter database add standby logfile;
alter database add standby logfile;
alter database add standby logfile;
创建备份日志文件的目的是实时同步

alter database recover managed standby database using current logfile disconnect from session nodelay;

出现(in transit)代表同步成功

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论