Beginner LevelPostgreSQL
What are Foreign Data Wrappers (postgres_fdw) and Federated Queries?
❓ Interview Prompt: Explain Foreign Data Wrappers (FDW), SQL/MED standard, `postgres_fdw`, `CREATE SERVER`, `CREATE FOREIGN TABLE`, and federated queries.
Foreign Data Wrappers (FDWs) implement the SQL/MED (Management of External Data) standard, allowing PostgreSQL to query external databases directly as local foreign tables:
Popular FDWs:
•
'postgres_fdw': Queries remote PostgreSQL databases.
•
'file_fdw': Queries remote CSV/log files.
•
'aws_s3': Queries files in Amazon S3 buckets.
Code Implementation Example
sql
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
CREATE SERVER remote_pg_server
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host '192.168.1.50', port '5432', dbname 'analytics');
CREATE USER MAPPING FOR CURRENT_USER
SERVER remote_pg_server
OPTIONS (user 'db_user', password 'secret');
CREATE FOREIGN TABLE remote_sales (
id BIGINT,
amount NUMERIC(10,2)
) SERVER remote_pg_server OPTIONS (table_name 'sales');💡Configuring postgres_fdw to query remote PostgreSQL foreign tables.
🎯 Interview Key Takeaway
Use postgres_fdw to execute federated queries across separate remote PostgreSQL databases seamlessly.
#FDW#postgres_fdw#Federated Queries#Beginner
Back to all PostgreSQL Questions→