Oracle數(shù)據(jù)庫網(wǎng)關(guān)可以透明地訪問其他數(shù)據(jù)庫,Oracle HS Agent將SQL語句轉(zhuǎn)換為非Oracle數(shù)據(jù)庫(PostgreSQL)可以理解的SQL語句,并通過ODBC 數(shù)據(jù)源發(fā)送該SQL語句,在PostgreSQL中執(zhí)行后將結(jié)果返回Oracle數(shù)據(jù)庫,本文介紹如何配置并訪問PostgreSQL數(shù)據(jù)庫。
操作系統(tǒng):RHEL 6.9
軟件版本:Oracle 11.2.0.4
主機(jī)地址:192.168.21.13
監(jiān)聽端口:1521
操作系統(tǒng):RHEL 7.8
軟件版本:PostgreSQL 10.2
主機(jī)地址:192.168.21.125
服務(wù)端口:5432
數(shù)據(jù)庫名:MYPGDB
用戶密碼:mypguser/oracle
安裝并創(chuàng)建相關(guān)數(shù)據(jù)庫,使用pgadmin測試,確保遠(yuǎn)程連接正常。
yum -y install unixODBC*
yum -y install postgresql-odbc postgresql-libs
odbcinst -j
odbc_config --odbcini --odbcinstini
默認(rèn)已經(jīng)創(chuàng)建了[PostgreSQL]條目。
# Example driver definitions
# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
數(shù)據(jù)源名稱為 pgdsn,可自定義其他名稱,注意在后繼配置中引用時保持一致。
PostgreSQL數(shù)據(jù)庫名為 MYPGDB, 服務(wù)器/端口為 192.168.21.125/5432, 用戶名/密碼為 mypguser/oracle。
[pgdsn]
Driver = PostgreSQL
Description = PostgreSQL ODBC Driver
Database = MYPGDB
Servername = 192.168.21.125
Username = mypguser
Password = oracle
Port = 5432
UseDeclareFetch = 1
CommLog = /tmp/pgodbclink.log
Debug = 1
LowerCaseIdentifier = 1
[root@rhel69rac1 ~]# isql pgdsn
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> select current_database(),inet_server_port();
+-----------------------------------------------------------------+-----------------+
| current_database | inet_server_port|
+-----------------------------------------------------------------+-----------------+
| MYPGDB | 5432 |
+-----------------------------------------------------------------+-----------------+
SQLRowCount returns -1
1 rows fetched
SQL>
在 $ORACLE_HOME/hs/admin 目錄下創(chuàng)建 init<數(shù)據(jù)源名>.ora 文件,本測試為 initpgdsn.ora。
HS_FDS_CONNECT_INFO = pgdsn
HS_FDS_TRACE_LEVEL = DEBUG
HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so
set ODBCINI=/etc/odbc.ini
注意集群環(huán)境的監(jiān)聽文件位置為$GRID_HOME/network/admin/listener.ora。
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.21.13)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC=
(SID_NAME = pgdsn)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(ENVS="LD_LIBRARY_PATH=/usr/local/lib:/usr/lib64:/u01/app/oracle/product/11.2.0/db_1")
(PROGRAM=dg4odbc)
)
)
配置文件為 $ORACLE_HOME/network/admin/tnsnames.ora。
pgdsn =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST = 192.168.21.13)(PORT = 1521))
(CONNECT_DATA=(sid=pgdsn))
(HS=OK)
)
lsnrctl stop
lsnrctl start
SQL> create public database link pglink connect to "mypguser" identified by "oracle" using pgdsn;
注意表名需要添加雙引號。
SQL> select count(*) from "pg_settings"@pglink;
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/130075.html
摘要:摘要第九屆中國數(shù)據(jù)庫技術(shù)大會,阿里云數(shù)據(jù)庫產(chǎn)品專家蕭少聰帶來以阿里云如何打破遷移上云的壁壘為題的演講。于是,阿里云給出了上面的解決方案。 摘要: 2018第九屆中國數(shù)據(jù)庫技術(shù)大會,阿里云數(shù)據(jù)庫產(chǎn)品專家蕭少聰帶來以阿里云如何打破Oracle遷移上云的壁壘為題的演講。Oracle是指數(shù)據(jù)庫管理系統(tǒng),面對Oracle遷移上云的壁壘,阿里云如何能夠打破它呢?本文提出了Oracle 到云數(shù)據(jù)庫P...
閱讀 1356·2023-01-11 13:20
閱讀 1707·2023-01-11 13:20
閱讀 1215·2023-01-11 13:20
閱讀 1906·2023-01-11 13:20
閱讀 4165·2023-01-11 13:20
閱讀 2757·2023-01-11 13:20
閱讀 1402·2023-01-11 13:20
閱讀 3671·2023-01-11 13:20