zoukankan      html  css  js  c++  java
  • pg创建dblink访问另外的库下的表

    pg版本:10

    [postgres@localhost ~]$ psql
    psql.bin (10.15)
    Type "help" for help.

    postgres=# l
                                      List of databases
       Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
    -----------+----------+----------+-------------+-------------+-----------------------
     db_test   | hxl      | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/hxl              +
               |          |          |             |             | hxl=CTc/hxl
     postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
     template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
     template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
    (4 rows)

    postgres=# select user;
       user   
    ----------
     postgres
    (1 row)

    创建dblink扩展
    postgres=# create extension dblink;

    查看扩展
    postgres=# select * from pg_extension;
     extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition
    ---------+----------+--------------+----------------+------------+-----------+--------------
     plpgsql |       10 |           11 | f              | 1.0        |           |
     dblink  |       10 |         2200 | t              | 1.2        |           |
    (2 rows)


    创建dblink
    postgres=# select dblink_connect('test_dblink1','dbname=db_test host=localhost port=5432 user=hxl password=postgres');

    这里的test_dblink1是dblink名

    postgres=# select * from dblink('test_dblink1','select id,name1 from tb_test limit 10') as t1(id int,name1 varchar);

    -- The End --

  • 相关阅读:
    修复grub引导Centos8和Windows
    少儿编程到底学什么?
    Windows平台最方便最易用的法语输入法
    ServiceStack.OrmLite 入门(一)
    起步:Proteus 8 仿真 Arduino 1.8.2
    命令行方式登录PostgreSQL
    CentOS 7 安装 PostgreSQL
    Twitter开源的Heron快速安装部署教程
    centos7下使用yum安装mysql
    [转]centos7 下安装MongoDB
  • 原文地址:https://www.cnblogs.com/hxlasky/p/14173016.html
Copyright © 2011-2022 走看看