---
title: "MySQL/MariaDB to PostgreSQL Migration"
description: "We have moved several Ruby on Rails projects from MySQL/MariaDB to PostgreSQL and know how to do it with minimal downtime and no data loss."
url: "https://qameta.com/mysql-to-postgresql-migration/"
---

# MySQL/MariaDB to PostgreSQL Migration

We have moved several production projects from MySQL/MariaDB to PostgreSQL.
It is a common step once a project outgrows MySQL's feature set or needs
capabilities PostgreSQL handles better - and it is not something to attempt
without a plan.

## Why move to PostgreSQL?

* Stricter data integrity and richer native types (arrays, JSONB, ranges)
* Better support for complex queries, window functions, and full-text search
* No forked ecosystem to track (MySQL vs. MariaDB feature drift)
* First-class support in the Rails ecosystem and on most PaaS providers

## What the migration involves

* Auditing the schema for MySQL-specific types, collations, and SQL that
  behaves differently on PostgreSQL
* Checking gems and raw SQL for MySQL-only syntax
* Migrating and verifying the data itself, not just the schema
* Running the application's full test suite against PostgreSQL before
  switching over - see our approach to
  [Test Driven Development](https://qameta.com/test-driven-development/)
* Cutting over through [Continuous Integration](https://qameta.com/continuous-integration/) and
  [Continuous Delivery](https://qameta.com/continuous-delivery/) so the switch is repeatable and
  verified, not a manual one-off

## From experience

We default to PostgreSQL on new infrastructure as well - see how we
[set up a PostgreSQL database on Dokku](https://qameta.com/posts/deploy-rails-7-0-to-dokku-micro-paas/#postgresql-dokku-database-setup)
when deploying Rails applications.

## Summary

Moving off MySQL/MariaDB touches the schema, the queries, the gems, and the
deployment pipeline. We have done this migration on several real projects and
can carry yours across without data loss or unplanned downtime.

Running MySQL or MariaDB and considering PostgreSQL? [Get in touch](mailto:info@qameta.com).
