Mattermost database read replicas and search replicas

Mattermost sends reads and search queries to PostgreSQL replicas and writes to the primary. This page explains when replicas pay off, how to configure hot standby so replicas do not cause outages, and what to confirm first.

On this page

When Mattermost read replicas and search replicas are worth adding

If your self-hosted Mattermost has outgrown a single database server and users report slow reads or heavy search load, read replicas and search replicas spread that load across more machines. Mattermost supports both, but only inside a high availability cluster, and that cluster is available only on the Enterprise and Enterprise Advanced plans. Confirm your plan in the System Console and with Mattermost sales before you design around replicas, because a Professional deployment cannot use this architecture as documented.

Replicas add real operational work. Each one is another PostgreSQL server to patch, monitor, back up and keep in step with the primary, and Mattermost routes reads across replicas while sending writes to the primary database. Replicas do not make a undersized primary faster at writes, and they do not fix slow queries that a better index or a larger primary would solve. Before adding anything, review the primary's CPU, memory, disk latency and connection counts during peak hours, and compare them with the reference architecture that matches your concurrent user count in the Mattermost server deployment planning guide.

The decision this page answers is whether your measured bottleneck is read volume that a replica can absorb, search load that belongs on a dedicated search node, or a primary problem that needs resizing first. The sections that follow explain how Mattermost routes reads, which PostgreSQL replication settings prevent replica lag and outages, and the signals that justify each component. Gather peak-hour metrics and your plan entitlement now, since those two facts determine whether replicas are an option at all and which of the three paths applies.

Which replica role fits which Mattermost workload

This table compares four layouts: a single primary, a PostgreSQL read replica, a search replica, and both replica types together. Read each row against your own load data to see which workload each role moves off the primary and what it adds to operations. The main takeaway is that replicas are a response to measured load, so confirm the bottleneck before adding one.

OptionWorkload it fitsWhat it moves off the primaryAdded operational burden and questions to confirm
Single primary onlySmall to moderate user counts where database CPU, I/O and connection counts stay within headroom under normal peaksNothing. All reads, writes and search queries run on one PostgreSQL serverLowest operational burden. Confirm with Mattermost which high availability tier applies and whether your peak load leaves room for growth
PostgreSQL read replicaGeneral read-heavy load such as channel loading, post history and member lookups when the primary is busy mostly with readsRead queries that Mattermost routes to replicas, freeing primary capacity for writesReplication lag, replica monitoring and failover planning. Confirm with Mattermost which read paths use replicas and how stale reads are handled
Search replicaSearch-heavy workloads where message search queries compete with normal chat activity on the primarySearch queries sent to dedicated search replicas, separated from general database readsSeparate replica sizing and monitoring. Confirm how search replicas interact with your search backend choice and whether they apply to your deployment tier
Read replica and search replica togetherLarge deployments where both general reads and search queries show measurable pressure on the primaryGeneral reads and search queries, leaving the primary focused on writesHighest burden: two replica roles, more lag to watch and more failure modes. Confirm the routing rules and test failover before production use

How application nodes send writes, reads and search queries

The diagram starts with users reaching a load balancer in front of two or more Mattermost application nodes. Writes go from the nodes to the primary PostgreSQL database, which streams changes to the read replicas. Reads are distributed across those replicas, while search queries are isolated on a search replica. Every node mounts the same shared file storage, and the database tier sits inside a marked trust boundary. Check that each node can reach the primary for writes and the replicas for reads, and that replication lag is acceptable for the features your users rely on.

Write, read and search paths between Mattermost nodes and the database tier.

How Mattermost routes reads and writes across replicas

The documented model is simple to state: Mattermost distributes read queries across configured read replicas and sends all writes to the primary PostgreSQL database. For a team planning replicas, the practical consequence is that a replica is only as current as its replication lag allows. Under PostgreSQL's asynchronous replication, a replica can trail the primary by a short interval, so any read served from a replica may not yet show a row that was just written. Hot standby settings and replication monitoring, covered elsewhere in this topic, determine how large that gap can get under load.

For users, the visible risk is read-after-write behavior. A user posts a message, then immediately opens or refreshes the channel, and the read goes to a replica that has not yet applied the insert. The message may appear to be missing for a moment, then show up. Whether this is acceptable is a product decision for your organization, and it should be tested with your own users rather than assumed. Ask Mattermost support or review the documentation for your version to learn whether any reads are pinned to the primary after a write, and whether that behavior differs for search, thread views or admin pages. Run a scripted post-then-read test against a staging cluster with artificial replication delay to see what users would actually observe.

Before you rely on this routing, confirm exactly which query classes Mattermost sends to which database for the server version you run, since routing rules can change between releases. PgBouncer is a separate connection pooler, documented at the PgBouncer project site. It manages how many client connections reach PostgreSQL but does not decide whether a query goes to a primary or a replica. Keep the two in separate change records, and verify replica routing by checking connection targets and query logs on each database node after deployment rather than trusting the architecture diagram.

Risks that replicas add to a Mattermost deployment

A read replica or search replica moves work off the primary, but it also adds a second database that must stay current, answer queries reliably and be recovered with the primary. The cards below cover the risks that follow from PostgreSQL replication behavior, and each names what to measure or confirm before you route Mattermost traffic to a replica.

Replication lag makes reads stale

Replicas apply changes from the primary after the primary has committed them, so a user who posts a message and then reloads a channel may read from a replica that has not caught up yet. Mattermost sends writes to the primary and distributes reads across replicas, so lag shows up as missing or delayed posts in the client. Measure replay lag on each standby at peak write volume, and confirm with Mattermost which read paths it sends to replicas before you accept the lag figure.

Mattermost HA docs

Queries cancelled during replay

On a hot standby, PostgreSQL can cancel a long read-only query when the standby must apply changes that conflict with it, such as removing rows the query still needs. Reporting queries, exports and admin searches are the usual casualties, and the error surfaces to the user as a failed request. Confirm the standby settings for conflict handling with your DBA, and test long-running queries against the standby during a pilot to see which ones fail.

PostgreSQL HA docs

Synchronous or asynchronous commit trade-off

With synchronous replication, a commit waits until a standby confirms it, which protects recent posts after a primary failure but adds network round trips to every write. With asynchronous replication, commits return sooner, but the newest writes may be lost if the primary fails before a standby receives them. Record the write latency you can accept for posts and file metadata, the number of standbys that must confirm, and the data loss window the business will sign off on.

PostgreSQL replication docs

No automatic failover in PostgreSQL

PostgreSQL does not detect a failed primary or promote a standby on its own, so a replica adds no availability until an external tool or runbook performs the promotion. Mattermost high availability also depends on redundant application servers and load balancers, and those must point at the new primary after a switch. Confirm which tool will detect the failure, who may approve promotion, how clients reconnect, and how the old primary is fenced so it cannot accept writes.

PostgreSQL failover docs

Standby falls behind unnoticed

A replica can fall behind because of disk pressure, network loss, long queries or a stopped replication connection, and Mattermost will keep running while routing reads to stale data. Without alerts on replay lag and replication connection state, the problem appears first as user complaints. Add monitoring for lag, connection status and disk space on each standby, set alert thresholds with the database team, and include a test that proves the standby still serves current data.

PostgreSQL HA docs

Extra backup and recovery scope

Each replica holds a copy of the data, but a replica is not a backup, because a dropped table or bad migration is replicated almost immediately. Recovery planning must cover the primary, the standbys and the point-in-time archive, and it must still include the files and configuration that Mattermost needs alongside the database. Confirm which node is the source of backups, how archived WAL is retained, and how a restore is tested on a separate host.

Continuous archiving docs

Which hot_standby settings keep replicas from causing outages

The first decision is whether a standby serves queries at all. With hot_standby set to on, a PostgreSQL standby accepts read-only connections while it continuously replays changes streamed from the primary. Queries and replay compete for the same data. When replay must remove row versions or apply a change that a running query still depends on, PostgreSQL resolves the conflict, and the query usually gives way. Every replica read path needs a plan for canceled queries. Mattermost sends reads to replicas only after you configure them, so confirm in Mattermost's documentation how the application reports a read canceled on the standby before you put replicas in front of user-facing traffic. A replica lags the primary and can cancel queries.

Two settings control the trade-off. max_standby_streaming_delay sets how long replay may wait for a conflicting query before that query is canceled. A higher value protects long reads on the replica, but replay falls further behind, the replica returns older data, and the primary retains more WAL until replay catches up. A lower value keeps the replica current but cancels queries sooner. hot_standby_feedback works in the opposite direction: the standby reports the oldest transaction it still needs back to the primary, so vacuum avoids removing rows the replica is reading. The cost lands on the primary as table bloat when a long replica query holds that horizon back. Enabling it on a search or reporting replica with long queries calls for a check of primary bloat and autovacuum behavior first.

Exact values depend on your query mix, write rate and hardware, and parameter behavior can change between PostgreSQL major versions. Confirm each setting against the PostgreSQL high availability documentation for your version, then choose values from load tests that use production-like query durations and write volume. Measure replay lag, canceled queries on the standby, bloat and autovacuum activity on the primary, and WAL disk usage during a long query and during a bulk import. Record the chosen values and test results, since a PostgreSQL upgrade or Mattermost release may shift the balance. Search replicas usually need a separate settings profile from user-facing read replicas.

How to add Mattermost read replicas without an outage

This sequence moves Mattermost database reads onto PostgreSQL standbys in stages, so each change is checked before the next one starts and the primary keeps serving users throughout. It ends with a tested rollback path and a documented replica lag baseline.

  1. Confirm plan and cluster prerequisites

    Confirm with your Mattermost account team that your plan includes high availability clustering, which the Mattermost pricing page places in the Enterprise and Enterprise Advanced plans. Then confirm the cluster prerequisites in the high availability documentation: redundant application servers, redundant database servers and redundant load balancers. Done means you have a written list of which plan and which nodes you are running, reviewed by the platform owner.

  2. Verify shared file storage on every node

    Check that every Mattermost application node mounts the same shared file store, either Amazon S3, an S3-compatible service or NAS, as the high availability documentation requires. Local file system storage does not work correctly in a cluster and risks file corruption, so treat any node that writes to local disk as a blocker. Done means a test file written from one node is readable from every other node.

  3. Prepare the primary for replication

    On the PostgreSQL primary, the database team sets the replication parameters, creates a dedicated replication role with a strong credential, and updates host-based access rules so only the standby address can connect for replication. Confirm the PostgreSQL version against the supported releases before you start, since the versioning policy lists end-of-life dates for each major version. Done means the primary restarts cleanly and a test connection from the standby host succeeds with the replication role.

  4. Create and synchronize the standby

    Take a base backup of the primary onto the standby host using the PostgreSQL high availability procedures, and start the standby in streaming mode. Choose asynchronous replication for read replicas unless your recovery objectives require a commit to wait for the standby, because synchronous replication adds latency to every write. Done means the standby reports that it is streaming and has caught up with the primary's write position.

  5. Enable hot standby and confirm read-only queries

    Set hot_standby on the standby and restart it, then run a read-only query and an attempted write on that node. The read should return data and the write should be refused, which confirms the node is safe to receive read traffic. Also confirm that the standby's settings for conflict handling and maximum standby delay match your expectations for long-running reports, because queries on the standby can be cancelled when they conflict with replayed changes. Done means both checks behave as expected and the settings are recorded.

  6. Point Mattermost at the replicas

    Add the standby endpoints to the Mattermost database configuration as read replicas, following the high availability documentation, and keep the primary as the only write target. Roll this out to one application node first, then to the rest of the cluster after you confirm log entries show reads going to the replica and writes going to the primary. Done means Mattermost starts on all nodes with no database errors and the System Console shows healthy database connections.

  7. Test failover behavior and replica lag

    Measure replication lag under normal and peak load, and record the lag at which users would notice stale channel or post data. Then run a controlled test in which you stop the standby and confirm Mattermost falls back to the primary without user-visible errors. PostgreSQL does not detect a failed primary or promote a standby by itself, so if you plan automatic failover, the external tooling must be tested in this same window. Done means you have a lag baseline, a documented fallback result and a list of any gaps.

  8. Rehearse the change and document rollback

    Run the full sequence in a non-production copy of the environment before the production change, and write a rollback plan that removes the replica endpoints from the Mattermost configuration and returns all reads to the primary. Schedule the production change with a support contact on hand and agree in advance who can make the rollback call. Done means the rehearsal completed with the same checks, the rollback was tested once, and the runbook is signed off by the platform and database owners.

Securing replica traffic, credentials and data copies

A read replica or search replica is a second copy of your Mattermost message data, and each one adds a network path, a credential and a host that must be protected. The controls below cover the connections between Mattermost and PostgreSQL, the accounts that replication uses, and the operational records you need to investigate access. Review them together when you design the topology, not after the replicas are live.

Encrypt replication and client connections

Require TLS for the connections from Mattermost to the primary and to each read replica, and for streaming replication between the primary and its standbys. Set the sslmode value in the Mattermost database connection string to a level that verifies the server certificate, not just encryption. Confirm that the PostgreSQL server enables SSL and that the certificate chain is trusted by every Mattermost node. Unencrypted replication traffic exposes every message written to the primary.

PostgreSQL high availability docs

Restrict hosts allowed to replicate

The replication user should be allowed to connect only from the replica addresses, using replication entries in pg_hba.conf, and never from all. Mattermost application nodes should match a separate database role that has no replication privilege. Review these entries whenever you add or retire a replica, because a stale entry is a path that nobody remembers to close. Ask your DBA to show the active rules on the primary during the design review.

Use SCRAM and certificate authentication

Set password_encryption to scram-sha-256 and use scram-sha-256 in pg_hba.conf for Mattermost and replica roles. PostgreSQL documents certificate authentication as an option for connections where you can issue and rotate client certificates reliably. Choose the method per role and confirm your Mattermost version supports the method you pick. Avoid MD5 password authentication, which PostgreSQL 18 deprecates in favor of SCRAM.

PostgreSQL authentication methods

Manage and rotate replica credentials

Give each replica and each Mattermost node its own role where practical, so one compromised host can be revoked without breaking the others. Store passwords in a secrets manager or a restricted configuration file, not in shell history or version control. Plan a rotation schedule and test it on a staging replica first, because rotating the replication password can interrupt streaming until the standby is reconfigured. Record who owns each credential.

Treat replicas as full copies of messages

A replica holds every channel, direct message and file reference that the primary holds, so it inherits the same sensitivity. Apply the same access restrictions, encryption at rest, backup handling and retention rules to every replica and to any search index built from its data. Confirm that retention deletions on the primary reach the replicas and that legal holds are respected there too. Forgotten copies in development or reporting environments are a common gap.

Log connections and failed logins

Enable connection and disconnection logging and log failed authentication attempts on the primary and on every replica, using PostgreSQL logging settings such as log_connections, log_disconnections and log_hostname. Forward these logs to a central store that your security team monitors, and set an alert for repeated authentication failures from unexpected addresses. Confirm the log volume and retention with your operations team before enabling verbose settings on busy servers.

What buyers ask about replica cost, effort and timing

What drives the effort of adding PostgreSQL read replicas to Mattermost?

The effort rises with the number of replicas, the replication mode, and how much of the surrounding platform must change. Each replica needs its own storage sized for the primary's data, a network path with enough bandwidth and low enough latency to keep up with writes, and monitoring for replication lag. Choosing synchronous replication adds commit latency because a write waits for standbys to confirm it, so the effort also includes load testing under realistic peak traffic. Failover tooling is a separate workstream, since PostgreSQL does not detect a failed primary or promote a standby on its own. Each of these items adds design, configuration and test time, and a written scope should list them separately.

Who pays for what when Mattermost replicas run in our own infrastructure?

In a self-hosted setup, you pay for the infrastructure, the Mattermost subscription, and any services you buy. Servers, storage, network capacity and cloud accounts are your costs, and they are paid to your hosting provider or data center. Mattermost sells its plans as prepaid annual subscriptions based on seat licenses, and its pricing page does not publish prices, so you confirm the plan with Mattermost, Inc. High availability clustering is listed on the Enterprise and Enterprise Advanced plans, so check the plan that covers your deployment before you design it. Implementation, configuration and testing services are a separate contract with the firm doing the work, and they are quoted from a written scope.

Which costs are one-time and which recur after replicas go live?

Setup costs are one-time, and running costs recur. One-time items include the design, the initial build, load and failover testing, and any migration of routing settings in the application. Recurring items include the compute and storage for each replica, the network capacity that carries replication traffic, monitoring and alerting, the Mattermost subscription renewal, and the time your team spends on patching and PostgreSQL minor releases. PostgreSQL minor releases do not change the storage format, but each one still requires a restart, so budget for a maintenance window each time. Major version upgrades are a larger recurring task because replicas must be upgraded or rebuilt with them.

What does our team need to provide for a replica project?

Your team needs to provide access, decisions and a test environment. Expect to supply access to the database servers, the network and the load balancer, along with the Mattermost administrators who know which features are in use. Your database team should decide the replication mode, the acceptable lag for search and reporting reads, and the failover approach. Your security team should review how replicas are authenticated and how backups cover them. A staging environment that resembles production is important because load behavior cannot be checked on a laptop. Ask the provider to list these inputs in the scope so they are not discovered during the build.

Can our team set up Mattermost read and search replicas without outside help?

A team with PostgreSQL operations experience and Mattermost administration skills can do it, but it is a multi-skill project. The database side needs replication setup, hot_standby settings, monitoring and tested failover. The Mattermost side needs correct routing of read traffic and clear handling of search queries. The part most often underestimated is failover testing, because PostgreSQL leaves failure detection and promotion to external tools. If your team has no recent experience with those tools, an outside partner can shorten the learning curve, or you can run the design review with a partner and build it internally. Either way, confirm that your staff can operate the result after handover.

When are read replicas worth the cost, and when is a bigger primary enough?

Replicas are worth it when read load, not write load, is what slows the system, and when a second database node gives you a fallback you can test. Mattermost distributes reads across replicas and sends writes to the primary, so read-heavy growth is the case replicas address. If the primary is limited by writes or by a single slow query, a replica will not fix it. Use the published reference architectures for Mattermost sizing and a pilot with measured load to decide. Search on a separate node is a different decision, covered by the enterprise search guidance, and should be evaluated against measured search latency.

What should we ask for in a written scope for replica work?

Ask for a scope that names each deliverable and how it will be verified. Request the list of replicas and their roles, the replication mode and the reasoning for it, the Mattermost plan and version the design assumes, and the exact hot_standby and related PostgreSQL settings to be applied. Ask how read and search traffic will be routed, how failover is detected and tested, how backups cover replicas, and how monitoring and alerts are configured. Also ask for the test plan, the acceptance criteria, the handover documentation and any post-launch support period. Confirm which items are excluded, such as infrastructure purchases, Mattermost licenses and PostgreSQL major upgrades, so the quote is comparable across providers.

What to confirm in your environment before you commit

Start by confirming that your Mattermost version and plan support the cluster and replica configuration you have in mind. Mattermost high availability is available only on the Enterprise and Enterprise Advanced plans, so a Professional deployment cannot use this design regardless of the database work around it. Check the release you intend to run against the server releases page, since v11.7 is the current Extended Support Release with support ending 2027-05-15, while monthly releases such as v12.0 carry shorter support windows. Ask your Mattermost account contact to confirm in writing which plan includes the features you need, because the public pricing page lists no prices and directs buyers to sales.

Next, confirm your PostgreSQL major version and its end-of-support date. The supplied schedule lists version 14 as supported only to 2026-11-12, version 15 to 2027-11-11 and version 18 to 2030-11-14, so a replica topology built on an older major version may need an upgrade within the first months of operation. Confirm that Mattermost accepts your chosen PostgreSQL version and that your replicas run the same major version as the primary. Also decide how you will detect a failed primary and promote a standby, because PostgreSQL does not provide that software on its own and the PostgreSQL failover documentation explains that external tooling is required. Name the tool, its owner and the runbook before go-live.

Measure network latency between the application nodes, the primary and each replica, and the search service. Replicas serve reads that can lag behind the primary, so a slow or congested link widens that lag and can show users stale channel or thread data. Ask your network team for the round-trip time under normal and peak load. Finally, decide whether your search workload fits a database replica or needs a dedicated search service. Replicas help database reads but do not replace a search engine, so confirm with Mattermost which search option matches your post volume and retention needs, and test your own search queries against a replica before you commit to the design.

How DeployOpen scopes and delivers Mattermost replica work

DeployOpen plans, builds and documents Mattermost database read replicas and search replicas inside your own infrastructure, starting from a written scope. The work covers PostgreSQL replication settings, read and write routing, search isolation, testing and the operating runbooks your team needs after handover.

How we scope

  • Engagements are fixed-scope, with the replica topology, deliverables and timelines agreed in writing before work starts.
  • The scope records current user counts, peak concurrency, database load and whether Mattermost is on an Enterprise plan that includes high availability.
  • We confirm the PostgreSQL major version in use and its support end date, since replica setup depends on the database version.
  • Search replica scope is set separately, with the search engine, hosts and access model confirmed before any indexing work begins.

How we build

  • Standby servers are configured with hot standby settings and replication mode chosen against your write durability requirements.
  • Mattermost read and search routing is configured and tested so writes always reach the primary database.
  • Shared file storage on Amazon S3, an S3-compatible service or NAS is verified on every application node before cutover.
  • Failover tooling is selected with you, because PostgreSQL does not detect primary failure or promote a standby on its own.

How we hand over

  • Handover includes configuration records, topology diagrams, replication lag checks and the commands used to verify each replica.
  • A tested runbook covers replica promotion, rerouting after a failure, and the steps to remove or add a replica.
  • Your team receives a retest of replication, routing and search behavior, with findings and fixes documented.
  • Backup and restore procedures are documented for the primary and replicas so recovery stays within your existing process.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after the initial scope is delivered.
  • Retainers can cover PostgreSQL minor updates, which replace executables and require a restart, and planned major upgrades.
  • Support can include reviewing Mattermost monthly release notes and ESR timing against your replica configuration before each upgrade.
  • Ask any proposed partner to confirm in writing who maintains replica settings, how lag is monitored and who responds to incidents.

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.