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
- LightDB 22.4 新特性之相容Oracle sqluldr2OracleSQL
- LightDB 22.4 新特性之相容Oracle樹形查詢Oracle
- PostgreSQL/LightDB分割槽表之常見問題SQL
- LightDB/PostgreSQL 設定LightDB訪問白名單pg_hba.confSQL
- LightDB 22.4 新特性之支援Oracle cardinality和ordered_predicates hintOracle
- AnalyticDB for PostgreSQL 6.0 新特性介紹SQL
- LightDB 22.4 新特性之完全相容Oracle varchar2資料型別Oracle資料型別
- oracle_fdwOracle
- CSS的特性之層疊性介紹CSS
- LightDB/PostgreSQL 相容Oracle儲存過程SQLOracle儲存過程
- 使用GoldenGate 遷移Oracle到PostgreSQL/LightDBGoOracleSQL
- LightDB 22.4 新特性之相容Oracle線上轉換普通表為分割槽表Oracle
- lightdb的merge into使用介紹
- PostgreSQL之SQL函式介紹及實踐(一)SQL函式
- Python之str內部功能的介紹Python
- LightDB 23.1相容Oracle新特性支援Oracle
- 貼程式碼框架PasteForm特性介紹之markdown和richtext框架ASTORM
- Elasticsearch之介紹Elasticsearch
- LightDB23.1新特性支援Oracle hint增強DB2Oracle
- Conflux 內建合約功能介紹UX
- Android之Zygote介紹AndroidGo
- oracle 10G特性之awrOracle 10g
- SQL Server 2022 AlwaysOn新特性之包含可用性組介紹SQLServer
- PostgreSQL:psql 介紹SQL
- 【SQL】SQL表連線方法方式介紹(Oracle/Postgresql)SQLOracle
- MyRocksTTL特性介紹
- iOS UIButton之UIControlEvents介紹iOSUI
- Spring框架之IOC介紹Spring框架
- ASP.NET Core模組化前後端分離快速開發框架介紹之3、資料訪問模組介紹ASP.NET後端框架
- 【INDEX】Postgresql索引介紹IndexSQL索引
- SAP工作流介紹之ABAP Business Workflow介紹
- Jetbrains CLion特性介紹AI
- Jetbrains pycharm特性介紹AIPyCharm
- Jetbrains datagrip特性介紹AI
- Jetbrains goland特性介紹AIGoLand
- HTTP之訪問控制「CORS」HTTPCORS
- Python 內建函式:——locals 和 globals介紹Python函式