Last active
September 5, 2018 21:15
-
-
Save MrHen/f16387c9f6cd16a13be74b0ff951c825 to your computer and use it in GitHub Desktop.
Postgres FDW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION IF NOT EXISTS postgres_fdw; | |
CREATE EXTENSION IF NOT EXISTS dblink; | |
CREATE SERVER {server_name} | |
FOREIGN DATA WRAPPER postgres_fdw | |
OPTIONS ( | |
host {src_host}, | |
port {src_port}, | |
dbname {src_db} | |
) | |
; | |
CREATE USER MAPPING | |
FOR CURRENT_USER | |
SERVER {server_name} | |
OPTIONS ( | |
user {src_username} | |
password {src_password} | |
) | |
; | |
CREATE SCHEMA IF NOT EXISTS {dst_schema}; | |
DROP FOREIGN TABLE IF EXISTS {dst_schema}.{src_table} CASCADE; | |
IMPORT FOREIGN SCHEMA {src_schema} | |
LIMIT TO ({src_table}) | |
FROM SERVER {server_name} | |
INTO {dst_schema} | |
; | |
select * | |
from information_schema.foreign_tables | |
; | |
select | |
srvname as name, | |
srvowner::regrole as owner, | |
fdwname as wrapper, | |
srvoptions as options | |
from pg_foreign_server | |
join pg_foreign_data_wrapper w on w.oid = srvfdw; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment