PostgreSQL
PostgreSQL # root directory of your Database
├── Events
├── Federate
│ ├── Database_Server (shop_bluesafety_com)
│ │ ├── Server
│ │ │ ├── Events
│ │ │ ├── Functions
│ │ │ ├── Procedures
│ │ │ ├── Tables
│ │ │ └── Views
│ │ ├── Tables
│ │ ├── mapping.sql
│ │ └── server.sql
│ └── ...
├── Functions
├── Procedures
├── Trigger
├── Tables
└── Views
Federation of MySQL
-- 1) Install extension (needs mysql_fdw installed on the server)
CREATE EXTENSION IF NOT EXISTS mysql_fdw;
-- 2) Define remote server
CREATE SERVER mysql_svr
FOREIGN DATA WRAPPER mysql_fdw
OPTIONS (host 'mysql-host', port '3306');
-- 3) User mapping (use a MySQL user)
CREATE USER MAPPING FOR CURRENT_USER
SERVER mysql_svr
OPTIONS (username 'mysql_user', password 'mysql_pass');
-- 4) Create foreign table (example)
CREATE FOREIGN TABLE public.mysql_customers (
id integer,
email text,
created_at timestamp
)
SERVER mysql_svr
OPTIONS (dbname 'mysql_db', table_name 'customers');
-- Query it
SELECT * FROM public.mysql_customers WHERE id = 42;
-- For granting User
GRANT USAGE ON SCHEMA public TO db_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO db_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT ON TABLES TO db_user;