Use mysql_fdw to access MariaDB tables inside PostgreSQL as if they were local.
Bringing MariaDB data into PostgreSQL lets teams join, filter, and report across both engines without ETL. Foreign Data Wrappers (FDW) make this seamless and real-time.
Install mysql_fdw
(works for MySQL & MariaDB). It exposes remote tables as local foreign tables.
mysql_fdw
?On most Linux distributions: sudo apt install postgresql-15-mysql-fdw
. Then inside psql: CREATE EXTENSION mysql_fdw;
Create a PostgreSQL role that owns the FDW objects.Ensure the MariaDB user has SELECT (and optional INSERT/UPDATE) on target tables.
Use CREATE SERVER
with host, port, and character set. Provide options like ssl_mode
for encrypted traffic.
CREATE USER MAPPING
links your PostgreSQL role to MariaDB credentials. Store passwords securely via create or replace user mapping
.
Yes.IMPORT FOREIGN SCHEMA
pulls table definitions, saving manual typing and matching data types closely.
Run normal SELECT
, INSERT
, UPDATE
, or DELETE
. PostgreSQL planner pushes down predicates where possible for performance.
Foreign tables behave like regular ones, so joins, window functions, and CTEs work. Optimize with indexes on the MariaDB side.
Use connection pooling via foreign_server
pool_size
, enable SSL, and monitor query plans with EXPLAIN VERBOSE
.Cache immutable reference tables in PostgreSQL if latency matters.
Avoid superuser mappings, prefer SSL, and rotate MariaDB passwords. Log FDW traffic to audit access.
Use DROP FOREIGN TABLE
, DROP USER MAPPING
, and DROP SERVER
to remove connections safely without affecting MariaDB.
.
Yes, any MariaDB version exposing the MySQL protocol (10.x+) works, provided character sets align.
Yes. Grant INSERT/UPDATE/DELETE on MariaDB tables and set use_remote_estimate 'true'
if write performance is critical.
PostgreSQL treats each statement as its own transaction on the remote side. Two-phase commit isn’t supported, so use caution for cross-engine writes.