Use the mysql_fdw extension to query an AWS-hosted MySQL database directly from PostgreSQL.
Cross-database querying avoids ETL overhead, keeps reports current, and simplifies migrations. Using mysql_fdw
, PostgreSQL treats AWS RDS or Aurora MySQL tables as native foreign tables you can read and write.
You need the RDS/Aurora endpoint, port (default 3306), a MySQL user with SELECT/INSERT/UPDATE privileges, and the database name that holds your ecommerce schema.
mysql_fdw
?On Amazon Linux: sudo yum install postgresql15-contrib mysql_fdw
. On Debian/Ubuntu: sudo apt-get install postgresql-15-mysql-fdw
. Restart PostgreSQL after installation.
Run the commands in the Syntax section. They create the extension, point a foreign server at your AWS endpoint, map credentials, then import tables.
After IMPORT FOREIGN SCHEMA
, run normal SELECT
, INSERT
, or UPDATE
on the created foreign tables, as shown in the Example Query.
Yes—mysql_fdw
supports DML. Ensure the mapped MySQL user has write privileges and include OPTIONS ("use_remote_estimate" 'true')
for better planner stats.
Use explicit casts or create PostgreSQL views that cast MySQL columns (e.g., DECIMAL
→numeric
, TINYINT(1)
→boolean
). Test inserts to confirm.
Keep the FDW in the same AWS region as MySQL to minimize latency. Push down filters in your queries (WHERE
, LIMIT
) so MySQL does the heavy lifting and reduces data transfer.
Encrypt traffic with SSL, rotate MySQL credentials, and restrict the FDW role to least privilege. Monitor pg_stat_foreign_tables for slow scans.
No. RDS PostgreSQL supports mysql_fdw
in custom DB parameter groups. For self-managed PostgreSQL, compile or install the package manually.
Yes. Add OPTIONS (sslmode 'require')
in CREATE SERVER
to enforce encryption.
Use INSERT INTO local_table SELECT * FROM foreign_table
to pull data or the reverse to push. For large volumes, rely on pg_dump
/ mysqldump
plus aws dms
.