您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么使用PostgreSQL contrib中的dblink插件”,在日常操作中,相信很多人在怎么使用PostgreSQL contrib中的dblink插件問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”怎么使用PostgreSQL contrib中的dblink插件”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
該插件可用于連接遠(yuǎn)程PG數(shù)據(jù)庫,看起來像是Oracle的DBLink.
安裝
進(jìn)入dblink目錄,make & make install
[root@localhost contrib]# cd dblink/ [root@localhost dblink]# ls dblink--1.0--1.1.sql dblink--1.1--1.2.sql dblink--1.2.sql dblink.c dblink.control dblink--unpackaged--1.0.sql expected input Makefile output pg_service.conf sql [root@localhost dblink]# [root@localhost dblink]# make make -C ../../src/backend generated-headers make[1]: Entering directory `/data/source/postgresql-12beta1/src/backend' make -C catalog distprep generated-header-symlinks make[2]: Entering directory `/data/source/postgresql-12beta1/src/backend/catalog' make[2]: Nothing to be done for `distprep'. make[2]: Nothing to be done for `generated-header-symlinks'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/backend/catalog' make -C utils distprep generated-header-symlinks make[2]: Entering directory `/data/source/postgresql-12beta1/src/backend/utils' make[2]: Nothing to be done for `distprep'. make[2]: Nothing to be done for `generated-header-symlinks'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/backend/utils' make[1]: Leaving directory `/data/source/postgresql-12beta1/src/backend' make -C ../../src/interfaces/libpq all make[1]: Entering directory `/data/source/postgresql-12beta1/src/interfaces/libpq' make -C ../../../src/port all make[2]: Entering directory `/data/source/postgresql-12beta1/src/port' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/port' make -C ../../../src/common all make[2]: Entering directory `/data/source/postgresql-12beta1/src/common' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/common' make[1]: Leaving directory `/data/source/postgresql-12beta1/src/interfaces/libpq' gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2 -fPIC -I../../src/interfaces/libpq -I. -I. -I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2 -c -o dblink.o dblink.c -MMD -MP -MF .deps/dblink.Po gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2 -fPIC -shared -o dblink.so dblink.o -L../../src/port -L../../src/common -L../../src/interfaces/libpq -lpq -Wl,--as-needed -Wl,-rpath,'/appdb/xdb/pg12beta1/lib',--enable-new-dtags [root@localhost dblink]# make install make -C ../../src/backend generated-headers make[1]: Entering directory `/data/source/postgresql-12beta1/src/backend' make -C catalog distprep generated-header-symlinks make[2]: Entering directory `/data/source/postgresql-12beta1/src/backend/catalog' make[2]: Nothing to be done for `distprep'. make[2]: Nothing to be done for `generated-header-symlinks'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/backend/catalog' make -C utils distprep generated-header-symlinks make[2]: Entering directory `/data/source/postgresql-12beta1/src/backend/utils' make[2]: Nothing to be done for `distprep'. make[2]: Nothing to be done for `generated-header-symlinks'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/backend/utils' make[1]: Leaving directory `/data/source/postgresql-12beta1/src/backend' make -C ../../src/interfaces/libpq all make[1]: Entering directory `/data/source/postgresql-12beta1/src/interfaces/libpq' make -C ../../../src/port all make[2]: Entering directory `/data/source/postgresql-12beta1/src/port' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/port' make -C ../../../src/common all make[2]: Entering directory `/data/source/postgresql-12beta1/src/common' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/data/source/postgresql-12beta1/src/common' make[1]: Leaving directory `/data/source/postgresql-12beta1/src/interfaces/libpq' /usr/bin/mkdir -p '/appdb/xdb/pg12beta1/lib/postgresql' /usr/bin/mkdir -p '/appdb/xdb/pg12beta1/share/postgresql/extension' /usr/bin/mkdir -p '/appdb/xdb/pg12beta1/share/postgresql/extension' /usr/bin/install -c -m 755 dblink.so '/appdb/xdb/pg12beta1/lib/postgresql/dblink.so' /usr/bin/install -c -m 644 ./dblink.control '/appdb/xdb/pg12beta1/share/postgresql/extension/' /usr/bin/install -c -m 644 ./dblink--1.2.sql ./dblink--1.1--1.2.sql ./dblink--1.0--1.1.sql ./dblink--unpackaged--1.0.sql '/appdb/xdb/pg12beta1/share/postgresql/extension/' [root@localhost dblink]#
簡介
dblink可以讓PG具備在遠(yuǎn)程數(shù)據(jù)庫上執(zhí)行查詢的能力,其語法如下:
dblink(text connname, text sql [, bool fail_on_error]) returns setof record dblink(text connstr, text sql [, bool fail_on_error]) returns setof record dblink(text sql [, bool fail_on_error]) returns setof record
其中,輸入?yún)?shù):connname為連接名稱,connstr是連接串,sql為查詢語句,fail_on_error標(biāo)記出現(xiàn)錯(cuò)誤是否停止;輸出參數(shù)是產(chǎn)生的行,Record類型.由于返回沒有列信息,因此使用時(shí)需指定columns信息.
使用
遠(yuǎn)程PG數(shù)據(jù)庫部署在26.26上,希望在PG中查詢?cè)?6.26實(shí)例testdb數(shù)據(jù)庫public模式下的t1表.
testdb=# select * from t1; id ---- 1 (1 row) testdb=# \d+ t1 Table "public.t1" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+---------+---------+--------------+------------- id | integer | | | | plain | | testdb=# select * from t1; id ---- 1 (1 row)
在本機(jī)執(zhí)行以下查詢:
testdb=# create extension dblink; CREATE EXTENSION testdb=# select t1.* from dblink('host=192.168.26.26 port=5432 dbname=testdb user=xdb','select * from t1') as t1(id int); id ---- 1 (1 row)
由于需要顯式的指定的返回?cái)?shù)據(jù)行的元數(shù)據(jù),使用起來有些啰嗦.
到此,關(guān)于“怎么使用PostgreSQL contrib中的dblink插件”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。