5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PostgreSQLでDBlinkを使用する方法

Posted at

PostgreSQLでDBLinkを使用する時のメモです。
DBLinkを使用することでリモートのデータベースへ接続してSQLを発行することが出来る。

dblinkを利用できるようにする

OracleDBのようにデフォルトだとDBlinkを使用できない。
extensionを導入する必要がある。

create extension dblink;

DBlintk作成して接続

select dblink_connetct('DBLINK01','host=host2 port=5432 dbname=db2 user=xxx password=xxx');
select * from dblink('DBLINK01',
                     'select id, name from table') as t1(id text, name text) ;

DBlinkのを作成しないで接続

select * from dblink('hostaddr=IPorHostname port=Port dbname=dbname user=connect_user password=Password',
                     'select id, name from table') as t1(id text, name text) ;
5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?