LightDB/postgresql內建特性之訪問oracle之oracle_fdw介紹
安裝外掛
LightDB預設整合了oracle_fdw外掛
create extension oracle_fdw;
安裝Oracle客戶端
oracle輕量客戶端可直接從oracle官網下載。
instantclient-basic-linux.x64-21.6.0.0.0dbru.zip instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip
解壓到當前目錄
[lightdb@node1 ~]$ pwd /home/lightdb [lightdb@node1 ~]$ unzip instantclient-basic-linux.x64-21.6.0.0.0dbru.zip [lightdb@node1 ~]$ unzip instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip [lightdb@node1 ~]$ unzip instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip [lightdb@node1 ~]$ ls -ltr | grep 21.6 -rw-r--r-- 1 lightdb lightdb 78665919 Jul 1 11:10 instantclient-basic-linux.x64-21.6.0.0.0dbru.zip -rw-r--r-- 1 lightdb lightdb 1001535 Jul 1 11:48 instantclient-sdk-linux.x64-21.6.0.0.0dbru.zip -rw-r--r-- 1 lightdb lightdb 936841 Jul 1 13:12 instantclient-sqlplus-linux.x64-21.6.0.0.0dbru.zip drwxrwxr-x 4 lightdb lightdb 4096 Jul 1 13:16 instantclient_21_6
配置環境變數
export PATH export EDITOR=vi export GGATE= export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export ORACLE_BASE=/home/lightdb/instantclient_21_6 export ORACLE_HOME=/home/lightdb/instantclient_21_6 export ORACLE_SID= export PATH=$ORACLE_HOME:$ORACLE_HOME/OPatch:$GGATE:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME:/usr/lib:$GGATE:$LD_LIBRARY_PATH export TNS_ADMIN=$ORACLE_HOME/network/admin
建立foreign 表
Oracle使用者名稱和表名統一大寫!!!
create server oradb foreign data wrapper oracle_fdw options (dbserver '//10.0.4.4:1521/orcl1'); --對應刪除命令 postgres=# DROP SERVER IF EXISTS oradb CASCADE; NOTICE: drop cascades to foreign table haha DROP SERVER create user mapping for USER server oradb options (user 'HR', password 'HR'); -- 對應的刪除命令 postgres=# drop user mapping if exists for USER SERVER oradb; DROP USER MAPPING GRANT USAGE ON FOREIGN DATA WRAPPER oracle_fdw TO CURRENT_USER; GRANT USAGE ON FOREIGN SERVER oradb TO CURRENT_USER; create foreign table haha ( id int) SERVER oradb OPTIONS (schema 'hr', table 'haha'); -- 建立對應結構的表,在PostgreSQL端要指明表結構,對應欄位為PostgreSQL的欄位型別 drop foreign table JOBS; create foreign table JOBS (JOB_ID VARCHAR(10) NOT NULL, JOB_TITLE VARCHAR(35) NOT NULL, MIN_SALARY NUMBER(6), MAX_SALARY NUMBER(6)) SERVER oradb OPTIONS (schema 'HR', table 'JOBS'); postgres=# select * from haha; ERROR: Oracle table "hr"."haha" for foreign table "haha" does not exist or does not allow read access DETAIL: ORA-00942: table or view does not exist HINT: Oracle table names are case sensitive (normally all uppercase).
如上錯誤是因為Oracle表預設儲存底層為大寫,在PostgreSQL端如果查詢小寫表名,遍報不存在錯誤,按照如下重建即可,表名haha要指定為大寫 HAHA,使用者名稱也一樣要大寫
postgres=# drop foreign table haha; DROP FOREIGN TABLE postgres=# create foreign table haha postgres-# ( id int) postgres-# SERVER oradb OPTIONS (schema 'HR', table 'HAHA'); CREATE FOREIGN TABLE postgres=# select * from haha; id ---- 1 (1 row) postgres=# \d List of relations Schema | Name | Type | Owner --------+----------------------------------------+---------------+--------- public | baselines | table | lightdb public | baselines_bl_id_seq | sequence | lightdb public | bl_samples | table | lightdb public | dual | view | lightdb public | funcs_list | table | lightdb public | haha | foreign table | lightdb
可以看到haha表型別為foreign table,指向了oradb的hr使用者下的haha表
postgres-# \d haha Foreign table "public.haha" Column | Type | Collation | Nullable | Default | FDW options --------+---------+-----------+----------+---------+------------- id | integer | | | | Server: oradb FDW options: (schema 'HR', "table" 'HAHA')
檢視fdw server
postgres=# postgres=# select * from pg_foreign_server; oid | srvname | srvowner | srvfdw | srvtype | srvversion | srvacl | srvoptions --------+---------+----------+--------+---------+------------+---------------------+---------------------------------- 485122 | oradb | 10 | 485121 | | | {lightdb=U/lightdb} | {dbserver=//10.0.4.4:1521/orcl1} (1 row)
外部表和使用者對映關係
postgres=# select * from pg_foreign_table; ftrelid | ftserver | ftoptions ---------+----------+------------------------ 485414 | 485122 | {schema=HR,table=HAHA} (1 row) postgres=# select * from pg_user_mapping; oid | umuser | umserver | umoptions --------+--------+----------+----------------------- 485123 | 10 | 485122 | {user=hr,password=hr} (1 row) postgres=# select * from pg_foreign_data_wrapper; oid | fdwname | fdwowner | fdwhandler | fdwvalidator | fdwacl | fdwoptions --------+-----------------+----------+------------+--------------+---------------------+------------ 15199 | dblink_fdw | 10 | 0 | 15198 | | 17299 | timescaledb_fdw | 10 | 17297 | 17298 | | 485121 | oracle_fdw | 10 | 485116 | 485117 | {lightdb=U/lightdb} | (3 rows)
oracle_fdw效能削減情況
1、建立Oracle測試表
create table haha as select * from dba_objects; insert into haha select * from haha; --多次執行後,最後表記錄3900萬,表大小6018MB
伺服器配置和最終測試結果如下表格:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-2935952/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle/MySQL透過odbc訪問PostgreSQL for LightDBOracleMySql
- PostgreSQL/LightDB分割槽表之常見問題SQL
- LightDB 22.4 新特性之相容Oracle sqluldr2OracleSQL
- LightDB/PostgreSQL 設定LightDB訪問白名單pg_hba.confSQL
- LightDB 22.4 新特性之相容Oracle樹形查詢Oracle
- AnalyticDB for PostgreSQL 6.0 新特性介紹SQL
- CSS的特性之層疊性介紹CSS
- Oracle PL/SQL之 Package介紹OracleSQLPackage
- PostgreSQL之SQL函式介紹及實踐(一)SQL函式
- LightDB 22.4 新特性之支援Oracle cardinality和ordered_predicates hintOracle
- .net之oraclecommand訪問oracleOracle
- MySQL Galera Cluster的特性和不足之處介紹MySql
- LightDB 22.4 新特性之完全相容Oracle varchar2資料型別Oracle資料型別
- oracle_fdwOracle
- Python之str內部功能的介紹Python
- LightDB/PostgreSQL 相容Oracle儲存過程SQLOracle儲存過程
- LightDB 22.4 新特性之相容Oracle線上轉換普通表為分割槽表Oracle
- 從頭來之【iOS及歷史版本特性介紹】iOS
- Elasticsearch之介紹Elasticsearch
- LightDB 23.1相容Oracle新特性支援Oracle
- 使用GoldenGate 遷移Oracle到PostgreSQL/LightDBGoOracleSQL
- 【DATAGUARD】DG系列之11g新特性簡單介紹
- oracle deadlock 之(一)--鎖機制介紹Oracle
- ASP.NET Core模組化前後端分離快速開發框架介紹之3、資料訪問模組介紹ASP.NET後端框架
- PHP內建攔截器初步介紹PHP
- MyRocksTTL特性介紹
- 【INDEX】Postgresql索引介紹IndexSQL索引
- PostgreSQL:psql 介紹SQL
- Android之Zygote介紹AndroidGo
- docker之Dockerfile指令介紹Docker
- percona之tcprstat 介紹TCP
- java之Object類介紹JavaObject
- Conflux 內建合約功能介紹UX
- Python的常用內建函式介紹Python函式
- 【Python】python內建函式介紹Python函式
- SQL Server 內建轉換函式介紹SQLServer函式
- Linux Awk 內建變數使用介紹Linux變數
- SAP工作流介紹之ABAP Business Workflow介紹