配置YUM(主备全操作):
[root@www ~]# vi /etc/yum.repos.d/redhat.repo
[server]
name=server
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
挂载光盘到MNT目录下(主备全操作):
[root@www ~]# mount /dev/cdrom /mnt
mount: block device /dev/cdrom is write-protected, mounting read-only
清除YUM缓存(主备全操作):
[root@www ~]# yum clean all
Loaded plugins: rhnplugin, security
Cleaning up Everything
[root@www ~]# yum repolist
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
server | 1.3 kB 00:00
server/primary | 845 kB 00:00
server 3040/3040
repo id repo name status
server server enabled: 3,040
repolist: 3,040
检查安装ORACLE所需要的依赖包(主备全操作):
[root@www ~]# unset uninstall_rpm;for i in binutils compat-libstdc++-33 \
elfutils-libelf elfutils-libelf-devel \
gcc gcc-c++ glibc glibc-devel glibc-headers kernel-headers \
libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel \
make sysstat unixODBC unixODBC-devel;do rpm -q $i &>/dev/null || uninstall_rpm="$uninstall_rpm $i";\
done;[[ -z "$uninstall_rpm" ]] && echo -e "\nuninstall_rpm:\n\tOK.OK.OK"|| \
echo -e "\nuninstall_rpm:\n\t$uninstall_rpm"
uninstall_rpm:
elfutils-libelf-devel gcc gcc-c++ glibc-devel glibc-headers kernel-headers libaio-devel libgomp libstdc++-devel sysstat unixODBC unixODBC-devel
安装缺少软件包(主备全操作):
[root@www ~]# yum install -y elfutils-libelf-devel gcc gcc-c++ glibc-devel glibc-headers kernel-headers libaio-devel libgomp libstdc++-devel sysstat unixODBC unixODBC-devel
Installed:
elfutils-libelf-devel.i386 0:0.137-3.el5 elfutils-libelf-devel.x86_64 0:0.137-3.el5
gcc.x86_64 0:4.1.2-46.el5 gcc-c++.x86_64 0:4.1.2-46.el5
glibc-devel.i386 0:2.5-42 glibc-devel.x86_64 0:2.5-42
glibc-headers.x86_64 0:2.5-42 kernel-headers.x86_64 0:2.6.18-164.el5
libaio-devel.i386 0:0.3.106-3.2 libaio-devel.x86_64 0:0.3.106-3.2
libgomp.i386 0:4.4.0-6.el5 libgomp.x86_64 0:4.4.0-6.el5
libstdc++-devel.i386 0:4.1.2-46.el5 libstdc++-devel.x86_64 0:4.1.2-46.el5
sysstat.x86_64 0:7.0.2-3.el5 unixODBC.i386 0:2.2.11-7.1
unixODBC.x86_64 0:2.2.11-7.1 unixODBC-devel.i386 0:2.2.11-7.1
unixODBC-devel.x86_64 0:2.2.11-7.1
Dependency Installed:
elfutils-libelf.i386 0:0.137-3.el5 elfutils-libelf-devel-static.i386 0:0.137-3.el5
elfutils-libelf-devel-static.x86_64 0:0.137-3.el5
Complete!
添加Oracle用户和组(主备全操作):
[root@www ~]# groupadd oinstall
[root@www ~]# groupadd dba
[root@www ~]# useradd -g oinstall -G dba oracle
[root@www ~]# passwd oracle
Changing password for user oracle.
New UNIX password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
修改系统对ORACLE限制(主备全操作):
[root@www ~]# vi /etc/sysctl.conf
kernel.shmall = 2097152
kernel.shmmax = 4294967296
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
使内核参数生效(主备全操作):
[root@www ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
kernel.shmall = 2097152
kernel.shmmax = 4294967296
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
修改ORACLE用户文件限制(主备全操作):
[root@www ~]# vi /etc/security/limits.conf
oracle soft nofile 65536
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
建立相关目录(主备全操作):
[root@www ~]# mkdir -p /home/oracle/u01/app/oracle
[root@www ~]# chown -R oracle:oinstall /home/oracle/u01/app/
[root@www ~]# chmod -R 775 /home/oracle/u01/app
[root@www ~]# chown -R oracle.oinstall /home/oracle/u01
修改ORACLE用户环境变量(主备全操作):
[root@www home]# su - oracle
[oracle@www ~]$ vi .bashrc
export ORACLE_BASE=/home/oracle/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=pri(主库为pri,备库为std)
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LANG=AMERICAN_AMERICA.ZHS16CGB231280
安装ORACLE软件(主备全操作):机器很慢
执行最后弹出的脚本:
[oracle@www ~]$ exit
[root@www ~]# /home/oracle/u01/app/ora
oracle/ oraInventory/
[root@www ~]# /home/oracle/u01/app/oraInventory/orainstRoot.sh
Changing permissions of /home/oracle/u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /home/oracle/u01/app/oraInventory to oinstall.
The execution of the script is complete.
[root@www ~]# /home/oracle/u01/app/oracle/product/11.2.0/db_1/root.sh
Performing root user operation for Oracle 11g
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /home/oracle/u01/app/oracle/product/11.2.0/db_1
Enter the full pathname of the local bin directory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
建立数据库(只在主库操作,备库用RMAN进行恢复):
[oracle@www ~]$ dbca
开启归档日志(只在主库上做):
[oracle@www ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 10 19:28:49 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select name,log_mode,force_logging from v$database;
NAME LOG_MODE FOR
--------- ------------ ---
PRI NOARCHIVELOG NO
SQL> alter database force logging;
Database altered.
SQL> select name,log_mode,force_logging from v$database;
NAME LOG_MODE FOR
--------- ------------ ---
PRI NOARCHIVELOG YES
复制密码文件给备库并改名(此步骤只在主库上做):
[oracle@www ~]$ cd $ORACLE_HOME/dbs
[oracle@www dbs]$ ls
hc_pri.dat init.ora lkPRI orapwpri spfilepri.ora
[oracle@www dbs]$ scp orapwpri 192.168.0.95:$ORACLE_HOME/dbs/orapwstd
The authenticity of host '192.168.0.95 (192.168.0.95)' can't be established.
RSA key fingerprint is 5e:40:2c:9d:22:d9:45:67:f9:9b:e1:79:28:18:76:91.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.95' (RSA) to the list of known hosts.
oracle@192.168.0.95's password:
orapwpri 100% 1536 1.5KB/s 00:00
创建redolog日志组(此步骤只在主库上做)
[oracle@www dbs]$ cd /home/oracle/u01/app/oracle/oradata/
[oracle@www oradata]$ mkdir standbylog
[oracle@www oradata]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 10 20:50:24 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
示例:alter database add standby logfile group 7 ('/u01/app/oracle/oradata/standbylog/std_redo07.log') SIZE 50M;
SQL>ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/u01/app/oracle/oradata/standbylog/std_redo04.log') SIZE 50M;
Database altered.
SQL> alter database add standby logfile group 5
('/u01/app/oracle/oradata/standbylog/std_redo05.log' size 50m;
Database altered.
SQL> alter database add standby logfile group 6 '/home/oracle/u01/app/oracle/oradata/standbylog/std_redo06.log' size 50m;
Database altered.
SQL> alter database add standby logfile group 7 '/home/oracle/u01/app/oracle/oradata/standbylog/std_redo07.log' size 50m;
Database altered.
查看standby 日志组的信息:
SQL> select group#,sequence#,status, bytes/1024/1024 from v$standby_log;
GROUP# SEQUENCE# STATUS BYTES/1024/1024
---------- ---------- ---------- ---------------
4 0 UNASSIGNED 50
5 0 UNASSIGNED 50
6 0 UNASSIGNED 50
7 0 UNASSIGNED 50
SQL> set pagesize 100
SQL> col member for a60
SQL> select group#,member from v$logfile order by group#;
GROUP# MEMBER
---------- ------------------------------------------------------------
1 /home/oracle/u01/app/oracle/oradata/pri/redo01.log
2 /home/oracle/u01/app/oracle/oradata/pri/redo02.log
3 /home/oracle/u01/app/oracle/oradata/pri/redo03.log
4 /home/oracle/u01/app/oracle/oradata/standbylog/std_redo04.log
5 /home/oracle/u01/app/oracle/oradata/standbylog/std_redo05.log
6 /home/oracle/u01/app/oracle/oradata/standbylog/std_redo06.log
7 /home/oracle/u01/app/oracle/oradata/standbylog/std_redo07.log
7 rows selected.
修改主库的pfile参数文件(此步骤只在主库上做)
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /home/oracle/u01/app/oracle/product/11.2.0/db_1/dbs/spfilepri.ora
用spfile创建一个pfile,用于修改:
SQL> create pfile from spfile;
File created.
修改主库的pfile(注意目录结构修改前请仔细对比):
[oracle@www oradata]$ cd $ORACLE_HOME/dbs
[oracle@www dbs]$ vi initpri.ora
pri.__shared_io_pool_size=0
pri.__shared_pool_size=771751936
pri.__streams_pool_size=0
*.audit_file_dest='/home/oracle/u01/app/oracle/admin/pri/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/home/oracle/u01/app/oracle/oradata/pri/control01.ctl','/home/oracle/u01/app/oracle/fast_recovery_area/pri/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='pri'
*.db_recovery_file_dest='/home/oracle/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/home/oracle/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=priXDB)'
*.open_cursors=300
*.pga_aggregate_target=2423259136
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=4294967296
*.undo_tablespace='UNDOTBS1'
以下内容是需要新增加的:
*.db_unique_name='pri'
*.log_archive_config='dg_config=(pri,std)'
*.log_archive_dest_1='location=/home/oracle/u01/app/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name=pri'
*.log_archive_dest_2='service=std valid_for=(online_logfiles,primary_role) db_unique_name=std'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.log_archive_max_processes=4
*.fal_server='std'
*.fal_client='pri'
*.db_file_name_convert='/home/oracle/u01/app/oracle/oradata/std','/home/oracle/u01/app/oracle/oradata/pri'
*.log_file_name_convert='/home/oracle/u01/app/oracle/oradata/std','/home/oracle/u01/app/oracle/oradata/pri'
*.standby_file_management='auto'
手工创建/home/oracle/u01/app/oracle/arch:此目录是上面配置文件里面后加的
[oracle@www dbs]$ mkdir -p /home/oracle/u01/app/oracle/arch
[oracle@www dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 12 08:46:09 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
用修改过的pfile重新创建一个spfile,用于重启数据库(此步骤只在主库上做)
SQL> shu immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile;
File created.
数据库启动到mount状态:
SQL> startup mount;
ORACLE instance started.
Total System Global Area 4275781632 bytes
Fixed Size 2260088 bytes
Variable Size 889193352 bytes
Database Buffers 3372220416 bytes
Redo Buffers 12107776 bytes
Database mounted.
启用归档模式:
SQL> alter database archivelog;
Database altered.
OPEN数据库:
SQL> alter database open;
Database altered.
查看是否启用归档模式
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/u01/app/oracle/arch
Oldest online log sequence 5
Next log sequence to archive 7
Current log sequence 7
查看当前数据库是否使用spfile启动:
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string /home/oracle/u01/app/oracle/product/11.2.0/db_1/dbs/spfilepri.ora
SQL> select name,log_mode,force_logging from v$database;
NAME LOG_MODE FOR
--------- ------------ ---
PRI ARCHIVELOG YES
添加静态监听(主库、备库都要做)
主库监听配置:
[oracle@www db_1]$ vi /home/oracle/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.92)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = pri_DGMGRL)
(ORACLE_HOME = /home/oracle/u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = pri)
)
)
ADR_BASE_LISTENER = /home/oracle/u01/app/oracle
[oracle@www db_1]$ vi /home/oracle/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
pri =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.92)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri)
)
)
std =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.95)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std)
)
)
pri_DGMGR =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.92)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri_DGMGRL)
)
)
std_DGMGR =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.95)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std_DGMGRL)
)
)
[oracle@www admin]$ lsnrctl start
备库监听配置:
[oracle@www ~]$ vi /home/oracle/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.95)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = std_DGMGRL)
(ORACLE_HOME = /home/oracle/u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = std)
)
)
ADR_BASE_LISTENER = /home/oracle/u01/app/oracle
[oracle@www db_1]$ vi /home/oracle/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
pri =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.92)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri)
)
)
std =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.95)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std)
)
)
pri_DGMGR =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.92)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri_DGMGRL)
)
)
std_DGMGR =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.95)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = std_DGMGRL)
)
)
[oracle@www admin]$ lsnrctl start
主库端把pfile拷贝给备库端的$ORACLE_HOME/dbs目录下,并重命名:
[oracle@www ~]$ cd $ORACLE_HOME/dbs
[oracle@www dbs]$ scp initpri.ora 192.168.0.95:$ORACLE_HOME/dbs/initstd.ora
oracle@192.168.0.38's password:
initpri.ora 100% 1664 1.6KB/s 00:00
备库端进行修改(注意目录结构):
[oracle@www ~]$ cd $ORACLE_HOME/dbs
[oracle@www dbs]$ vi initstd.ora
pri.__db_cache_size=1392508928
pri.__java_pool_size=16777216
pri.__large_pool_size=33554432
pri.__oracle_base='/home/oracle/u01/app/oracle'#ORACLE_BASE set from environment
pri.__pga_aggregate_target=620756992
pri.__sga_target=1862270976
pri.__shared_io_pool_size=0
pri.__shared_pool_size=402653184
pri.__streams_pool_size=0
*.audit_file_dest='/home/oracle/u01/app/oracle/admin/std/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/home/oracle/u01/app/oracle/oradata/std/control01.ctl','/home/oracle/u01/app/oracle/oradata/std/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='pri'
*.db_recovery_file_dest='/home/oracle/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/home/oracle/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=stdXDB)'
*.open_cursors=300
*.pga_aggregate_target=2423259136
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=4294967296
*.undo_tablespace='UNDOTBS1'
*.db_unique_name='std'
*.log_archive_config='dg_config=(pri,std)'
*.log_archive_dest_1='location=/home/oracle/u01/app/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name=std'
*.log_archive_dest_2='service=pri valid_for=(online_logfiles,primary_role) db_unique_name=pri'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.log_archive_max_processes=4
*.fal_server='pri'
*.fal_client='std'
*.db_file_name_convert='/home/oracle/u01/app/oracle/oradata/pri','/home/oracle/u01/app/oracle/oradata/std'
*.log_file_name_convert='/home/oracle/u01/app/oracle/oradata/pri','/home/oracle/u01/app/oracle/oradata/std'
*.standby_file_management='auto'
备库操作:
[oracle@www dbs]$mkdir -pv /home/oracle/u01/app/oracle/admin/std/adump
[oracle@www dbs]$mkdir -pv /home/oracle/u01/app/oracle/oradata/std/
[oracle@www dbs]$mkdir -pv /home/oracle/u01/app/oracle/fast_recovery_area
[oracle@www dbs]$mkdir -pv /home/oracle/u01/app/oracle/arch
[oracle@www dbs]$mkdir -pv /home/oracle/u01/app/oracle/diag/rdbms/std/std/trace
[oracle@www dbs]$mkdir -pv /home/oracle/u01/app/oracle/oradata/standbylog
用修改后的pfile创建一个spfile,用于启动数据库(备库端做):
[oracle@www dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 10 21:46:04 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create spfile from pfile;
File created.
数据库启动到nomount状态:
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 4275781632 bytes
Fixed Size 2260088 bytes
Variable Size 889193352 bytes
Database Buffers 3372220416 bytes
Redo Buffers 12107776 bytes
利用RMAN在备库上恢复主库(备库端做):
[oracle@www ~]$ rman target sys/123123@pri auxiliary sys/123123@std
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Mar 10 22:29:01 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PRI (DBID=997507876)
connected to auxiliary database: PRI (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck;
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=1066861837 file name=/home/oracle/u01/app/oracle/oradata/std/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=1066861837 file name=/home/oracle/u01/app/oracle/oradata/std/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=1066861837 file name=/home/oracle/u01/app/oracle/oradata/std/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=1066861837 file name=/home/oracle/u01/app/oracle/oradata/std/users01.dbf
Finished Duplicate Db at 10-MAR-21
RMAN> exit
[oracle@www ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 10 22:33:32 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
MOUNTED
备库启动日志应用:
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select sequence#,applied from v$archived_log order by 1;
SEQUENCE# APPLIED
---------- ---------
12 YES
13 YES
14 YES
如上,如果发现有个NO的,也是正常的,说明该日志在主库上还没有归档,可以在主库上运行alter system switch logfile;命令来进行日志切换,再到备库查看日志应用情况
分别查看主库和备库的Current log sequence归档序列号是否一致:
主操作:
SQL> alter system switch logfile;
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/arch
Oldest online log sequence 14
Next log sequence to archive 16
Current log sequence 16
备操作:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/arch
Oldest online log sequence 14
Next log sequence to archive 0
Current log sequence 16
如发现不能同步在备库端进行以下操作:
SQL> alter database recover managed standby database cancel;
SQL> shu immediate;
SQL> startup nomount;
SQL> alter database mount standby database;
SQL> alter database open read only;
SQL> alter database recover managed standby database using current logfile disconnect from session;
启动broken(主库和备库都切换):
SQL> alter system set dg_broker_start=true;
System altered.
开启闪回(主库和备库都开启):
主操作:
SQL> alter database flashback on;
Database altered.
SQL> select open_mode,database_role,log_mode,flashback_on from v$database;
OPEN_MODE DATABASE_ROLE LOG_MODE FLASHBACK_ON
-------------------- ---------------- ------------ ------------------
READ WRITE PRIMARY ARCHIVELOG YES
备操作:
SQL> alter system set dg_broker_start=true;
System altered.
SQL> select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database flashback on;
Database altered.
SQL> recover managed standby database using current logfile disconnect;
Media recovery complete.
SQL> select open_mode,database_role,log_mode,flashback_on from v$database;
OPEN_MODE DATABASE_ROLE LOG_MODE FLASHBACK_ON
-------------------- ---------------- ------------ ------------------
READ ONLY WITH APPLY PHYSICAL STANDBY ARCHIVELOG YES
创建DGMGRL配置文件,主库操作:
[oracle@www ~]$ dgmgrl sys/123123@pri_dgmgr
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
Connected.
DGMGRL> create configuration dg as primary database is pri connect identifier is pri_dgmgr;
Configuration "dg" created with primary database "pri"
DGMGRL> show configuration;
Configuration - dg
Protection Mode: MaxPerformance
Databases:
pri - Primary database
Fast-Start Failover: DISABLED
Configuration Status:
DISABLED
DGMGRL> add database std as connect identifier is std_DGMGR maintained as physical;
Database "std" added
DGMGRL> show configuration;
Configuration - dg
Protection Mode: MaxPerformance
Databases:
pri - Primary database
std - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
DISABLED
DGMGRL> enable configuration;
Enabled.
DGMGRL> show configuration;
Configuration - dg
Protection Mode: MaxPerformance
Databases:
pri - Primary database
std - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS
备库操作:
$dgmgrl sys/123123 "start observer" &
主库操作:
DGMGRL> ENABLE FAST_START FAILOVER;
Enabled.
DGMGRL>exit
======================================================================================
[oracle@www dbs]$exit
[root@www ~]#reboot
[root@www ~]#su - oracle
[oracle@www dbs]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 10 22:33:32 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> startup;
SQL> exit;
[oracle@www dbs]$lsnrctl start
======================================================================================
[oracle@www ~]$ dgmgrl sys/123123@pri_dgmgr
DGMGRL> show configuration
Configuration - dg
Protection Mode: MaxPerformance
Databases:
pri - Primary database
std - (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS
手动切换到备库测试:
/home/oracle/u01/app/oracle/diag/rdbms/pri/pri/trace日志
DGMGRL> switchover to std
Performing switchover NOW, please wait...
Operation requires a connection to instance "std" on database "std"
Connecting to instance "std"...
Connected.
New primary database "std" is opening...
Operation requires startup of instance "pri" on database "pri"
Starting instance "pri"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "std"
DGMGRL> show configuration
Configuration - dg
Protection Mode: MaxPerformance
Databases:
std - Primary database
pri - (*) Physical standby database
Fast-Start Failover: ENABLED
Configuration Status:
SUCCESS
自动切换功能
begin
DBMS_SERVICE.CREATE_SERVICE (
service_name => 'HAHA',
network_name => 'HAHA',
aq_ha_notifications => TRUE,
failover_method => 'BASIC',
failover_type => 'SELECT',
failover_retries => 30,
failover_delay => 5);
end;
create or replace procedure cmc_taf_service_proc
is
v_role VARCHAR(30);
begin
select DATABASE_ROLE into v_role from V$DATABASE;
if v_role = 'PRIMARY' then
DBMS_SERVICE.START_SERVICE('HAHA');
else
DBMS_SERVICE.STOP_SERVICE('HAHA');
end if;
end;
create or replace TRIGGER cmc_taf_service_trg_startup
after startup on database
begin
cmc_taf_service_proc;
end;
create or replace TRIGGER cmc_taf_manage_trg_rolechange
after db_role_change on database
begin
cmc_taf_service_proc;
end;
SQL> exec cmc_taf_service_proc;
SQL> alter system archive log current;
SQL> show parameter service_names
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




