greenplum資料庫建立dblink
最初使用greenplum的時候就想oracle有一個非常實用的跨庫查詢功能dblink,那麼gp庫有沒有這個功能呢,也有很多同事問道gp庫有沒有dblink,答案是有。用了很久的gp庫了一直沒使用dblink,直到後面需要用到這個功能了才去建立,gp庫的dblink建立與oracle完全不一樣,實際上去建立dblink時可是吃盡苦頭,網上查了很多,可是都沒能成功。
1.上傳包建立dblink使用的包postgresql-8.3.23.tar.gz並解壓
tar -xvf postgresql-8.3.23.tar.gz
2. 進入contrib/dblink目錄,找到Makefile檔案修改內容PG_CPPFLAGS = -I$(libpq_srcdir) -w 儲存
cd postgresql-8.3.23/contrib/dblink/
[****dblink]$ vi Makefile
# $PostgreSQL: pgsql/contrib/dblink/Makefile,v 1.15 2007/11/10 23:59:50 momjian Exp $
MODULE_big = dblink
PG_CPPFLAGS = -I$(libpq_srcdir) -w
OBJS = dblink.o
SHLIB_LINK = $(libpq)
DATA_built = dblink.sql
DATA = uninstall_dblink.sql
REGRESS = dblink
3.安裝
[***** 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/data/espine1/dev/tools/curl/7.21.7/dist/rhel5_x86_64/include -Werror -fpic -I/opt/greenplum/greenplum-db-4.3.8.0/include -w -I. -I/opt/greenplum/greenplum-db-4.3.8.0/include/postgresql/server -I/opt/greenplum/greenplum-db-4.3.8.0/include/postgresql/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/data/pulse2-agent/agents/agent1/work/GPDB-4_3_x-rcbuilds-1repo/rhel5_x86_64/src/gpAux/ext/rhel5_x86_64/include -I/data/pulse2-agent/agents/agent1/work/GPDB-4_3_x-rcbuilds-1repo/rhel5_x86_64/src/gpAux/ext/rhel5_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/data/espine1/dev/tools/curl/7.21.7/dist/rhel5_x86_64/include -Werror -fpic -shared dblink.o -L/opt/greenplum/greenplum-db-4.3.8.0/lib -L/opt/greenplum/greenplum-db-4.3.8.0/lib -L/opt/greenplum/greenplum-db-4.3.8.0/lib -L/data/pulse2-agent/agents/agent1/work/GPDB-4_3_x-rcbuilds-1repo/rhel5_x86_64/src/gpAux/ext/rhel5_x86_64/lib -lpq -Wl,-rpath,'/opt/greenplum/greenplum-db-4.3.8.0/lib',--enable-new-dtags -o dblink.so
/bin/mkdir -p '/opt/greenplum/greenplum-db-4.3.8.0/lib/postgresql'
/bin/sh /opt/greenplum/greenplum-db-4.3.8.0/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 755 dblink.so '/opt/greenplum/greenplum-db-4.3.8.0/lib/postgresql/dblink.so'
/bin/sh /opt/greenplum/greenplum-db-4.3.8.0/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./uninstall_dblink.sql '/opt/greenplum/greenplum-db-4.3.8.0/share/postgresql/contrib'
/bin/sh /opt/greenplum/greenplum-db-4.3.8.0/lib/postgresql/pgxs/src/makefiles/../../config/install-sh -c -m 644 dblink.sql '/opt/greenplum/greenplum-db-4.3.8.0/share/postgresql/contrib'
[***** dblink]$
4.使用gpscp命令 拷貝dblink.so檔案到各個節點:
[********* ~]$ gpscp -f host_seg /opt/greenplum/greenplum-db-4.3.8.0/lib/postgresql/dblink.so =:/opt/greenplum/greenplum-db-4.3.8.0/lib/postgresql/dblink.so
5.到contrib目錄下執行dblink.sql 檔案
[******** contrib]$ psql -f dblink.sql >dblink.sql.log 2>&1 &
[******** contrib]$ more dblink.sql.log
SET
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
REVOKE
REVOKE
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION........................................................
6.檢查是否成功
[****** contrib]$ psql
psql (8.2.15)
Type "help" for help.
csgbi=#
csgbi=# select * from dblink_connect('?','dbname=csgbi');
dblink_connect
----------------
OK
(1 row)
csgbi=#
已成功安裝dblink模組。