环境:
OS:Centos 7
DB:13.8
1.赋予普通用户超级用户权限
因为创建扩展需要超级用户的权限,否则报如下的错误:
db_test=> create extension dblink;
ERROR: permission denied to create extension "dblink"
HINT: Must be superuser to create this extension.
postgres=# alter user hxl superuser;
ALTER ROLE
1.登录hxl用户
[postgres@host134 pg13]$ psql -h 192.168.1.134 -U hxl -p15432 -d db_test
Password for user hxl:
psql (13.8)
Type "help" for help.
db_test=>
这里我们使用用户hxl登录,登录的库为db_test
2.创建dblink扩展
需要使用超级用户登录创建
[postgres@host134 pg13]$ psql -h 192.168.1.134 -U hxl -p15432 -d db_test
postgres=# create extension dblink;
CREATE EXTENSION
3.访问其他用户的表
这里访问用户hxl01下db_test01库下的表tb_t
db_test=# select * from dblink('hostaddr=192.168.1.134 port=15432 dbname=db_test01 user=hxl01 password=postgres','select "name" from "tb_t"') AS testTable ("name" VARCHAR); name ------- name1 name2 name3 name4 name5 (5 rows)
标签:postgresql,postgres,create,db,hxl,dblink,test,垮库 From: https://www.cnblogs.com/hxlasky/p/16831947.html