Greenplum資料庫的dblink功能之搭建
Greenplum資料庫的dblink功能之搭建
文件參考:http://blog.2ndquadrant.com/using_dblink_in_greenplum/
關鍵字: greenplum,dblink
1、什麼是dblink
dblink是一個PostgreSQL contrib模組,允許對另一個資料庫執行查詢。
當前PostgreSQL的模型需要使用者連線到一個特定的資料庫伺服器上。因此,它本身是不可能對另一個資料庫執行SQL查詢。
通常我們不鼓勵使用dblink查詢遠端資料庫。
我們總是建議使用者使用模式。但有時,這也許還不夠。
不管怎樣,這篇文章向您展示如何PostgreSQL和Greenplum是相關的。
2、準備:
greenplum資料庫:
檢查環境:看是否已經安裝了,如果已經安裝了,直接跳到第4步。
gpadmin@linux-hd1:~> pg_config --pkglibdir
/usr/local/greenplum-db/lib/postgresql/
然後在上邊這個目錄裡檢查一下各個節點主機的是否安裝。(all_host:包含你所有主備用控制節點和資料節點)
gpadmin@linux-hd1:~> gpssh -f all_host 'll /usr/local/greenplum-db/lib/postgresql/dblink.so'
1、主節點上沒有,其他節點上有的,建議重新安裝DBLINK元件
2、主節點上有,其他節點上沒有的,將主節點上的檔案複製到其他節點上。
3、安裝dblink元件
postgressql8.2版本的原始碼:(建議使用8.2的版本,9.2版本在編碼的時候報錯,提示少檔案)
下載地址:http://www.postgresql.org/ftp/source/v8.2.23/
上傳到GREENPLUM資料庫主節點上,如:上傳至/home/gpadmin
*解壓縮
gpadmin@linux-hd1:~> tar vxf postgresql-8.2.23.tar.gz
*進入dblink目錄:
gpadmin@linux-hd1:~> cd /home/gpadmin/postgresql-8.2.23/contrib/dblink/
*編輯 Makefile,在第PG_CPPFLAGS語句後面加上-w(通常是在第4行,作用是忽略警告),修改後如下:
PG_CPPFLAGS = -I$(libpq_srcdir) -w
*編譯程式碼
gpadmin@linux-hd1:~/postgresql-8.2.23/contrib/dblink> make USE_PGXS=1 install
sed 's,MODULE_PATHNAME,$libdir/dblink,g' dblink.sql.in >dblink.sql
gcc -m64 -O3 -funroll-loops -fargument-noalias-global -fno-omit-frame-pointer -g -finline-limit=1800 -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include -Werror -fpic -I/usr/local/greenplum-db-4.2.2.4/include -w -I. -I/usr/local/greenplum-db-4.2.2.4/include/postgresql/server -I/usr/local/greenplum-db-4.2.2.4/include/postgresql/internal -D_GNU_SOURCE -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include/libxml2 -c -o dblink.o dblink.c
gcc -m64 -O3 -funroll-loops -fargument-noalias-global -fno-omit-frame-pointer -g -finline-limit=1800 -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include -Werror -fpic -shared dblink.o -L/usr/local/greenplum-db-4.2.2.4/lib -L/usr/local/greenplum-db-4.2.2.4/lib -L/usr/local/greenplum-db-4.2.2.4/lib -L/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/lib -L/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/lib -lpq -Wl,-rpath,'/usr/local/greenplum-db-4.2.2.4/lib',--enable-new-dtags -o dblink.so
/bin/mkdir -p '/usr/local/greenplum-db-4.2.2.4/lib/postgresql'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 755 dblink.so '/usr/local/greenplum-db-4.2.2.4/lib/postgresql/dblink.so'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./uninstall_dblink.sql '/usr/local/greenplum-db-4.2.2.4/share/postgresql/contrib'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 dblink.sql '/usr/local/greenplum-db-4.2.2.4/share/postgresql/contrib'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./README.dblink '/usr/local/greenplum-db-4.2.2.4/doc/postgresql/contrib'
*分發dblink.so到各臺主機的指定目錄下:
注意下邊這個/home/gpadmin/host_all檔案裡要包含你所有的主用備用控制節點和資料節點
gpadmin@linux-hd1:~/postgresql-8.2.23/contrib/dblink> gpscp -f all_host dblink.so =:/usr/local/greenplum-db/lib/postgresql/dblink.so
4、建立dblink相關的系統函式:注意這個my_db是你的本地資料庫名。
gpadmin@linux-hd1:~> psql -f dblink.sql my_db
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
REVOKE
REVOKE
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE TYPE
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
5、測試dblink
*如果是在一個資料庫例項裡,可以不用寫遠端主機、使用者名稱密碼等。
*myconn是一個描述符號
*dbname=bi:是資料庫連線串。本地可以這樣寫,遠端得寫成hostaddr=***.***.***.*** port=5432 dbname=*** user=*** password=***
*insert * from select語句不能使用myconn 得寫資料庫連線串
gpadmin@linux-hd1:~> psql my_db
psql (8.2.15)
Type "help" for help.
my_db=# \l
List of databases
Name | Owner | Encoding | Access privileges
-----------+---------+----------+---------------------
bi | gpadmin | UTF8 |
createdb | gpadmin | UTF8 |
my_db | gpadmin | UTF8 |
postgres | gpadmin | UTF8 |
template0 | gpadmin | UTF8 | =c/gpadmin
: gpadmin=CTc/gpadmin
template1 | gpadmin | UTF8 | =c/gpadmin
: gpadmin=CTc/gpadmin
(6 rows)
my_db=# select dblink_connect('myconn','dbname=bi');
dblink_connect
----------------
OK
(1 row)
my_db=# select dblink_connect('myconn','dbname=bi');
ERROR: duplicate connection name
my_db=# select * from dblink('myconn','select * from public.a');
ERROR: a column definition list is required for functions returning "record"
LINE 1: select * from dblink('myconn','select * from public.a');
^
my_db=# select * from dblink('myconn','select * from public.a') AS t1(v varchar) LIMIT 5;
v
----
3
21
41
4
11
(5 rows)
my_db=# select * from dblink('myconn','select * from public.a') AS t1(v1 varchar);
v1
----
1
31
2
3
21
41
4
11
(8 rows)
my_db=# insert into public.ab select * from dblink('myconn','select * from public.a') AS t1(v1 varchar);
ERROR: could not establish connection (entry db linux-hd1:5432 pid=6389)
DETAIL: missing "=" after "myconn" in connection info string
my_db=# insert into public.ab select * from dblink('dbname=bi','select * from public.a') AS t1(v1 varchar);
INSERT 0 8
my_db=# select * from public.ab
my_db-# ;
v1
----
21
4
1
3
41
31
2
11
(8 rows)
my_db=#
至此結束。
文件參考:http://blog.2ndquadrant.com/using_dblink_in_greenplum/
關鍵字: greenplum,dblink
1、什麼是dblink
dblink是一個PostgreSQL contrib模組,允許對另一個資料庫執行查詢。
當前PostgreSQL的模型需要使用者連線到一個特定的資料庫伺服器上。因此,它本身是不可能對另一個資料庫執行SQL查詢。
通常我們不鼓勵使用dblink查詢遠端資料庫。
我們總是建議使用者使用模式。但有時,這也許還不夠。
不管怎樣,這篇文章向您展示如何PostgreSQL和Greenplum是相關的。
2、準備:
greenplum資料庫:
檢查環境:看是否已經安裝了,如果已經安裝了,直接跳到第4步。
gpadmin@linux-hd1:~> pg_config --pkglibdir
/usr/local/greenplum-db/lib/postgresql/
然後在上邊這個目錄裡檢查一下各個節點主機的是否安裝。(all_host:包含你所有主備用控制節點和資料節點)
gpadmin@linux-hd1:~> gpssh -f all_host 'll /usr/local/greenplum-db/lib/postgresql/dblink.so'
1、主節點上沒有,其他節點上有的,建議重新安裝DBLINK元件
2、主節點上有,其他節點上沒有的,將主節點上的檔案複製到其他節點上。
3、安裝dblink元件
postgressql8.2版本的原始碼:(建議使用8.2的版本,9.2版本在編碼的時候報錯,提示少檔案)
下載地址:http://www.postgresql.org/ftp/source/v8.2.23/
上傳到GREENPLUM資料庫主節點上,如:上傳至/home/gpadmin
*解壓縮
gpadmin@linux-hd1:~> tar vxf postgresql-8.2.23.tar.gz
*進入dblink目錄:
gpadmin@linux-hd1:~> cd /home/gpadmin/postgresql-8.2.23/contrib/dblink/
*編輯 Makefile,在第PG_CPPFLAGS語句後面加上-w(通常是在第4行,作用是忽略警告),修改後如下:
PG_CPPFLAGS = -I$(libpq_srcdir) -w
*編譯程式碼
gpadmin@linux-hd1:~/postgresql-8.2.23/contrib/dblink> make USE_PGXS=1 install
sed 's,MODULE_PATHNAME,$libdir/dblink,g' dblink.sql.in >dblink.sql
gcc -m64 -O3 -funroll-loops -fargument-noalias-global -fno-omit-frame-pointer -g -finline-limit=1800 -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include -Werror -fpic -I/usr/local/greenplum-db-4.2.2.4/include -w -I. -I/usr/local/greenplum-db-4.2.2.4/include/postgresql/server -I/usr/local/greenplum-db-4.2.2.4/include/postgresql/internal -D_GNU_SOURCE -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include/libxml2 -c -o dblink.o dblink.c
gcc -m64 -O3 -funroll-loops -fargument-noalias-global -fno-omit-frame-pointer -g -finline-limit=1800 -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv -I/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/include -Werror -fpic -shared dblink.o -L/usr/local/greenplum-db-4.2.2.4/lib -L/usr/local/greenplum-db-4.2.2.4/lib -L/usr/local/greenplum-db-4.2.2.4/lib -L/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/lib -L/home/build/builds/greenplum-db/Release-4_2_2_4-build-1_rc_100312-1300/Release-4_2_2_4-build-1_src/ext/suse10_x86_64/lib -lpq -Wl,-rpath,'/usr/local/greenplum-db-4.2.2.4/lib',--enable-new-dtags -o dblink.so
/bin/mkdir -p '/usr/local/greenplum-db-4.2.2.4/lib/postgresql'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 755 dblink.so '/usr/local/greenplum-db-4.2.2.4/lib/postgresql/dblink.so'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./uninstall_dblink.sql '/usr/local/greenplum-db-4.2.2.4/share/postgresql/contrib'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 dblink.sql '/usr/local/greenplum-db-4.2.2.4/share/postgresql/contrib'
/bin/sh /usr/local/greenplum-db-4.2.2.4/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./README.dblink '/usr/local/greenplum-db-4.2.2.4/doc/postgresql/contrib'
*分發dblink.so到各臺主機的指定目錄下:
注意下邊這個/home/gpadmin/host_all檔案裡要包含你所有的主用備用控制節點和資料節點
gpadmin@linux-hd1:~/postgresql-8.2.23/contrib/dblink> gpscp -f all_host dblink.so =:/usr/local/greenplum-db/lib/postgresql/dblink.so
4、建立dblink相關的系統函式:注意這個my_db是你的本地資料庫名。
gpadmin@linux-hd1:~> psql -f dblink.sql my_db
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
REVOKE
REVOKE
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE TYPE
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
5、測試dblink
*如果是在一個資料庫例項裡,可以不用寫遠端主機、使用者名稱密碼等。
*myconn是一個描述符號
*dbname=bi:是資料庫連線串。本地可以這樣寫,遠端得寫成hostaddr=***.***.***.*** port=5432 dbname=*** user=*** password=***
*insert * from select語句不能使用myconn 得寫資料庫連線串
gpadmin@linux-hd1:~> psql my_db
psql (8.2.15)
Type "help" for help.
my_db=# \l
List of databases
Name | Owner | Encoding | Access privileges
-----------+---------+----------+---------------------
bi | gpadmin | UTF8 |
createdb | gpadmin | UTF8 |
my_db | gpadmin | UTF8 |
postgres | gpadmin | UTF8 |
template0 | gpadmin | UTF8 | =c/gpadmin
: gpadmin=CTc/gpadmin
template1 | gpadmin | UTF8 | =c/gpadmin
: gpadmin=CTc/gpadmin
(6 rows)
my_db=# select dblink_connect('myconn','dbname=bi');
dblink_connect
----------------
OK
(1 row)
my_db=# select dblink_connect('myconn','dbname=bi');
ERROR: duplicate connection name
my_db=# select * from dblink('myconn','select * from public.a');
ERROR: a column definition list is required for functions returning "record"
LINE 1: select * from dblink('myconn','select * from public.a');
^
my_db=# select * from dblink('myconn','select * from public.a') AS t1(v varchar) LIMIT 5;
v
----
3
21
41
4
11
(5 rows)
my_db=# select * from dblink('myconn','select * from public.a') AS t1(v1 varchar);
v1
----
1
31
2
3
21
41
4
11
(8 rows)
my_db=# insert into public.ab select * from dblink('myconn','select * from public.a') AS t1(v1 varchar);
ERROR: could not establish connection (entry db linux-hd1:5432 pid=6389)
DETAIL: missing "=" after "myconn" in connection info string
my_db=# insert into public.ab select * from dblink('dbname=bi','select * from public.a') AS t1(v1 varchar);
INSERT 0 8
my_db=# select * from public.ab
my_db-# ;
v1
----
21
4
1
3
41
31
2
11
(8 rows)
my_db=#
至此結束。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/177006/viewspace-1274018/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- GreenPlum資料庫安裝資料庫
- 配置ORACLE資料庫到達夢資料庫的異構DBLINKOracle資料庫
- Greenplum資料庫系統架構資料庫架構
- 【greenplum】greenplum叢集搭建
- 配置達夢資料庫同構DBLINK資料庫
- 【greenplum】greenplum叢集資料庫初始化輸出內容樣例資料庫
- 達夢DBlink叢集之間通訊搭建
- Oracle資料庫連結(DBLink)中如何訪問包含BLOB欄位的資料Oracle資料庫
- 通過dblink,資料泵expdp遠端跨版本導庫
- Greenplum初始化資料庫gpinitsystem報錯以及解決資料庫
- Oracle DBLink跨資料庫訪問SQL server資料同步 踩坑實錄Oracle資料庫SQLServer
- mpp 資料庫greenplum官方商業版本與開源版本的差異資料庫
- 達夢DM7 資料庫之資料守護DG搭建資料庫
- MySQL-主從複製之搭建從資料庫MySql資料庫
- MySQL-主從複製之搭建主資料庫MySql資料庫
- 資料庫安全審計在資料安全中的功能資料庫
- Python3爬蟲資料入資料庫---把爬取到的資料存到資料庫,帶資料庫去重功能Python爬蟲資料庫
- Postgresql10資料庫之更改資料庫的名稱SQL資料庫
- 基於Greenplum,postgreSQL的大型資料倉儲實踐SQL
- AWSredshift->hdbpg(Greenplum),資料庫-S3匯入匯出(unload,externaltable)-hdbpgexternaltable資料庫S3
- (資料庫之pymysql)資料庫MySql
- 配置Oracle DBlink連線MySQL庫OracleMySql
- 並推出了關係型資料庫功能來補充其核心NoSQL資料庫功能資料庫SQL
- ETL資料整合丨將GreenPlum資料同步至Doris數倉
- 【MySQL資料庫】認識資料庫+環境搭建--------Windows系統MySql資料庫Windows
- mongo資料庫單節點搭建Go資料庫
- 搭建 mariadb 資料庫主從同步資料庫主從同步
- 資料庫系統概述之國產資料庫資料庫
- 國產資料庫調研之——AntDB資料庫資料庫
- 大資料之Hadoop偽分散式的搭建大資料Hadoop分散式
- 為VNPY增加資料庫記錄交易資料功能資料庫
- 資料庫升級之-資料泵資料庫
- MySQL資料庫之索引MySql資料庫索引
- 資料庫安全之金融資料庫
- 資料庫之建立索引資料庫索引
- Go之資料庫操作Go資料庫
- mongoDB資料庫之聚合MongoDB資料庫
- luffy之資料庫配置資料庫
- 資料庫系統概述之資料庫最佳化資料庫