亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

在PostgreSQL中訪問Oracle的具體步驟

 更新時(shí)間:2025年05月22日 10:15:39   作者:趙渝強(qiáng)老師  
在PostgreSQL數(shù)據(jù)庫中,oracle_fdw是PostgreSQL數(shù)據(jù)庫支持的外部擴(kuò)展,通過使用oracle_fdw擴(kuò)展可以讀取到Oracle數(shù)據(jù)庫中的數(shù)據(jù),本文就給大家介紹了在PostgreSQL中如何通過oracle_fdw訪問Oracle,需要的朋友可以參考下

在PostgreSQL數(shù)據(jù)庫中,oracle_fdw是PostgreSQL數(shù)據(jù)庫支持的外部擴(kuò)展。通過使用oracle_fdw擴(kuò)展可以讀取到Oracle數(shù)據(jù)庫中的數(shù)據(jù)。它是一種非常方便且常見的PostgreSQL與Oracle的同步數(shù)據(jù)的方法。使用oracle_fdw擴(kuò)展需要依賴Oracle的Instance Client環(huán)境。

下面通過具體的步驟來演示如何使用oracle_fdw擴(kuò)展。

(1)從Oracle官方網(wǎng)站下載以下3個(gè)Oracle Instance Client安裝包,如下圖所示。

instantclient-basic-linuxx64.zip 
instantclient-sdk-linuxx64.zip
instantclient-sqlplus-linuxx64.zip

(2)解壓三個(gè)文件包。

unzip instantclient-basic-linuxx64.zip 
unzip instantclient-sdk-linuxx64.zip
unzip instantclient-sqlplus-linuxx64.zip

(3)解壓后會生成instantclient_21_10目錄,將其更名為instantclient

mv instantclient_21_10 instantclient

(4)設(shè)置Oracle環(huán)境變量。

export ORACLE_HOME=/home/postgres/tools/instantclient
export OCI_LIB_DIR=$ORACLE_HOME
export OCI_INC_DIR=$ORACLE_HOME/sdk/include
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH

(5)從GitHub上下載oracle_fwd擴(kuò)展,并解壓安裝包,如下圖所示。

(6)設(shè)置pg_config的環(huán)境變量,并編譯oracle_fdw擴(kuò)展。

export PATH=/home/postgres/training/pgsql/bin:$PATH
cd oracle_fdw-ORACLE_FDW_2_5_0/
make
make install

(7)使用root用戶添加Oracle依賴的庫信息,添加完成后切換回postgres用戶。

su -
echo "/home/postgres/tools/instantclient/" >> /etc/ld.so.conf
ldconfig
su - postgres

(8)啟動PostgreSQL數(shù)據(jù)庫服務(wù)器,并登錄PostgreSQL數(shù)據(jù)庫實(shí)例創(chuàng)建oracle_fdw擴(kuò)展。

postgres=# create extension oracle_fdw;

(9)查看當(dāng)前PostgreSQL數(shù)據(jù)庫中已安裝的擴(kuò)展。

postgres=# \dx

# 輸出的信息如下:
List of installed extensions
-[ RECORD 1 ]---------------------------------------------------
Name        | file_fdw
Version     | 1.0
Schema      | public
Description | foreign-data wrapper for flat file access
-[ RECORD 2 ]---------------------------------------------------
Name        | oracle_fdw
Version     | 1.2
Schema      | public
Description | foreign data wrapper for Oracle access
-[ RECORD 3 ]---------------------------------------------------
Name        | plpgsql
Version     | 1.0
Schema      | pg_catalog
Description | PL/pgSQL procedural language
-[ RECORD 4 ]---------------------------------------------------
Name        | postgres_fdw
Version     | 1.0
Schema      | public
Description | foreign-data wrapper for remote PostgreSQL servers

(10)創(chuàng)建基于oracle_fdw的外部數(shù)據(jù)庫服務(wù)。

postgres=# create server oracle_fdw foreign data wrapper 
     oracle_fdw options(dbserver '//192.168.79.173:1521/orcl');

# 這里創(chuàng)建的外部數(shù)據(jù)庫服務(wù)名稱叫oracle_fdw,
# 并通過參數(shù)dbserver指定了外部Oracle數(shù)據(jù)庫的地址信息。

(11)查看當(dāng)前數(shù)據(jù)庫中移創(chuàng)建的外部服務(wù)。

postgres=# \des+

# 輸出的信息如下:
List of foreign servers
-[ RECORD 1 ]--------+----------------------------------------
Name                 | foreign_server
Owner                | postgres
Foreign-data wrapper | postgres_fdw
Access privileges    | 
Type                 | 
Version              | 
FDW options       | (host '192.168.79.178', port '5432', dbname 'scott')
Description          | 
-[ RECORD 2 ]--------+----------------------------------------
Name                 | oracle_fdw
Owner                | postgres
Foreign-data wrapper | oracle_fdw
Access privileges    | 
Type                 | 
Version              | 
FDW options          | (dbserver '//192.168.79.173:1521/orcl')
Description          | 
-[ RECORD 3 ]--------+-----------------------------------------------
Name                 | service_file
Owner                | postgres
Foreign-data wrapper | file_fdw
Access privileges    | 
Type                 | 
Version              | 
FDW options          | 
Description          | 

(12)創(chuàng)建PostgreSQL和Oracle之間的用戶映射。

postgres=# create user mapping for postgres server oracle_fdw 
    options (user 'c##scott', password 'tiger');

# 該語句為本地postgres用戶創(chuàng)建了一個(gè)訪問
# 遠(yuǎn)程服務(wù)器oracle_fdw時(shí)的用戶映射,
# 也就是使用用戶名c##scott和密碼 tiger連接遠(yuǎn)程服務(wù)器。

(13)查看用戶映射信息。

postgres=# \deu+

# 輸出的信息如下:
List of user mappings
-[ RECORD 1 ]------------------------------------------
Server      | foreign_server
User name   | postgres
FDW options | ("user" 'postgres', password 'Welcome_1')
-[ RECORD 2 ]------------------------------------------
Server      | oracle_fdw
User name   | postgres
FDW options | ("user" 'c##scott', password 'tiger')

(14)在PostgreSQL數(shù)據(jù)庫中創(chuàng)建外部表訪問Oracle中的數(shù)據(jù)。

postgres=# create foreign table oracle_emp(
  empno numeric(4,0) options (key 'true') not null,
  ename        varchar(10), 
  job          varchar(9) , 
  mgr          numeric(4,0), 
  hiredate     timestamp,	
  sal          numeric(7,2) , 
  comm         numeric(7,2), 
  deptno       numeric(2,0)
)server oracle_fdw 
options (schema 'C##SCOTT', table 'EMP');

# 注意,這里的'C##SCOTT'和'EMP'需要大寫。

(15)現(xiàn)在可以在本地?cái)?shù)據(jù)庫中通過外部表訪問Oracle數(shù)據(jù)庫中對應(yīng)的遠(yuǎn)程表。

postgres=# select * from oracle_emp;

# 輸出的信息如下:
 empno | ename  |...|   sal   |  comm   | deptno 
-------+--------+---+---------+---------+--------
  7369 | SMITH  |...|  800.00 |         |     20
  7499 | ALLEN  |...| 1600.00 |  300.00 |     30
  7521 | WARD   |...| 1250.00 |  500.00 |     30
  7566 | JONES  |...| 2975.00 |         |     20
  7654 | MARTIN |...| 1250.00 | 1400.00 |     30
  7698 | BLAKE  |...| 2850.00 |         |     30
  7782 | CLARK  |...| 2450.00 |         |     10
  7788 | SCOTT  |...| 3000.00 |         |     20
  7839 | KING   |...| 5000.00 |         |     10
  7844 | TURNER |...| 1500.00 |    0.00 |     30
  7876 | ADAMS  |...| 1100.00 |         |     20
  7900 | JAMES  |...|  950.00 |         |     30
  7902 | FORD   |...| 3000.00 |         |     20
  7934 | MILLER |...| 1300.00 |         |     10
(14 rows)

到此這篇關(guān)于在PostgreSQL中訪問Oracle的具體步驟的文章就介紹到這了,更多相關(guān)PostgreSQL訪問Oracle內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論