Export PostgreSQL data, transform incompatible types, and import into MariaDB with minimal downtime.
MariaDB can reduce licensing costs, simplify replication setups, and integrate easily with MySQL-compatible tools. Moving from on-premise PostgreSQL to MariaDB also eases cloud adoption because most managed databases support the MySQL protocol.
Small databases (<10 GB) work well with CSV exports and LOAD DATA INFILE
. Larger sets benefit from logical replication tools like pg_chameleon
, while near-zero-downtime moves combine pg_dump
for initial load with CDC tools (e.g., Debezium) for catch-up.
List all PostgreSQL column types and map them: BOOLEAN → TINYINT(1)
, TEXT → LONGTEXT
, UUID → CHAR(36)
, TIMESTAMPTZ → DATETIME
. Create staging tables in MariaDB with compatible types before import to avoid runtime errors.
Use pg_dump
with --column-inserts
or CSV format. The latter produces faster imports because MariaDB can bulk-load files.
# full CSV export
pg_dump -h 192.168.1.10 -U admin -F c -t Customers -t Orders -t Products \
--data-only --file=ecom_backup.dump ecommerce
# single table CSV
psql -h 192.168.1.10 -U admin -d ecommerce -c \
"\COPY Customers TO 'customers.csv' CSV"
Copy exported files to the MariaDB server. Then bulk-load:
LOAD DATA INFILE '/var/lib/mysql-files/customers.csv'
INTO TABLE Customers
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';
Run row-count checks: SELECT COUNT(*) FROM Customers;
in both systems. Spot-check totals (SUM(total_amount)
) on Orders. For strict validation, hash full tables with MD5(GROUP_CONCAT(...))
and compare.
1) Freeze writes on PostgreSQL. 2) Export delta via logical replication or WAL2JSON. 3) Apply deltas to MariaDB. 4) Update application connection strings. Keep PostgreSQL read-only for rollback.
• Migrate least critical tables first.
• Disable foreign-key checks during bulk load (SET foreign_key_checks = 0;
).
• Enable binary logging after import to keep backups consistent.
• Index after loading to speed inserts.
Data type mismatch: Failing to convert NUMERIC
to DECIMAL
causes silent truncation. Map types explicitly before import.
Ignoring time zones: PostgreSQL stores TIMESTAMPTZ
in UTC, but MariaDB’s DATETIME
is naive. Convert to UTC strings during export to keep timestamps correct.
✔️ Schema recreated in MariaDB
✔️ All tables loaded and validated
✔️ Triggers, defaults, and constraints re-implemented
✔️ Application connection strings switched
✔️ Rollback plan documented
No. PostgreSQL PL/pgSQL differs from MariaDB SQL/PSM. Rewrite logic manually or move it to the application layer.
Rough estimate: 5–10 GB/hour with CSV and LOAD DATA
. Network bandwidth and disk I/O are the primary bottlenecks.
Direct replication is unsupported. Use an intermediary CDC tool (Debezium, Maxwell) to stream changes into MariaDB.