Skip to content

Instantly share code, notes, and snippets.

@RohanM
Last active May 27, 2022 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohanM/be489e29cb5dc9dc4998f70369b665d0 to your computer and use it in GitHub Desktop.
Save RohanM/be489e29cb5dc9dc4998f70369b665d0 to your computer and use it in GitHub Desktop.
Configuring access to multiple postgres databases
-- For more see: https://www.compose.com/articles/cross-database-querying-in-compose-postgresql/
-- From client database
CREATE EXTENSION postgres_fdw;
CREATE SERVER my_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'localhost', dbname 'other_db_name', port '5432');
CREATE USER MAPPING FOR my_user SERVER my_server OPTIONS (user 'my_user');
CREATE SCHEMA my_foreign_schema;
IMPORT FOREIGN SCHEMA public LIMIT TO (table1, table2, table3) FROM SERVER my_server INTO my_schema;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment