Use mysql_fdw to access a cloud-hosted MySQL instance directly from PostgreSQL.
Cloud-hosted MySQL refers to a managed MySQL server running on services such as Amazon RDS, Google Cloud SQL, or Azure Database for MySQL. The provider handles backups, scaling, and patches.
Yes. Install the mysql_fdw
extension, create a foreign server that points to the cloud host, and map remote tables so they appear local to PostgreSQL.
mysql_fdw
keeps data live.Queries run in PostgreSQL always hit the latest rows in MySQL, eliminating batch pipelines and reducing latency.
mysql_fdw
?On most Linux distributions: sudo apt install postgresql-15-mysql-fdw
or build from source. Restart PostgreSQL and verify with CREATE EXTENSION mysql_fdw;
.
Allow inbound traffic from your PostgreSQL server’s IP to the MySQL cloud instance on port 3306. Use TLS for encrypted transport.
Create a service account with SELECT
on the target schema.For write access, grant INSERT
, UPDATE
, or DELETE
as needed.
Push joins and filters to MySQL using the OPTIONS (use_remote_estimate 'true')
clause. Add indexes on columns used in WHERE clauses.
Store the MySQL username and password in pgpass
or use CREATE USER MAPPING
with password_encrypted
. Avoid hard-coding in SQL files.
Run IMPORT FOREIGN SCHEMA
again when new MySQL tables appear, or script periodic refreshes with cron
.
Yes.Include OPTIONS (autocommit 'true')
in the foreign table definition and ensure the FDW was compiled with write support.
.
Yes, many companies use it in production. Monitor query plans and stay current with releases.
Yes. PostgreSQL sends prepared queries to MySQL, improving performance for repetitive workloads.
Use logical replication tools like Debezium or AWS DMS if you need a local copy rather than live access.