-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres_fdw.sql
More file actions
28 lines (23 loc) · 1.09 KB
/
Copy pathpostgres_fdw.sql
File metadata and controls
28 lines (23 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- =============================================================================
-- Example: postgres_fdw (query another PostgreSQL server)
-- These are NOT auto-run — copy/paste and adapt to a real remote server.
-- =============================================================================
-- 1) Define the remote server.
CREATE SERVER IF NOT EXISTS remote_pg
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'remote-postgres.example.com', port '5432', dbname 'remote_db');
-- 2) Map your local user to a remote login.
CREATE USER MAPPING IF NOT EXISTS FOR CURRENT_USER
SERVER remote_pg
OPTIONS (user 'remote_user', password 'remote_password');
-- 3a) Import an entire remote schema as foreign tables.
-- IMPORT FOREIGN SCHEMA public
-- FROM SERVER remote_pg INTO public;
-- 3b) ...or declare a single foreign table by hand.
-- CREATE FOREIGN TABLE remote_customers (
-- id bigint,
-- name text,
-- email text
-- ) SERVER remote_pg OPTIONS (schema_name 'public', table_name 'customers');
-- 4) Query it like a local table:
-- SELECT * FROM remote_customers LIMIT 10;