虚拟机上安装Oracle 12c 单机到单机的DG
虚拟机上安装Oracle 12c 单机到单机的DG
·
虚拟机上安装Oracle 12c 单机到单机的DG
环境准备:
ubuntu16.04+kvm1.3.2
CentOS6.5 64bit
oracle 12c1
test@vostro-2421:/media/test/mc2t/bak/kvm/dg$ qemu-img create -f qcow2 -o size=40G ./cos6512c1.img
Formatting './cos6512c1.img', fmt=qcow2 size=42949672960 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
test@vostro-2421:/media/test/mc2t/bak/kvm/dg$ qemu-img create -f qcow2 -o size=40G ./cos6512c2.img
Formatting './cos6512c1.img', fmt=qcow2 size=42949672960 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
test@vostro-2421:/media/test/mc2t/bak/kvm/dg$ qemu-img info ./cos6512c1.img
image: ./cos6512c1.img
file format: qcow2
virtual size: 40G (42949672960 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
3G内存40G硬盘未分区,由CENTOS6.5自动处理
database server->customize now->databases不安装mysql.postgresql数据库->Desktops->Desktop.xwindowssystem->Development除eclipse,其他全安装。
vi /etc/hosts
192.168.122.4 dg1
192.168.122.5 dg2
1.规划
主库(192.168.122.4)dg1:
db_name dg1
db_unique_name dg1
service_name dg1
instance_name dg1
本地归档路径 /u01/app/oracle/oradata/dg1/archivelog
tnsnames dg2 --配置去备库的tns
备库(192.168.122.5)dg2:
db_name dg1 数据库名要一样
db_unique_name dg2 在一个dg环境里面,每一个成员的名字。
servicer_name dg2
instance_name dg2 实例名可以不一样
本地归档路径 /u01/app/oracle/oradata/dg1/archivelog
tnsnames dg1 --配置去主库的tns
2.安装ORACLE
在VNC下使用Oracle用户安装软件,,无法正常显示图形界面解决办法:root用户执行 xhost +
重装oracle:
shutdown immediate;
lsnrctl stop
echo '' > /etc/oratab
rm -rf /u01
go1/2[脚本见我的另一文档]
1:/2:[1指dg1,2指dg2服务器]
安装oracle数据库
disable I wish to receve security updates via My Oracle Support ->next -> no email ->yes ->Skip software updates ->next ->Create and configure a database ->next ->Server class ->next ->Single instance ->next ->Advanced install ->next ->add Simplified chinese ->next ->Enterprise Edition ->next ->next ->next ->next
Global database name:dg1
Oracle system identifier(SID):dg1/2
Pluggable database name: pdbdg1/2
->next
Memory:
Enable Automatic Memory Management
Allocate memory 40%
Character sets:
Traditional Chinaese ZHT16HKSCS
->next database file location:/u01/app/oracle/oradata
->next ->next
Enable Recovery File system
Recovery area location: /u01/app/oracle/recovery_area
->next
Use the same passwor all accounts:123456
->next ->yes ->next
->install
database creation complete.For details check the logfiles at:
/u01/app/oracle/cfgtoollogs/dbca/dg1
Global Database Name: dg1
System Identifier(SID): dg1/2
Server Parameter File name:/u01/app/oracle/dbhome/dbs/spfiledg1/2.ora
EM Database Express URL:https://dg1/2:5500/em
->ok ->close
log: /u01/app/oraInventory/logs/installActions2016-10-09...log
ORACLE不会自动启动,运行dbSet.sh
dg2:
./runInstaller -silent -ignorePrereq -responseFile /home/oracle/db20161009.rsp
$ netca
$ dbca
3.设置DG数据库环境
dg1/2:
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
------------------------------------------------------------------------------
YES
[oracle@dg1 dg1]$ pwd
/u01/app/oracle/oradata/dg1
[oracle@dg1 dg1]$ ls
control01.ctl pdbseed redo02.log sysaux01.dbf temp01.dbf users01.dbf
pdbdg1 redo01.log redo03.log system01.dbf undotbs01.dbf
SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/' scope=both;
SQL> alter database close;
SQL> alter database archivelog;
SQL> select GROUP#,MEMBERS,BYTES/1024/1024 from v$log;
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
1 1 50
3 1 50
2 1 50
SQL> select GROUP#,MEMBER from v$logfile;
GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
3
/u01/app/oracle/oradata/dg1/redo03.log
2
/u01/app/oracle/oradata/dg1/redo02.log
1
/u01/app/oracle/oradata/dg1/redo01.log
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo1.log' size 50M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo2.log' size 50M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo3.log' size 50M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo4.log' size 50M;
Database altered.
4.修改SPFILE参数文件
[oracle@dg1 dbs]$ mkdir bak
[oracle@dg1 dbs]$ cp *.* ./bak/
[oracle@dg1 dbs]$ cp *1 ./bak
[oracle@dg1 dbs]$ ls bak
hc_dg1.dat init.ora lkDG1 orapwdg1 spfiledg1.ora
[oracle@dg1 dbs]$ ls
bak hc_dg1.dat init.ora lkDG1 orapwdg1 spfiledg1.ora
SQL> create pfile from spfile;
[oracle@dg1 dbs]$ ls
bak hc_dg1.dat initdg1.ora init.ora lkDG1 orapwdg1 spfiledg1.ora
dg1$ vi initdg1.ora添加
#primary dg1
DB_UNIQUE_NAME='dg1'
log_archive_config='DG_CONFIG=(dg1,dg2)'
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg1'
LOG_ARCHIVE_DEST_2='SERVICE=dg2 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dg2'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
STANDBY_FILE_MANAGEMENT=AUTO
dg2$ vi initdg2.ora添加
#standby dg2
DB_UNIQUE_NAME='dg2'
log_archive_config='DG_CONFIG=(dg1,dg2)'
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg2'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
STANDBY_FILE_MANAGEMENT=AUTO
log_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
db_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
5.配置网络监听
[oracle@dg1 admin]$ pwd
/u01/app/oracle/12c/dbhome/network/admin
[oracle@dg1 admin]$ mkdir bak
[oracle@dg1 admin]$ cp *.* bak/
[oracle@dg1 admin]$ ls
bak listener.ora samples shrept.lst sqlnet.ora tnsnames.ora
[oracle@dg1 admin]$ ls bak
listener.ora shrept.lst sqlnet.ora tnsnames.ora
1/2$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DG1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.4)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg1)
)
)
DG2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.5)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg2)
)
)
1$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dg1)
(ORACLE_HOME = /u01/app/oracle/12c/dbhome)
(SID_NAME = dg1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
)
)
2$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dg2)
(ORACLE_HOME = /u01/app/oracle/12c/dbhome)
(SID_NAME = dg2)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
)
)
6.用新参数重新启动数据库
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile;
File created.
SQL> startup;
ORACLE instance started.
Total System Global Area 1269366784 bytes
Fixed Size 2287912 bytes
Variable Size 805308120 bytes
Database Buffers 452984832 bytes
Redo Buffers 8785920 bytes
Database mounted.
Database opened.
[oracle@dg1 dbs]$ pwd
/u01/app/oracle/12c/dbhome/dbs
dg2:
[oracle@dg2 dbs]$ ls
bak hc_dg2.dat init.ora spfiledg2.ora
lkDG2 orapwdg2
SQL> create pfile from spfile;
[oracle@dg2 dbs]$ ls
bak hc_dg2.dat initdg2.ora lkDG2 orapwdg2
init.ora spfiledg2.ora
$ vi initdg2.ora
#standby dg2
DB_UNIQUE_NAME='dg2'
log_archive_config='DG_CONFIG=(dg1,dg2)'
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg2'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
STANDBY_FILE_MANAGEMENT=AUTO
log_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
db_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
[oracle@dg2 admin]$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dg2)
(ORACLE_HOME = /u01/app/oracle/12c/dbhome)
(SID_NAME = dg2)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
)
)
[oracle@dg2 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DG1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.4)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg1)
)
)
DG2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.5)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg2)
)
)
SQL> create spfile from pfile;
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1269366784 bytes
Fixed Size 2287912 bytes
Variable Size 788530904 bytes
Database Buffers 469762048 bytes
Redo Buffers 8785920 bytes
7.rman duplicate 复制数据库
[oracle@dg2 dbs]$ mkdir /u01/app/oracle/oradata/dg1/pdbdg1
shutdiwn immediate;startup nomount;
dg2$ rman target sys/123456@dg1 auxiliary sys/123456@dg2
RMAN>duplicate target database for standby from active database nofilenamecheck dorecover;
......
archived log file name=/u01/app/oracle/oradata/dg1/archivelog1_57_924786787.dbf thread=1 sequence=57
media recovery complete, elapsed time: 00:02:46
Finished recover at 2016:10:12 13:45:07
Finished Duplicate Db at 2016:10:12 13:45:38
RMAN>
8.启动备库数据库
SQL> alter database open;
SQL> select process,client_process,sequence#,status from v$managed_standby;
PROCESS CLIENT_PROCESS SEQUENCE# STATUS
------------------ ---------------- ---------- ------------------------
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
SQL> alter database recover managed standby database disconnect from session;
SQL> select process,client_process,sequence#,status from v$managed_standby;
PROCESS CLIENT_P SEQUENCE# STATUS
--------- -------- ---------- ------------
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
MRP0 N/A 27 WAIT_FOR_LOG
SQL> select sequence#,applied from v$archived_log;
SEQUENCE# APPLIED
---------- ------------------
51 YES
52 YES
53 YES
9.测试DG
dg1$ sqlplus / as sysdba
SQL> create tablespace mc datafile '/home/oracle/mc01.dbf' size 10M autoextend on next 5M maxsize 100M;
Tablespace created.
SQL> CREATE USER c##mcc IDENTIFIED BY mcc DEFAULT TABLESPACE mc;
User created.
SQL> grant connect,resource to c##mc;
Grant succeeded.
SQL> alter user c##mc QUOTA unlimited ON mc TEMPORARY TABLESPACE temp;
User altered.
dg1$ sqlplus c##mcc/mcc
SQL> create table bb(a varchar(3),b varchar(3));
Table created.
SQL> insert into bb values('q','q');
1 row created.
SQL> commit;
Commit complete.
dg2$ sqlplus c##mcc/mcc
SQL> desc bb;
Name Null? Type
----------------------------------------- -------- ----------------------------
A VARCHAR2(3)
B VARCHAR2(3)
SQL> select * from bb;
A B
------ ------
q q
SQL>
OK
10.参考:
http://blog.csdn.net/knuuy/article/details/47154571
http://blog.csdn.net/tianlesoftware/article/details/41675139
环境准备:
ubuntu16.04+kvm1.3.2
CentOS6.5 64bit
oracle 12c1
test@vostro-2421:/media/test/mc2t/bak/kvm/dg$ qemu-img create -f qcow2 -o size=40G ./cos6512c1.img
Formatting './cos6512c1.img', fmt=qcow2 size=42949672960 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
test@vostro-2421:/media/test/mc2t/bak/kvm/dg$ qemu-img create -f qcow2 -o size=40G ./cos6512c2.img
Formatting './cos6512c1.img', fmt=qcow2 size=42949672960 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
test@vostro-2421:/media/test/mc2t/bak/kvm/dg$ qemu-img info ./cos6512c1.img
image: ./cos6512c1.img
file format: qcow2
virtual size: 40G (42949672960 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
3G内存40G硬盘未分区,由CENTOS6.5自动处理
database server->customize now->databases不安装mysql.postgresql数据库->Desktops->Desktop.xwindowssystem->Development除eclipse,其他全安装。
vi /etc/hosts
192.168.122.4 dg1
192.168.122.5 dg2
1.规划
主库(192.168.122.4)dg1:
db_name dg1
db_unique_name dg1
service_name dg1
instance_name dg1
本地归档路径 /u01/app/oracle/oradata/dg1/archivelog
tnsnames dg2 --配置去备库的tns
备库(192.168.122.5)dg2:
db_name dg1 数据库名要一样
db_unique_name dg2 在一个dg环境里面,每一个成员的名字。
servicer_name dg2
instance_name dg2 实例名可以不一样
本地归档路径 /u01/app/oracle/oradata/dg1/archivelog
tnsnames dg1 --配置去主库的tns
2.安装ORACLE
在VNC下使用Oracle用户安装软件,,无法正常显示图形界面解决办法:root用户执行 xhost +
重装oracle:
shutdown immediate;
lsnrctl stop
echo '' > /etc/oratab
rm -rf /u01
go1/2[脚本见我的另一文档]
1:/2:[1指dg1,2指dg2服务器]
安装oracle数据库
disable I wish to receve security updates via My Oracle Support ->next -> no email ->yes ->Skip software updates ->next ->Create and configure a database ->next ->Server class ->next ->Single instance ->next ->Advanced install ->next ->add Simplified chinese ->next ->Enterprise Edition ->next ->next ->next ->next
Global database name:dg1
Oracle system identifier(SID):dg1/2
Pluggable database name: pdbdg1/2
->next
Memory:
Enable Automatic Memory Management
Allocate memory 40%
Character sets:
Traditional Chinaese ZHT16HKSCS
->next database file location:/u01/app/oracle/oradata
->next ->next
Enable Recovery File system
Recovery area location: /u01/app/oracle/recovery_area
->next
Use the same passwor all accounts:123456
->next ->yes ->next
->install
database creation complete.For details check the logfiles at:
/u01/app/oracle/cfgtoollogs/dbca/dg1
Global Database Name: dg1
System Identifier(SID): dg1/2
Server Parameter File name:/u01/app/oracle/dbhome/dbs/spfiledg1/2.ora
EM Database Express URL:https://dg1/2:5500/em
->ok ->close
log: /u01/app/oraInventory/logs/installActions2016-10-09...log
ORACLE不会自动启动,运行dbSet.sh
dg2:
./runInstaller -silent -ignorePrereq -responseFile /home/oracle/db20161009.rsp
$ netca
$ dbca
3.设置DG数据库环境
dg1/2:
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
------------------------------------------------------------------------------
YES
[oracle@dg1 dg1]$ pwd
/u01/app/oracle/oradata/dg1
[oracle@dg1 dg1]$ ls
control01.ctl pdbseed redo02.log sysaux01.dbf temp01.dbf users01.dbf
pdbdg1 redo01.log redo03.log system01.dbf undotbs01.dbf
SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/' scope=both;
SQL> alter database close;
SQL> alter database archivelog;
SQL> select GROUP#,MEMBERS,BYTES/1024/1024 from v$log;
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
1 1 50
3 1 50
2 1 50
SQL> select GROUP#,MEMBER from v$logfile;
GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
3
/u01/app/oracle/oradata/dg1/redo03.log
2
/u01/app/oracle/oradata/dg1/redo02.log
1
/u01/app/oracle/oradata/dg1/redo01.log
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo1.log' size 50M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo2.log' size 50M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo3.log' size 50M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/dg1/stdredo4.log' size 50M;
Database altered.
4.修改SPFILE参数文件
[oracle@dg1 dbs]$ mkdir bak
[oracle@dg1 dbs]$ cp *.* ./bak/
[oracle@dg1 dbs]$ cp *1 ./bak
[oracle@dg1 dbs]$ ls bak
hc_dg1.dat init.ora lkDG1 orapwdg1 spfiledg1.ora
[oracle@dg1 dbs]$ ls
bak hc_dg1.dat init.ora lkDG1 orapwdg1 spfiledg1.ora
SQL> create pfile from spfile;
[oracle@dg1 dbs]$ ls
bak hc_dg1.dat initdg1.ora init.ora lkDG1 orapwdg1 spfiledg1.ora
dg1$ vi initdg1.ora添加
#primary dg1
DB_UNIQUE_NAME='dg1'
log_archive_config='DG_CONFIG=(dg1,dg2)'
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg1'
LOG_ARCHIVE_DEST_2='SERVICE=dg2 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dg2'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
STANDBY_FILE_MANAGEMENT=AUTO
dg2$ vi initdg2.ora添加
#standby dg2
DB_UNIQUE_NAME='dg2'
log_archive_config='DG_CONFIG=(dg1,dg2)'
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg2'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
STANDBY_FILE_MANAGEMENT=AUTO
log_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
db_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
5.配置网络监听
[oracle@dg1 admin]$ pwd
/u01/app/oracle/12c/dbhome/network/admin
[oracle@dg1 admin]$ mkdir bak
[oracle@dg1 admin]$ cp *.* bak/
[oracle@dg1 admin]$ ls
bak listener.ora samples shrept.lst sqlnet.ora tnsnames.ora
[oracle@dg1 admin]$ ls bak
listener.ora shrept.lst sqlnet.ora tnsnames.ora
1/2$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DG1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.4)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg1)
)
)
DG2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.5)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg2)
)
)
1$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dg1)
(ORACLE_HOME = /u01/app/oracle/12c/dbhome)
(SID_NAME = dg1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
)
)
2$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dg2)
(ORACLE_HOME = /u01/app/oracle/12c/dbhome)
(SID_NAME = dg2)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
)
)
6.用新参数重新启动数据库
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile;
File created.
SQL> startup;
ORACLE instance started.
Total System Global Area 1269366784 bytes
Fixed Size 2287912 bytes
Variable Size 805308120 bytes
Database Buffers 452984832 bytes
Redo Buffers 8785920 bytes
Database mounted.
Database opened.
[oracle@dg1 dbs]$ pwd
/u01/app/oracle/12c/dbhome/dbs
dg2:
[oracle@dg2 dbs]$ ls
bak hc_dg2.dat init.ora spfiledg2.ora
lkDG2 orapwdg2
SQL> create pfile from spfile;
[oracle@dg2 dbs]$ ls
bak hc_dg2.dat initdg2.ora lkDG2 orapwdg2
init.ora spfiledg2.ora
$ vi initdg2.ora
#standby dg2
DB_UNIQUE_NAME='dg2'
log_archive_config='DG_CONFIG=(dg1,dg2)'
log_archive_dest_1='LOCATION=/u01/app/oracle/oradata/dg1/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg2'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
STANDBY_FILE_MANAGEMENT=AUTO
log_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
db_file_name_convert='/u01/app/oracle/oradata/dg1/archivelog','/u01/app/oracle/oradata/dg1/archivelog'
[oracle@dg2 admin]$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dg2)
(ORACLE_HOME = /u01/app/oracle/12c/dbhome)
(SID_NAME = dg2)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
)
)
[oracle@dg2 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/12c/dbhome/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DG1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.4)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg1)
)
)
DG2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.5)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dg2)
)
)
SQL> create spfile from pfile;
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1269366784 bytes
Fixed Size 2287912 bytes
Variable Size 788530904 bytes
Database Buffers 469762048 bytes
Redo Buffers 8785920 bytes
7.rman duplicate 复制数据库
[oracle@dg2 dbs]$ mkdir /u01/app/oracle/oradata/dg1/pdbdg1
shutdiwn immediate;startup nomount;
dg2$ rman target sys/123456@dg1 auxiliary sys/123456@dg2
RMAN>duplicate target database for standby from active database nofilenamecheck dorecover;
......
archived log file name=/u01/app/oracle/oradata/dg1/archivelog1_57_924786787.dbf thread=1 sequence=57
media recovery complete, elapsed time: 00:02:46
Finished recover at 2016:10:12 13:45:07
Finished Duplicate Db at 2016:10:12 13:45:38
RMAN>
8.启动备库数据库
SQL> alter database open;
SQL> select process,client_process,sequence#,status from v$managed_standby;
PROCESS CLIENT_PROCESS SEQUENCE# STATUS
------------------ ---------------- ---------- ------------------------
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
SQL> alter database recover managed standby database disconnect from session;
SQL> select process,client_process,sequence#,status from v$managed_standby;
PROCESS CLIENT_P SEQUENCE# STATUS
--------- -------- ---------- ------------
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
ARCH ARCH 0 CONNECTED
MRP0 N/A 27 WAIT_FOR_LOG
SQL> select sequence#,applied from v$archived_log;
SEQUENCE# APPLIED
---------- ------------------
51 YES
52 YES
53 YES
9.测试DG
dg1$ sqlplus / as sysdba
SQL> create tablespace mc datafile '/home/oracle/mc01.dbf' size 10M autoextend on next 5M maxsize 100M;
Tablespace created.
SQL> CREATE USER c##mcc IDENTIFIED BY mcc DEFAULT TABLESPACE mc;
User created.
SQL> grant connect,resource to c##mc;
Grant succeeded.
SQL> alter user c##mc QUOTA unlimited ON mc TEMPORARY TABLESPACE temp;
User altered.
dg1$ sqlplus c##mcc/mcc
SQL> create table bb(a varchar(3),b varchar(3));
Table created.
SQL> insert into bb values('q','q');
1 row created.
SQL> commit;
Commit complete.
dg2$ sqlplus c##mcc/mcc
SQL> desc bb;
Name Null? Type
----------------------------------------- -------- ----------------------------
A VARCHAR2(3)
B VARCHAR2(3)
SQL> select * from bb;
A B
------ ------
q q
SQL>
OK
10.参考:
http://blog.csdn.net/knuuy/article/details/47154571
http://blog.csdn.net/tianlesoftware/article/details/41675139
更多推荐
已为社区贡献3条内容
所有评论(0)