Choosing a database for Moodle: PostgreSQL, MySQL or MariaDB

Moodle runs on PostgreSQL, MySQL or MariaDB, and the right choice depends on the release you plan to run, the replica and locking setup you need and how you will upgrade over the next several years.

On this page

Choosing a Moodle database: what the decision affects

PostgreSQL, MySQL and MariaDB are all supported by Moodle, so the choice comes down to which engine your team can operate well for the life of the site. Moodle's database engine is set at install time, and it shapes which Moodle releases you can run, which server versions you must provision, and how much work a later upgrade will take. Teams standing up a self-hosted instance in the Moodle codebase should settle the engine before the first install, because moving an existing site between engines is a migration project of its own, not a configuration change.

The version floor is the first constraint. Moodle 5.1 requires PostgreSQL 15, MySQL 8.4 or MariaDB 10.11, and Moodle 5.3 requires PostgreSQL 17, MySQL 8.4 or MariaDB 11.4. Confirm the exact minimums for the release you plan to run against the release notes, not against your distribution's default package, because many Linux repositories ship older engine versions. Check your upgrade path too: the 5.1 and 5.3 notes set the earliest Moodle version each release can upgrade from, so a site already on an older release may need intermediate steps before the database choice even matters.

Settle the engine early for three reasons: your backup and point-in-time recovery tooling depends on it, your database operations skills and monitoring must match it, and any read replica plan depends on driver support. Moodle's read-only replica option is supported by the pgsql and mysqli driver families, so confirm the driver family and replica setup against the settings in the sample configuration file before you size infrastructure. If your organization already runs one engine well in production, choosing that engine usually lowers long-term effort, and a managed database service should be checked against the same version and driver requirements.

Supported database minimums by Moodle release

This table compares the minimum PHP, database and upgrade-from versions that Moodle 5.1 and Moodle 5.3 require. Read each database row against the engine you plan to run, because a minimum is the oldest version Moodle supports and says nothing about which version you should choose. The main takeaway is that the PostgreSQL and MariaDB minimums move forward in 5.3, while the MySQL 8.4 minimum stays the same.

RequirementMoodle 5.1Moodle 5.3
PHP minimum64-bit PHP 8.2 or later, with PHP 8.3 and 8.4 supported64-bit PHP 8.3 or later, with PHP 8.4 supported
PostgreSQLPostgreSQL 15PostgreSQL 17
MySQLMySQL 8.4MySQL 8.4
MariaDBMariaDB 10.11MariaDB 11.4
Microsoft SQL ServerSQL Server 2017 or laterSQL Server 2019 or later
Minimum version to upgrade fromMoodle 4.2.3 or laterMoodle 4.4 or later
Confirm before you commitCheck the 5.1 release notes for your exact target version and any point release changesCheck the 5.3 release notes for your exact target version and any later patch release you plan to run

Which engine fits which environment

If your organization already runs PostgreSQL for other platforms, Moodle is usually the lowest-friction choice, since the same people can tune, back up and patch it. Confirm that the PostgreSQL version you plan to run matches the minimum for the Moodle release you will install, because that minimum changes between releases. Moodle 5.1 requires PostgreSQL 15 and Moodle 5.3 requires PostgreSQL 17, so an older cluster may need upgrading before the Moodle upgrade can proceed.

  • Operational skills: Your DBAs should already handle vacuum tuning, connection pooling and major version upgrades without outside help.
  • Backup tooling: Reuse your existing physical backup and point-in-time recovery setup, and test a restore into a separate environment.
  • Monitoring: Extend current dashboards to cover long-running transactions, bloat and replication lag if you use a read replica.
  • Replica planning: Moodle's read-only replica option is supported by the pgsql driver family, so confirm your replica topology with the Moodle configuration reference before relying on it.
  • Upgrade coupling: Track the PostgreSQL major version alongside Moodle's yearly LTS path so both move in the same change window.

Before committing, ask whether your PostgreSQL team can support Moodle's query patterns and whether its runbooks already cover restores.

Read replicas and locking options to confirm

Read replicas and locking decide how Moodle behaves once course traffic grows, and they interact with the driver you pick. The four decision points below should be settled together, then verified on the exact release and driver your team will run.

Replica support by driver family

Moodle's read-only replica option is supported by the pgsql and mysqli driver families, so a MariaDB site uses the mysqli family in the same way as MySQL. Confirm that your database platform and driver fall within those families before you plan a replica topology. If a managed service exposes a replica endpoint, check which driver it expects and whether Moodle can reach that endpoint from the web and cron tiers.

Config-dist reference

Replica configuration in config.php

Replicas are declared in config.php through the read-only database settings, which sit alongside the primary connection details. Each replica needs its own host, credentials and connection options, and the replica must be a current copy of the primary before Moodle reads from it. Keep the exact key names and array structure from your release's config-dist.php, because examples in forums and older guides often differ from the current file.

Replication lag and consistency

Asynchronous replicas lag behind the primary, so a student who submits an assignment and reloads a page may briefly see old data if that read goes to a replica. Test the screens that must be consistent immediately, such as submissions, quiz attempts and grade updates, and confirm with your release notes how Moodle routes those reads. Measure lag on your own replication setup rather than assuming a figure.

Locking behavior under concurrent writes

Quiz attempts, grading and cron tasks write to shared tables at the same time, so lock contention is where a database choice shows up in practice. Compare the storage engine and isolation settings on MySQL 8.4 and MariaDB 11.4 against PostgreSQL 17 with your expected concurrency. Ask your team to confirm the table types and transaction settings Moodle expects for your release, and record them in your build notes.

Connection handling and pooling

Each PHP-FPM worker and cron process opens its own database connections, and a replica adds a second pool on top of the primary. Plan connection limits on both servers, decide whether a pooler sits in front of them, and check that cron runs against the primary for write tasks. Confirm pooler compatibility with Moodle's connection behavior in your release before you put it into production.

Load tests to run before go-live

Test the database choice with a realistic mix of logins, quiz attempts, forum posts, gradebook views and cron runs at expected peak concurrency. Include a failover of the replica and a primary restart, and record query latency, lock waits and replica lag for each run. Ask your partner or internal team to deliver the test plan, the results and the settings that passed, so the choice is backed by evidence for your own environment.

How the database decision flows into deployment and upgrades

The path starts with the skills and standards your team already runs, then checks the Moodle release you target against that release's supported engine minimums. Next comes the question of whether you need a read-only replica, which the pgsql and mysqli driver families support, and whether a managed service or a self-run server fits your operations. Each later Moodle release then re-checks the engine minimum, so the choice is revisited at every upgrade, not only at install. Confirm each minimum against the release notes for the version you plan to run.

Database choice runs from team skills through release minimums to each later upgrade.

How to set up the chosen database for Moodle

This sequence takes the database decision from a target release to a working Moodle install, with a check at each stage so the database is verified before it carries live courses. Follow it in order, since the version and character set choices made early constrain every later step.

  1. Confirm the target Moodle release and its minimums

    Decide which Moodle release you will install and read its release notes for the required PHP version and the minimum database engine versions. Compare the planned release with the version your current platform runs if you are migrating, because upgrade paths can require a minimum starting version. Record the target release, the PHP version and the database engine version in your build notes. Done means one written table that names the release and the minimum engine versions you will provision, signed off by the person who owns the platform.

  2. Provision the database engine at the required version

    Install PostgreSQL, MySQL or MariaDB at or above the minimum for the chosen release, on the servers or managed service you control. For Moodle 5.1, the supported minimums are PostgreSQL 15, MySQL 8.4 or MariaDB 10.11, and for Moodle 5.3 they are PostgreSQL 17, MySQL 8.4 or MariaDB 11.4. Your infrastructure team does this work, and it is a one-time build step that recurs whenever the engine is patched. Check the engine version with the server's own version query and confirm it matches the minimum in your build notes.

  3. Create the database, user and character set

    Create a dedicated database and a dedicated login for Moodle, granting that login rights only on its own database. Set the character set and collation that the Moodle install documentation requires for your chosen engine, since a wrong default is hard to fix after data is loaded. Confirm the Moodle documentation for the exact collation values, because they differ between engines and releases. Check that a test login from the Moodle web server host can connect and that the database default character set and collation match the documented values.

  4. Set connection values in config.php

    Add the database type, host, name, user, password and table prefix to config.php, using the driver family that matches your engine. Keep the password out of version control and limit file permissions on config.php to the web server user. If you plan a read-only replica, add the replica settings in the same file, noting that Moodle supports this option only for the pgsql and mysqli driver families. Done means config.php parses without errors and the file's permissions are restricted as your security baseline requires.

  5. Point the web server document root correctly

    For Moodle 5.1 and later, configure the web server so its document root is the public directory inside the Moodle code, not the main Moodle folder. Without this, the site can show directory listings or errors before the installer even runs. Reload the web server and request the site in a browser. Done means the installer page loads with no directory listing and no PHP errors on the page.

  6. Run the installer and verify the connection

    Run the browser installer or the command-line installer against the prepared database. Confirm that the installer creates the expected tables without character set warnings, and that the environment check reports the database driver and version as supported. Log in as the administrator and open the site administration environment page to confirm the database check passes. Done means the install completes and the environment page shows no database errors.

  7. Confirm cron and scheduled tasks reach the database

    Run the Moodle cron job from the command line as the web server user and confirm it completes without database errors. Check that scheduled tasks run in the site administration task log and that the cron entry is set to run at the interval your operations team chose. Done means the cron run finishes cleanly and the task log shows recent executions against the new database.

  8. Test a backup and restore before go-live

    Take a database dump with the engine's standard tooling, restore it into a scratch database, and point a test Moodle config at the restored copy to confirm it starts. Record the commands and schedule in your operations runbook. Pair the database backup with the moodledata backup, since the database alone does not restore a working site. Done means a restored copy loads in Moodle and the runbook names the owner of the backup schedule.

Security and operational considerations for the database

The database holds every course, grade and user record, so its security and recovery settings matter as much as the choice of engine. The cards below cover the decisions that carry over regardless of whether you pick PostgreSQL, MySQL or MariaDB. Confirm each specific setting against your engine vendor's documentation and your security team's baseline.

Scope the Moodle database account

Moodle needs a dedicated database user with rights limited to its own schema. Upgrades need schema changes, so the account used during an upgrade may need more privileges than the one serving daily traffic. Separate the two if your policy requires it, and confirm with your engine vendor which privileges an install and upgrade actually require. Avoid running Moodle as a superuser or the database administrator account.

Encrypt connections to the database

If the web and cron servers are not on the same host as the database, traffic crosses a network segment that should be encrypted. Ask your engine vendor how to enable TLS on the server, then confirm that the Moodle connection settings require it. Also check whether your security team expects certificate verification, not just encryption, on every connection, including replicas.

Plan backups and point-in-time recovery

A nightly dump is not enough for a learning platform used during term time. Ask whether your engine supports continuous WAL or binary log archiving so you can restore to a chosen moment before a bad upgrade or deletion. Test restores into a separate environment and time them, because the restore duration determines your real recovery window. Back up the moodledata directory on the same schedule so the two stay consistent.

Patch the engine on a schedule

Moodle's supported minimums rise with each release, so the engine version you choose today sets your upgrade path. Track the security advisories for your engine and the Moodle releases that require a newer version. Apply minor engine patches in a staging copy first, then roll them to production in a planned window. Record which version each environment runs.

Moodle 5.1 minimum
PostgreSQL 15

Keep credentials out of the web root

The database password lives in config.php, which must sit outside any path the web server serves. Move the file or restrict access so requests for it return an error, and confirm the same for backup files and editor temporary files. Store the password in a secrets manager or an environment-specific file with restricted permissions, and rotate it when staff with access change. Check the Moodle security report after each deployment.

Log and review database access

Enable the engine's connection and slow query logging, and ship those logs to the place your security team already monitors. Review failed logins, unexpected administrator sessions and accounts that should no longer exist. Ask your engine vendor which audit features are included in the edition you run, since some are not in the community editions.

Questions buyers ask before choosing a Moodle database

What does choosing a Moodle database cost in effort, and who does the work?

The licence cost is usually zero for PostgreSQL, MySQL and MariaDB, so the real cost is effort. Your team or a partner must install and tune the engine, set up backups and restore tests, configure monitoring, and apply patches. Those tasks recur every month. The initial build is one-time work. Ask any quote to split setup, testing, handover and ongoing support, and to say which party owns each backup and patch cycle. The effort is larger when your team has no experience with the chosen engine, because the learning curve falls on the project.

How long does a Moodle database migration take, and what drives it?

Duration depends mostly on database size, the number of plugins that write to custom tables, how much downtime the course calendar allows, and how well the source and target engines are matched in collation and data types. Moodle must be upgraded to a version that supports your target database before the cutover, which adds planning time. Ask for a rehearsal on a copy of production, a timed dry run, and a written rollback plan. Any duration in a quote should come with the dataset size and the rehearsal results behind it.

Can our team run a Moodle database internally?

Yes, if you already operate PostgreSQL, MySQL or MariaDB for other systems and have people who can handle backups, replication and upgrades. The gaps usually appear in restore testing and in failover procedures, which teams often document but never exercise. Check whether your staff can restore a backup to a clean host within your recovery target, whether they can apply a minor engine patch without a long outage, and whether someone owns the database through each Moodle upgrade. If any of those answers is no, plan training or outside support before go-live.

How does the database choice affect future Moodle upgrades?

The choice sets the minimum versions you must maintain. Moodle 5.1 requires PostgreSQL 15, MySQL 8.4 or MariaDB 10.11 (or SQL Server 2017 or later), and Moodle 5.3 requires PostgreSQL 17, MySQL 8.4 or MariaDB 11.4 (or SQL Server 2019 or later). Upgrading the database engine is therefore a prerequisite for some Moodle upgrades, not an optional step. Check the release notes for each target version, and plan engine upgrades in the same change window. Sites must also be on a minimum Moodle version before upgrading, so keep that in the upgrade path.

Does Moodle support read replicas for PostgreSQL and MySQL?

Moodle supports a read-only replica option through its database configuration, and this option is available for the pgsql and mysqli driver families. A replica can take read traffic off the primary, but it does not remove the need for a tested backup strategy or a failover plan. Confirm the exact configuration keys in the config-dist.php file for your Moodle version, and test replication lag under real course-page load. MariaDB uses the mysqli family, but confirm behaviour with your specific build before relying on it.

Is a managed database service supported for Moodle?

Moodle runs against standard engine protocols, so a managed PostgreSQL or MySQL service can host the database if it meets the version minimums for your release. Confirm with the provider that the engine version, extensions and collation settings match Moodle's requirements, and that the service provides point-in-time recovery and maintenance windows you can accept. Managed services shift patching and some backup work to the provider, but your team still owns Moodle's configuration, schema upgrades and restore testing. Ask the provider for their documented restore procedure and recovery objectives in writing.

Which database engine is the safer choice for a regulated Moodle site?

There is no universal answer, but PostgreSQL is the common choice where teams want the widest version coverage in current releases and mature replication tooling. MySQL 8.4 and MariaDB are workable where existing operations skills are strong. Whichever engine you pick, your compliance evidence depends on backups, access control, encryption at rest, audit logging and documented change control, not on the engine name. Map each control your auditor asks about to a configuration and an owner. Independent auditors and certification bodies, not DeployOpen, issue any audit opinion.

Limits to confirm in your own environment

Database choice for Moodle depends on version-specific minimums, how your managed service behaves, and how replicas and collations will hold up under your load. The cards below list the checks to run against your target release and your own environment before you pick an engine and build around it.

Exact engine version for the target release

Moodle sets minimum engine versions per release, and they change between majors. Moodle 5.1 lists PostgreSQL 15, MySQL 8.4 and MariaDB 10.11 as minimums, while Moodle 5.3 lists PostgreSQL 17, MySQL 8.4 and MariaDB 11.4. Confirm the exact minimum for the release you will run on the release notes, then check that the version your platform team can patch and support meets it. A version that works today may fall below the floor for your next major upgrade.

Moodle 5.3 notes

Managed service support for Moodle

A managed database service may run a supported engine version but still omit settings Moodle expects, such as particular privileges, character sets, or access to the parameters Moodle reads at install time. Ask the provider which engine versions and configuration options they offer, whether their version matches the Moodle minimum, and how they handle minor upgrades. Test a full install and a restore into the managed service before you commit to it.

Read replica behavior under your load

Moodle's read-only replica option is supported by the pgsql and mysqli driver families, so the choice of driver family affects whether a replica is an option at all. Confirm how replication lag is handled in your setup, which queries you expect Moodle to send to the replica, and how the site behaves when the replica falls behind. Measure this with realistic course traffic, since lag that is invisible at low use can cause stale reads during assessments.

config-dist.php

Collation and character set settings

Collation and character set choices affect sorting, uniqueness checks and how multilingual content is stored. Moodle expects a Unicode-capable setup with consistent settings across the database, tables and connection. Confirm the collation your engine uses by default, whether your course content includes languages that need specific collations, and how the choice will carry into backups and restores. Changing this after content exists is costly, so settle it before the first install.

Upgrade path from your starting version

Moodle requires the site to be on a minimum version before it can upgrade to a given release. Moodle 5.1 requires sites to be on 4.2.3 or later, and Moodle 5.3 requires 4.4 or later. If your current site is older, you may need intermediate upgrades, each with its own database and PHP requirements. Map the full path from your starting version to the target release, and confirm the engine version at each step so the database does not become the blocker halfway through.

Moodle releases

How DeployOpen scopes a Moodle database decision

DeployOpen plans and implements self-hosted Moodle inside your own infrastructure, and the database decision is one of the first items written into the scope. Before any build starts, we confirm which engine your organization can operate, which Moodle release you will launch on, and how that release's database minimums line up with what your hosting platform or database team already supports. For example, Moodle 5.1 lists PostgreSQL 15, MySQL 8.4 and MariaDB 10.11 as minimums, while Moodle 5.3 raises them to PostgreSQL 17, MySQL 8.4 and MariaDB 11.4. An engine that clears the launch release may fall short of the release you plan to upgrade to, so that gap is recorded in the scope rather than discovered at upgrade time.

The written scope then covers the parts of the decision that carry operational weight: whether a read-only replica is needed and whether your chosen driver supports it (Moodle's read-only replica option is supported by the pgsql and mysqli driver families), which locking and transaction behavior your team will test against, whether a managed database service is acceptable under your data residency and backup rules, and who owns patching, failover and restore testing. We document the resulting config.php database settings, driver choice, connection details and backup schedule, so your engineers can reproduce the build and your auditors can trace how the database was configured. Confirm with your database platform team which engine versions they will support for the full life of the Moodle release you select.

How DeployOpen works on this

DeployOpen plans, implements, hardens, documents and supports self-hosted Moodle inside your own cloud accounts, data centers or air-gapped networks. For the database decision, that means the choice is tested against your release target, your replica and failover needs and your upgrade calendar before any server is built.

How we scope

  • Scope is agreed in writing before work starts, so the database choice and its deliverables are fixed up front.
  • We confirm your target Moodle release and the database version that release requires, checked against Moodle's release notes.
  • We record whether you need a read replica, a managed database service or a self-managed server, and who operates each.

How we build

  • We install the chosen database and connect Moodle through config.php, testing the pgsql or mysqli driver settings in your environment.
  • We configure the read-only replica option only where the driver family supports it, and test failover behavior with your team.
  • We check collation, locking and connection settings against your expected concurrency and document the results.

How we hand over

  • You receive a written record of the database version, Moodle release, driver settings, replica topology and backup approach.
  • Runbooks cover routine maintenance, version upgrade steps and the checks to run before each Moodle upgrade.
  • We walk your platform and database administrators through the build and the restore test so they can operate it without us.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer, including planned database major version moves.
  • Before each Moodle major release, we review the minimum database version and the upgrade path your site must follow.
  • Support scope and response arrangements are set out in the written agreement, so you confirm them before you commit.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.