ORACLE19.8 RAC搭建ADG-主备都在原主机上配置关于PDB连接
标签: oracle19c
我们知道多租户环境下,pdb中建立的普通用户连接pdb需要通过tnsnames.ora或ezconnect的方式连接。而pdb的连接需要通过IP、端口和PDB服务名来连接,那么相同主机adg的情况下,备库的IP和PDB和主库是完全相同的。所以我们只能考虑通过区分端口来进行主备pdb的连接。
配置需要考虑如下步骤:
1.grid通过netca创建新的监听服务比如DGLISTENER,端口为2521(不能使用主机已经占用的端口)
2.grid用户创建好新的监听后,修改监听文件添加静态注册参数:
节点1添加实例1的名称:
-
DGLISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=DGLISTENER)))) # line added by Agent
-
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
-
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
-
ASMNET1LSNR_ASM=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=ASMNET1LSNR_ASM)))) # line added by Agent
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_ASMNET1LSNR_ASM=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_ASMNET1LSNR_ASM=SUBNET # line added by Agent
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_LISTENER_SCAN1=OFF # line added by Agent - Disabled by Agent because REMOTE_REGISTRATION_ADDRESS is set
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_LISTENER=SUBNET # line added by Agent
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_DGLISTENER=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_DGLISTENER=SUBNET # line added by Agent
-
SID_LIST_LISTENER =
-
(SID_LIST =
-
(SID_DESC =
-
(GLOBAL_DBNAME = orcl)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = orcl1)
-
)
-
(SID_DESC =
-
(GLOBAL_DBNAME = orcl_DGMGRL)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = orcl1)
-
)
-
)
-
SID_LIST_DGLISTENER =
-
(SID_LIST =
-
(SID_DESC =
-
(GLOBAL_DBNAME = dgorcl)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = dgorcl1)
-
)
-
(SID_DESC =
-
(GLOBAL_DBNAME = dgorcl_DGMGRL)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = dgorcl1)
-
)
-
)
节点2添加实例2的名称:
-
DGLISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=DGLISTENER)))) # line added by Agent
-
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
-
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent
-
ASMNET1LSNR_ASM=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=ASMNET1LSNR_ASM)))) # line added by Agent
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_ASMNET1LSNR_ASM=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_ASMNET1LSNR_ASM=SUBNET # line added by Agent
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_LISTENER=SUBNET # line added by Agent
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_LISTENER_SCAN1=OFF # line added by Agent - Disabled by Agent because REMOTE_REGISTRATION_ADDRESS is set
-
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_DGLISTENER=ON # line added by Agent
-
VALID_NODE_CHECKING_REGISTRATION_DGLISTENER=SUBNET # line added by Agent
-
SID_LIST_LISTENER =
-
(SID_LIST =
-
(SID_DESC =
-
(GLOBAL_DBNAME = orcl)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = orcl2)
-
)
-
(SID_DESC =
-
(GLOBAL_DBNAME = orcl_DGMGRL)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = orcl2)
-
)
-
)
-
SID_LIST_DGLISTENER =
-
(SID_LIST =
-
(SID_DESC =
-
(GLOBAL_DBNAME = dgorcl)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = dgorcl2)
-
)
-
(SID_DESC =
-
(GLOBAL_DBNAME = dgorcl_DGMGRL)
-
(ORACLE_HOME = /oracle/app/oracle/product/19c/dbhome_1)
-
(SID_NAME = dgorcl2)
-
)
-
)
重启监听:
srvctl stop listener -l LISTENER
srvctl stop listener -l DGLISTENER
srvctl start listener -l LISTENER
srvctl start listener -l DGLISTENER
检查服务:
lsnrctl status LISTENER
lsnrctl status DGLISTENER
3.oracle用户添加tnsnames.ora
两个节点内容一致,设置如下:
-
[oracle@rac1 admin]$ cat tnsnames.ora
-
# tnsnames.ora Network Configuration File: /oracle/app/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora
-
# Generated by Oracle configuration tools.
-
scan-orcl =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = orcl)
-
)
-
)
-
scan-dgorcl =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 2521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = dgorcl)
-
)
-
)
-
scan_orcl_pdb =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = pdb)
-
)
-
)
-
scan_dgorcl_pdb =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 2521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = pdb)
-
)
-
)
-
scan_orcl_jyc =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = jyc)
-
)
-
)
-
scan_dgorcl_jyc =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 2521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = jyc)
-
)
-
)
-
orcl =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 1521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 1521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = orcl)
-
)
-
)
-
dgorcl =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 2521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 2521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = dgorcl)
-
)
-
)
-
tns_orcl =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 1521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 1521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = orcl)
-
)
-
)
-
tns_dgorcl =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 2521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 2521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = dgorcl)
-
)
-
)
-
orcl_pdb =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 1521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 1521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = pdb)
-
)
-
)
-
dgorcl_pdb =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 2521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 2521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = pdb)
-
)
-
)
-
orcl_jyc =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 1521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 1521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = jyc)
-
)
-
)
-
dgorcl_jyc =
-
(DESCRIPTION =
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 2521))
-
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 2521))
-
(CONNECT_DATA =
-
(SERVER = DEDICATED)
-
(SERVICE_NAME = jyc)
-
)
-
)
tnsping 服务名测试,确认OK:
[oracle@rac1 admin]$ tnsping orcl
TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 31-JUL-2020 11:22:18
Copyright (c) 1997, 2020, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (0 msec)
[oracle@rac1 admin]$ tnsping dgorcl
TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 31-JUL-2020 11:22:21
Copyright (c) 1997, 2020, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.183)(PORT = 2521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.52.184)(PORT = 2521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dgorcl)))
OK (0 msec)
4.修改LOCAL_LISTENER、remote_listener
增加scan listener端口
srvctl modify scan_listener -endpoints "TCP:1521/TCP:2521"
节点1:
export ORACLE_SID=orcl1
sqlplus / as sysdba
alter system set local_listener ='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.52.183)(PORT=1521))' scope=both sid='orcl1';
alter system set remote_listener ='rac-scan:1521' scope=both sid='orcl1';
export ORACLE_SID=dgorcl1
sqlplus / as sysdba
alter system set local_listener ='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.52.183)(PORT=2521))' scope=both sid='dgorcl1';
alter system set remote_listener ='rac-scan:2521' scope=both sid='dgorcl1';
节点2:
export ORACLE_SID=orcl2
sqlplus / as sysdba
alter system set local_listener ='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.52.184)(PORT=1521))' scope=both sid='orcl2';
alter system set remote_listener ='rac-scan:1521' scope=both sid='orcl2';
export ORACLE_SID=dgorcl2
sqlplus / as sysdba
alter system set local_listener ='(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.52.184)(PORT=2521))' scope=both sid='dgorcl2';
alter system set remote_listener ='rac-scan:2521' scope=both sid='dgorcl2';
重启监听:
srvctl stop listener -l LISTENER
srvctl stop listener -l DGLISTENER
srvctl start listener -l LISTENER
srvctl start listener -l DGLISTENER
检查服务,确认端口1521只监听主库的服务,2521只监听备库的服务,基本就没问题了。一般测试过程结合数据库后台日志alert查看是否有异常,根据问题再排查处理即可。
lsnrctl status LISTENER
lsnrctl status DGLISTENER
5.测试连接:
sqlplus sys/oracle@orcl as sysdba
sqlplus sys/oracle@dgorcl as sysdba
sqlplus jyc/jyc@dgorcl_pdb
sqlplus jyc/jyc@dgorcl_jyc
[oracle@rac1 ~]$ sqlplus sys/oracle@dgorcl as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jul 31 11:27:13 2020
Version 19.8.0.0.0
Copyright (c) 1982, 2020, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0
SQL> show parameter name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cdb_cluster_name string
cell_offloadgroup_name string
db_file_name_convert string +DATA, +DATA
db_name string orcl
db_unique_name string dgorcl
global_names boolean FALSE
instance_name string dgorcl1
lock_name_space string
log_file_name_convert string +DATA, +DATA
pdb_file_name_convert string
processor_group_name string
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string dgorcl
SQL> select INSTANCE_NUMBER from v$instance;
INSTANCE_NUMBER
---------------
1
SQL> conn jyc/jyc@dgorcl_pdb
ERROR:
ORA-01109: database not open
Warning: You are no longer connected to ORACLE.
SQL> conn jyc/jyc@dgorcl_pdb
ERROR:
ORA-01109: database not open
SQL> conn jyc/jyc@dgorcl_jyc
ERROR:
ORA-01109: database not open
SQL> conn sys/oracle@dgorcl as sysdba
Connected.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB MOUNTED
4 JYC MOUNTED
SQL> alter pluggable database all open instances=all;
Pluggable database altered.
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ ONLY NO
4 JYC READ ONLY NO
SQL> alter database recover managed standby database using current logfile disconnect;
Database altered.
SQL> set line 160
SQL> set wrap off
SQL> col inst_id for 99
SQL> col FORCE_LOGGING for a4
SQL> select INST_ID, dbid,name,DB_UNIQUE_NAME,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from gv$database
INST_ID DBID NAME DB_UNIQUE_NAME CURRENT_SCN PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
------- ---------- --------- ------------------------------ ----------- -------------------- ---------------- ---- -------------------- --------------------
1 1574560670 ORCL dgorcl 4477548 MAXIMUM PERFORMANCE PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED
2 1574560670 ORCL dgorcl 4477548 MAXIMUM PERFORMANCE PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED
SQL> conn sys/oracle@orcl as sysdba
Connected.
SQL> select INST_ID, dbid,name,DB_UNIQUE_NAME,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from gv$database;
INST_ID DBID NAME DB_UNIQUE_NAME CURRENT_SCN PROTECTION_MODE DATABASE_ROLE FORC OPEN_MODE SWITCHOVER_STATUS
------- ---------- --------- ------------------------------ ----------- -------------------- ---------------- ---- -------------------- --------------------
2 1574560670 ORCL orcl 4477580 MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY
1 1574560670 ORCL orcl 4477580 MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY
SQL> conn jyc/jyc@dgorcl_pdb
Connected.
SQL> conn jyc/jyc@dgorcl_jyc
Connected.
SQL>
版权声明:本文为jycjyc原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:oracle19.8 rac搭建adg-主备都在原主机上配置关于pdb连接_adg 备库pdb连接_好记忆不如烂笔头abc的博客-CSDN博客