本文分別介紹GuassDB跨集羣訪問遠端oracle以及遠端MPPDB數據庫。因環境有限,這裏不列舉對接HDFS以及對接Spark功能。node
Gaussdb要求的unixODBC版本必須爲2.3.6。操做系統自帶的版本不能正常使用,須要從官方網站單獨下載並編譯安裝。linux
[root@hd06 ~]# tar -xzf unixODBC-2.3.6.tar.gz [root@hd06 ~]# cd unixODBC-2.3.6 [root@hd06 unixODBC-2.3.6]# ./configure [root@hd06 unixODBC-2.3.6]# make [root@hd06 unixODBC-2.3.6]# make install
安裝完成後,須要指定庫文件的環境變量,不然使用過程當中會報錯。web
[root@hd06 ~]# vi /etc/profile export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib [root@hd06 ~]# isql --version unixODBC 2.3.6 [root@hd06 ~]# su - omm Last login: Tue Oct 29 16:35:31 CST 2019 [omm@hd06 ~]$ isql --version unixODBC 2.3.6
保存完成後,必須使環境變量生效。sql
從oracle官方網站下載以下三個壓縮包,而後壓縮爲package.zip文件。數據庫
[root@hd06 tmp]# zip package.zip instantclient-*.zip adding: instantclient-basic-linux.x64-12.2.0.1.0.zip (stored 0%) adding: instantclient-odbc-linux.x64-12.2.0.1.0-2.zip (stored 0%) adding: instantclient-sqlplus-linux.x64-12.2.0.1.0.zip (stored 0%)
登陸FusionInsight Manager>選擇「集羣 > 待操做的集羣名稱 > 服務 > MPPDB > 對接 > 對接Oracle」,單擊「建立」,填寫配置組名稱,單擊「肯定」。以下圖所示:
參數說明見下表:
輸入相關配置參數並上傳驅動文件「package.zip」,單擊「上傳並部署」,等待部署完成。部署完成後,單擊「保存」。等待保存配置成功,單擊「完成」。而後在集羣「概覽」頁面,選擇「更多 > 重啓」,執行相應操做重啓服務。
注:在服務重啓的過程當中,系統會把odbc驅動分發到各個節點以完成部署。ODBC的部署目錄爲:/opt/huawei/Bigdata/mppdb/core/utilslib/fc_conf。oracle
從主機上切換到omm用戶,並鏈接到mppdb數據庫,執行下面的語句建立:ide
[root@hd06 ~]# su - omm Last login: Tue Oct 29 16:43:45 CST 2019 [omm@hd06 ~]$ gsql -d postgres -p 25308 gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#CREATE DATA SOURCE ds_oracle TYPE 'ORACLE' OPTIONS (DSN 'oracle_DSN', USERNAME 'spwuser', PASSWORD 'redhat', ENCODING 'UTF8'); CREATE DATA SOURCE
使用下面的語句驗證是否能夠鏈接到遠端oracle數據庫:函數
postgres=# SELECT * FROM exec_on_extension('ds_oracle', 'select * from web_customer;') AS (c1 int,c2 text,c3 text,c4 text);
以下圖所示:
注:使用「exec_on_extension」以前須要建立Data Source對象。
如下舉例將遠端的查詢結果導入本地表:post
[omm@hd06 ~]$ gsql -d postgres -p 25308 gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#\c rhnschema rhnschema=# CREATE TABLE dd AS SELECT * FROM exec_on_extension('ds_oracle', 'select * from rhnpackagefile;') AS (package_id numeric,capability_id numeric,device numeric, inode numeric,file_mode numeric,username character varying(32),groupname character varying(32),rdev numeric,file_size numeric,mtime timestamp with time zone, checksum_id numeric,linkto character varying(256),flags numeric,verifyflags numeric,lang character varying(32),created timestamp with time zone,modified timestamp with time zone); NOTICE: The 'DISTRIBUTE BY' clause is not specified. Using 'package_id' as the distribution column by default. HINT: Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column. INSERT 0 6304854 rhnschema=# select count(*) from dd; count --------- 6304854 (1 row)
GaussDB 200支持兩種方式訪問遠端MPPDB數據庫集羣,包括經過FusionInsight Manager配置方式和建立Foreign Table的方式。性能
[omm@hd03 ~]$ gs_guc check -Z coordinator -I all -c "listen_addresses" expected guc information: hd02: listen_addresses=NULL: [/srv/BigData/mppdb/data1/coordinator/postgresql.conf] gs_guc check: hd02: listen_addresses='localhost,192.168.110.24': [/srv/BigData/mppdb/data1/coordinator/postgresql.conf] Total GUC values: 1. Failed GUC values: 0. The value of parameter listen_addresses is same on all instances. listen_addresses='localhost,192.168.110.24'
若是沒有監聽業務IP,可使用下面的方法將其加入監聽裏:
[omm@hd03 ~]$ gs_guc set -I all -Z coordinator -c "listen_addresses='localhost,192.168.110.24'" expected instance path: [/srv/BigData/mppdb/data1/coordinator/postgresql.conf] gs_guc set: listen_addresses='*': [/srv/BigData/mppdb/data1/coordinator/postgresql.conf] Total instances: 1. Failed instances: 0. Success to perform gs_guc!
以上只在集羣的一個節點有效,其餘節點也須要單獨操做。另外多個IP之間,用逗號隔開。
在遠端集羣CN設置認證方式
默認狀況下,系統只容許集羣各個節點之間互相通訊。若是其餘網段須要訪問就必須設置認證方式,這個在任意一個節點執行便可。
[omm@hd01 ~]$ gs_guc reload -Z coordinator -N all -I all -h "host all all 192.168.120.0/24 sha256" Begin to perform gs_guc for all coordinators. Total instances: 3. Failed instances: 0. Success to perform gs_guc!
設置完成後,重啓集羣:
[omm@hd01 ~]$ gs_om -t stop && gs_om -t start
[omm@hd06 ~]$ gsql -d postgres -p 25308 gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=# CREATE DATA SOURCE ds_mppdb type 'MPPDB' OPTIONS (DSN 'mppdb_DSN', USERNAME 'spwuser', PASSWORD 'abcABC12', ENCODING 'UTF8'); CREATE DATA SOURCE postgres=# SELECT * FROM exec_on_extension('ds_oracle', 'select * from web_customer;') AS (c1 int,c2 text,c3 text,c4 text); c1 | c2 | c3 | c4 ----+------+-----------------------------+----------------------------- 1 | xzxj | 2019-4-11 8:42:35.094133000 | 2019-4-11 8:42:35.094168000 (1 row)
注意事項:
postgres=# CREATE SERVER Gauss1 FOREIGN DATA WRAPPER GC_FDW OPTIONS (address '192.168.110.22:25308,192.168.110.23:25308,192.168.110.24:25308' , dbname 'rhnschema', username 'spwuser', password 'abcABC12');
建立外表並查看
postgres=# CREATE FOREIGN TABLE f_web_customer ( ID NUMERIC, NAME character varying(128), CREATED timestamp with time zone, MODIFIED timestamp with time zone ) SERVER Gauss1 OPTIONS ( schema_name 'public', table_name 'web_customer', encoding 'UTF-8' ); postgres=# \d f_web_customer;
使用外表進行導入數據
postgres=# CREATE TABLE local_web_customer ( ID NUMERIC, NAME character varying(128), CREATED timestamp with time zone, MODIFIED timestamp with time zone ); postgres=# INSERT INTO local_web_customer SELECT * FROM f_web_customer; INSERT 0 1 postgres=# select *from local_web_customer;