Operating system upgrades and PostgreSQL collation changes

An OS upgrade can change how PostgreSQL sorts text, which can leave text indexes returning wrong results. This page explains the glibc 2.28 change, which copies of the cluster are affected and how to plan the reindex.

On this page

Why a PostgreSQL OS upgrade can break text indexes without any error

An operating system upgrade can change locale data and therefore the sort order of text, so every index on a text, varchar, char or citext column needs checking and usually a reindex before the cluster returns to production. The database does not refuse to start and queries keep returning rows, which is why the problem is easy to miss. An index built under the old sort order still exists and still answers lookups, but it no longer matches how the new system orders strings. Equality and range queries can then return incomplete results, and the planner has no signal that anything is wrong. Nothing in the logs announces it, so the risk stays hidden until someone compares results or a constraint fails.

This is a separate risk from a PostgreSQL major or minor upgrade. A PostgreSQL upgrade changes the server binaries or the on-disk format, while an OS upgrade changes the C library and locale files that PostgreSQL calls when it sorts text. A team can complete a clean pg_upgrade and still have broken indexes because the Linux distribution underneath moved. The reference case is glibc 2.28, released on August 1, 2018, which changed locale data in a way that can alter sort order. The first distribution releases that shipped the new locale data included Debian 10 (buster) and Ubuntu 18.10, so any host moved across that boundary deserves a closer look. Confirm the glibc version on each host with your distribution's package tools before deciding how much checking to do.

The PostgreSQL wiki page on locale data changes is the primary source for which releases are affected and what to reindex. Read it before planning the change, because it also explains why binary copies such as streaming replicas and pg_basebackup restores on hosts with different locale data are affected, while pg_dump and logical replication are not. Inventory the collation of every database and column that uses text types, and decide in advance who signs off on the reindex plan.

What changes in the OS and what it does to PostgreSQL

This table maps each part of the glibc 2.28 locale change to its effect on PostgreSQL data and the check or step it calls for. Read it before any OS upgrade that moves a database host across glibc versions, and use the actions as a checklist for the cutover plan.

ChangeImpactAction needed
glibc 2.28 locale data change (released August 1, 2018)Can change the sort order of text, so existing text index order may no longer match what the database expectsCompare glibc versions on the old and new hosts with ldd --version before choosing a plan
Indexes on text, varchar, char and citext columnsIndexes built under the old sort order can return wrong results or miss rows after the changeReindex all such indexes before production use on the upgraded host, and test with a representative query set
Binary copies on hosts with different locale data (streaming replicas, pg_basebackup restores)Copies made to a host with different locale data inherit the same index problemConfirm each replica and restore target has the same glibc locale data as the primary, or reindex after the move
pg_dump and logical replicationNot affected by the locale change because they carry logical rows, not binary index filesUse them as a path to a new host with different locale data, then rebuild indexes on the target and verify
Debian 10 (buster) and Ubuntu 18.10The first releases of these distributions shipped the new glibc locale dataConfirm the glibc version of every distribution and release you run, since this page does not list others as affected

How to decide which copies need a reindex

The decision starts at the OS upgrade that changes glibc locale data, then asks how each PostgreSQL copy was made. Binary copies, such as streaming replicas and pg_basebackup restores, must first be checked for matching locale data, and text indexes on a mismatched host are reindexed before production use. Logical copies, such as pg_dump restores and logical replication targets, are rebuilt on the new OS, so their text indexes are reindexed there and then tested. Both paths end by verifying the affected indexes and recording the result.

Decision path for which PostgreSQL copies need text index rebuilds after an OS upgrade.

Which copies of the cluster are affected by the locale change

Streaming replicas are affected when the standby runs on a host whose locale data differs from the primary's. Streaming replication ships WAL records that reference index pages byte for byte, so the standby assumes its sort order matches the primary. If the primary still runs the old glibc and the replica moved to a distribution with glibc 2.28 or later, the two can disagree about where a text key belongs in a B-tree. Queries on the standby may then return wrong results or miss rows, and the disagreement can persist until the indexes are rebuilt.

  • Compare the OS and glibc on both hosts: run ldd --version on the primary and on every replica, and record the distribution release for each.
  • Check the collation in use: query pg_database and the collation of each text column to see which databases depend on libc collations.
  • Plan the order of operations: upgrade the replicas in a way that keeps the primary and every standby on a matching locale set, or rebuild indexes before promotion.
  • Do not promote an unverified standby: a standby that has been moved to a new OS should be treated as suspect until its indexes are rebuilt and checked.
  • Confirm the details: check the PostgreSQL wiki on locale data changes and your own host documentation for the exact glibc version shipped in each release.

Before accepting any replica that has crossed the OS boundary, confirm that its locale data and its indexes match the primary's.

How to sequence an OS upgrade under a running cluster

This sequence moves the operating system under PostgreSQL in an order that keeps a rollback point at every change and ensures no replica serves reads against mismatched collations. It produces a tested cutover plan with the reindex work finished before production traffic moves.

  1. Inventory OS and glibc versions on every host

    Record the distribution, release, and glibc version on each PostgreSQL primary, standby, backup host, and rehearsal copy, along with the PostgreSQL version and the locale settings each cluster uses (lc_collate and lc_ctype). Compare the glibc versions across hosts to find where a locale data change could separate a source from its copies. Rollback point: nothing changes yet. Done when you hold one table that lists every host, its glibc version, and its target OS, and you can name every host that will cross the glibc 2.28 boundary.

  2. List text-type indexes and their collations

    Query the catalog for every index on text, varchar, char, and citext columns, and record the collation each one depends on, including any index built with an explicit COLLATE clause. Note which indexes are on partitioned tables, expression indexes, and primary keys, because these are the ones most often missed in manual checks. Rollback point: nothing changes yet. Done when you have a complete inventory with the count and owning schema of each affected index, reviewed by the team that owns the application.

  3. Take and verify backups before any change

    Take a fresh base backup and confirm the archived WAL needed to restore to the current point is in place, then test-restore that backup to a separate host and run a read check against it. Keep the backup set on storage that the upgrade will not touch. Rollback point: this backup is your fallback for every later step. Done when a test restore completes and the restored copy answers queries, and you have written down the restore command and the recovery target.

  4. Upgrade a rehearsal copy of the cluster

    Restore the verified backup onto a host running the target operating system, with the same PostgreSQL version and locale settings as production. Apply the OS upgrade on that copy, start PostgreSQL, and confirm the cluster starts cleanly and the log shows no collation warnings beyond the expected ones. Keep the original rehearsal host unchanged so you can repeat the test. Done when the upgraded rehearsal copy starts, accepts connections, and passes the application's smoke tests.

  5. Compare query results and reindex on the rehearsal copy

    Run ordered queries and sort-dependent checks on the rehearsal copy before and after the upgrade, and compare the results for the text columns that drive uniqueness, joins, and ordering. Then reindex every text-type index from the inventory, and rerun the comparison to confirm that index scans and sort results agree with the table order. Rollback point: the rehearsal copy can be rebuilt from the backup at any time. Done when the reindex completes without errors and the ordering checks match the expected results for each affected index.

  6. Upgrade replicas before the primary

    Upgrade each streaming replica after the rehearsal succeeds, keeping the old host or its volume available until the replica is confirmed healthy. A replica on a different glibc version than the primary must not serve read traffic against indexes that have not been reindexed, so remove it from the read pool until its reindex is complete. Rollback point: the retained old replica host or a fresh base backup. Done when each replica reports streaming status, replication lag returns to its normal level, and the reindex on that replica has finished.

  7. Reindex and cut over the primary in a planned window

    Schedule the primary change with the application team, take a final backup, and perform the OS upgrade on the primary. Run the reindex for all text-type indexes before the application reconnects to the primary for production traffic, because the reindex step must finish before production cutover. Rollback point: the final backup and the retained old primary volume. Done when the reindex completes, the cluster passes the checks from the rehearsal, and the application runs its smoke tests against production.

  8. Confirm results and retire rollback assets

    After production runs under the new OS for a period you agree on in advance, confirm replication is healthy, the backup jobs succeed on the new host, and no application error mentions sort order or unique violations. Keep the old host or volume until that check passes, then retire it according to your retention policy. Done when the monitoring, backup, and application checks are signed off and the rollback assets are recorded as retired.

Reindexing text indexes and deciding whether to move to ICU collations

Start by confirming which indexes are exposed. After a glibc 2.28 locale change, every index on a text, varchar, char or citext column is a candidate for reindexing, because the sort order those indexes were built with may no longer match what the database now computes. The PostgreSQL wiki's guidance on locale data changes is the reference for this step. Inventory indexes by database and by column type, and note which ones use a collation other than the default. Check the locale in use with the datcollate column of pg_database and the collation on each column in pg_attribute and pg_collation. Then decide the order: reindex on the primary with REINDEX or REINDEX CONCURRENTLY where your PostgreSQL version and locking needs allow it, and confirm the exact options for your version in the PostgreSQL documentation before you run them. Rebuilt indexes will also be replicated, so plan the work with the replicas in mind. Replicas on a host with different locale data need their own check, since binary copies carry the old index contents. Schedule large rebuilds outside peak load, watch disk space and I/O during the rebuild, and keep a rollback path if a rebuild takes longer than planned.

Before committing to reindexing as the long-term fix, evaluate ICU collations as a separate decision. ICU is a different locale provider from the operating system's C library, so choosing it is not just a rebuild step. Creating or altering a collation to use ICU changes collation definitions, and existing columns and indexes that depend on a collation will need to be reviewed and usually rebuilt. The syntax for creating ICU collations, the options available for your PostgreSQL version and the behavior of comparisons, sorting and pattern matching under ICU should all be confirmed in the PostgreSQL documentation for your version before you decide. Also confirm how your application queries, constraints and extensions depend on existing collations. The choice matters beyond this upgrade: an ICU collation no longer depends on the distribution's glibc version, so it can reduce the reindexing you face at the next OS upgrade, but it does not remove the need to test and document collation behavior. Record the decision, the affected objects and the test results so the next operating system upgrade starts from a known position.

What to prepare before the OS upgrade starts

Most collation damage happens because teams start the operating system upgrade without knowing what they run, what depends on text ordering, or how to go back. The six items below turn that into written artifacts with named owners, so the upgrade can proceed or stop on evidence rather than assumptions.

Host, OS and glibc inventory

Produce a table listing every PostgreSQL host, primary and replica, with its current distribution release, glibc version and the locale settings each cluster was initialized with. Include hosts that only receive base backups or hold pg_basebackup restores, because those copies inherit the locale data of the machine they run on. Your infrastructure or platform team owns this inventory and should confirm it against the actual hosts rather than against the build documentation.

glibc locale change
2.28
Locale data changes

Text index and collation register

List every index on text, varchar, char and citext columns, with the table, the column collation and whether the index is a unique constraint or a foreign key dependency. Also record any column or database that uses an explicit COLLATE clause. The database team owns this register, and the output should be a query result saved with the change ticket, not a memory exercise.

Verified backups and a tested restore

Confirm that a recent base backup and the archived WAL needed to reach a consistent point are both present and readable, then restore them to a scratch host and start the cluster. A backup that has never been restored is not a rollback plan. The backup owner signs off on the restore result, and the record should show the restore time measured on the same hardware class as production.

Continuous archiving docs

Test environment from the same OS image

Build a staging cluster from the same distribution image, package set and glibc build that production will run after the upgrade, then load a recent copy of the data. Run the reindex and the application test suite there first. The platform team owns the image, and the application owners own the acceptance tests that exercise sorting, uniqueness and search on real text.

Reindex plan with agreed windows

Write a plan that lists each index to rebuild, the order of rebuilds, the expected lock behavior for each command, and the time window in which each application can accept degraded reads or writes. Confirm the windows with application owners before the change date, not on it. The plan should also name who approves a pause if a rebuild runs longer than expected.

Rollback owner and retained host

Name one person with authority to call a rollback and define the trigger conditions in advance, such as failed restore checks or unexpected query results after reindex. Keep the old host or a storage snapshot intact until the new cluster has passed agreed checks. The change owner on your side holds this decision, and the retention period should be written down, not left open.

What makes the collation work take longer

This table lists the factors that change how much work a glibc or collation change creates, and what to measure in your own environment before estimating. Read each row as a sizing question: the more of a driver you have, the more reindexing, validation and coordination the upgrade needs. Start with the first two rows, since index volume and replica OS versions usually set the bulk of the effort.

DriverWhy it mattersWhat to check
Number and size of text-type indexesEvery index on text, varchar, char or citext columns may need a rebuild because sort order can change. Large indexes take longer to rebuild and need more free disk space.Query pg_index and pg_class for indexes on text-like columns, sorted by size. Record total size and the largest individual indexes.
Number of replicas and their OS versionsStreaming replicas and pg_basebackup restores are binary copies, so a replica on a host with different locale data can disagree with the primary about sort order.List every standby with its host OS, glibc version and locale settings. Count how many hosts still run the older locale data.
Single data center or multiple sitesCross-site clusters add network transfer, change windows in more than one location and separate approvals, which slows coordination even when the technical steps are the same.Confirm which sites host replicas, backups and standby clusters, and who must approve changes in each one.
Applications that depend on sort orderUnique constraints on text, range queries, ordered output and keyset pagination can return different results or fail after the sort order changes, so each one needs review.Inventory applications and queries that rely on ORDER BY, text uniqueness, range filters or cursor pagination. Note which ones have automated tests.
Ability to rehearse on a copyA rehearsal shows reindex time, failed constraints and application behavior before production. Without a copy, the team learns these problems during the change window.Check whether a restored copy of production with matching OS and locale settings can be built, and how long a restore takes in your environment.
Number of distributions in the fleetEach distribution and release may ship different locale data, so the affected set and the steps can differ across hosts that look similar.Record distribution, release and glibc version for every database host, then group hosts that need the same procedure.

Questions teams ask before an OS upgrade under PostgreSQL

Does every operating system upgrade under PostgreSQL require a reindex?

Not every upgrade does, but any upgrade that moves glibc across the 2.28 locale change can change how text sorts, so the indexes on text columns need attention. Check the glibc version before and after the OS upgrade, using the target distribution's release notes and ldd --version on each host. If the glibc version does not cross 2.28 and the locale data is unchanged, the risk is lower, but confirm that with your own before and after comparison. Where the version does change, plan to reindex every index on text, varchar, char and citext columns before production use, as the PostgreSQL wiki advises.

How do we tell whether a streaming replica is affected by a collation change?

A streaming replica is affected when its host has different locale data from the primary, because it is a binary copy that depends on the same sort order. Compare the glibc version and the locale definitions on the primary and each replica, including hosts that are upgraded on different schedules. Replicas that were rebuilt with pg_basebackup on a newer OS carry the same problem, so check them too. Confirm the mismatch in your own environment before you assume a replica is safe, and treat the cluster as a single unit until every host matches.

Do pg_dump and logical replication avoid the collation problem?

Yes, according to the PostgreSQL wiki, pg_dump and logical replication are not affected in the way binary copies are, because they move logical data rather than the on-disk index files. The restored indexes are still built on the new host, so confirm that the destination uses the locale you expect. Any index on text columns that you carry over should still be checked against the sort order of the new environment, and you should test queries that depend on ordering before cutover.

What does an OS upgrade under PostgreSQL cost, and what drives the cost?

The cost has four main components: the inventory of hosts, indexes and locale settings, the reindex window, the rehearsal and cutover labor, and the verification afterward. Most of these are one-time costs for the upgrade itself, while monitoring and ongoing checks recur. The size of the database, the number of text indexes, the number of replicas and how many environments you must rehearse in all push the cost up. Ask any provider for a quote that lists each component separately, names who performs each step, and states what is included in the rehearsal. DeployOpen does not publish a price list, and a quote follows from the written scope.

How long does an OS upgrade with a collation check take, and what drives the duration?

The duration depends mostly on how long reindexing takes for your largest text indexes, how many replicas must be matched, and how many rehearsals the change requires. Reindexing time grows with table and index size and with the amount of available I/O during the change window. Plan the inventory and rehearsal first, because they set the actual cutover window. No fixed duration applies across environments, so ask for a timeline built from measurements on a copy of your own data.

What must our team provide before an OS upgrade engagement starts?

Your team should provide a complete inventory of PostgreSQL hosts, versions, replicas and databases, along with the list of text-based indexes and the locale settings in use. You also need access to the hosts and a non-production copy of the data for rehearsal, plus named owners for each application that depends on sort order. Agree on change windows and rollback criteria in advance. Confirm these items with your change board and platform owners at the start, since missing access or unclear owners are the most common delays.

Can our team run the collation and OS upgrade without outside help?

Yes, a team with PostgreSQL administration experience can perform this work, provided it has the time to inventory the cluster, rehearse the reindex and verify replicas. The main risks are missed text indexes, replicas upgraded out of step and changed sort order that breaks application queries. Decide whether your team has the capacity to handle these checks during the change window. If not, a fixed-scope engagement with written deliverables can cover the inventory, rehearsal and cutover support, and DeployOpen can describe that scope in writing before work starts.

How DeployOpen scopes and delivers a PostgreSQL OS upgrade

DeployOpen plans and delivers the operating system upgrade and the collation work around it as one written scope inside infrastructure you control. The work covers locale checks, reindexing of text indexes, replica rebuilds and the verification evidence your teams need before cutover.

How we scope

  • We inventory hosts, distributions, glibc versions and every PostgreSQL cluster, replica and backup set that shares the locale data.
  • We list text, varchar, char and citext indexes and identify which ones need reindexing or a rebuild window.
  • We agree the written scope, deliverables and timeline before work starts, with fixed-scope engagements as the default.

How we build

  • We rehearse the operating system upgrade on a copy of production, comparing collation results before and after the locale change.
  • We plan the reindex order, replica rebuild sequence and any ICU collation decisions, then test each step in a staging environment.
  • We run backup and restore checks on the upgraded hosts so recovery is proven before the change reaches production.

How we hand over

  • We deliver a runbook with pre-checks, reindex commands, rollback points and post-upgrade verification queries for your operators.
  • We document the locale and collation decisions, including which indexes were rebuilt and why, for your change records.
  • We walk your database and platform teams through the runbook and leave them with the evidence pack for review.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after the initial engagement ends.
  • A retainer can cover the next distribution release, minor PostgreSQL updates and re-testing of collation behavior after changes.
  • Confirm response expectations, coverage hours and retainer terms in writing with your quote before the engagement starts.

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.