ALTER_COLLATION(7pg14)

πŸ“¦ version 14.24, in opensuse-leap 16.0

✨ ALTER COLLATION ✨

okay so bestie, welcome to the ALTER COLLATION page from the PostgreSQL 14.24 Documentation (yes, the 7 in ALTER COLLATION(7) means it's a SQL command page, iykyk) πŸ’… this one's all about changing the definition of a collation β€” and no cap, it's shorter than you'd think but every word matters 🫢


🌸 SYNOPSIS 🌸

ALTER COLLATION name REFRESH VERSION

ALTER COLLATION name RENAME TO new_name
ALTER COLLATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER COLLATION name SET SCHEMA new_schema

πŸ¦‹ DESCRIPTION πŸ¦‹

ALTER COLLATION changes the definition of a collation. that's the whole vibe ✨

but here's the gatekeeping part, bestie β€” you must own the collation to use ALTER COLLATION. and if you wanna change the owner? you also gotta be a direct or indirect member of the new owning role, and that role has to have CREATE privilege on the collation's schema. 😭

why tho? because these restrictions enforce that altering the owner doesn't let you do anything you couldn't already do by dropping and recreating the collation. it's giving "no cheating" energy fr fr.

but plot twist β€” a superuser can alter ownership of any collation anyway πŸ‘‘ periodt.


πŸŽ€ PARAMETERS πŸŽ€

  • name β€” the name of an existing collation. it can be optionally schema-qualified, so go ahead and be specific if you want πŸ’–
  • new_name β€” the new name of the collation. rebranding era ✨
  • new_owner β€” the new owner of the collation. handing over the crown πŸ‘‘
  • new_schema β€” the new schema for the collation. moving day 🚚
  • REFRESH VERSION β€” updates the collation's version. the deets are in Notes below, keep scrolling bestie πŸ‘€

πŸ’œ NOTES πŸ’œ

🧊 the ICU situation

when you're using collations provided by the ICU library, the ICU-specific version of the collator gets recorded in the system catalog at the moment the collation object is created πŸ“. then, whenever the collation is used, the current version is checked against that recorded version β€” and if there's a mismatch, you get a warning, like this:

WARNING:  collation "xx-x-icu" has version mismatch
DETAIL:  The collation in the database was created using version 1.2.3.4, but the operating system provides version 2.3.4.5.
HINT:  Rebuild all objects affected by this collation and run ALTER COLLATION pg_catalog."xx-x-icu" REFRESH VERSION, or build PostgreSQL with the right library version.

πŸ’€ the scary part (pay attention)

a change in collation definitions can lead to corrupt indexes and other problems, because the database system relies on stored objects having a certain sort order. 😭 generally this should be avoided β€” but it can happen in legitimate circumstances, like when you use pg_upgrade to upgrade to server binaries linked with a newer version of ICU.

when that happens, all objects depending on the collation should be rebuilt, for example using REINDEX. once that's done, you can refresh the collation version with ALTER COLLATION ... REFRESH VERSION. this updates the system catalog to record the current collator version and makes the warning go away ✨

⚠️ important caveat bestie: this does not actually check whether all affected objects have been rebuilt correctly. it just trusts you. so like… actually rebuild them, okay? πŸ™ˆ

🌈 libc collations

when using collations provided by libc, version information is recorded on systems using the GNU C library (most Linux systems), FreeBSD and Windows.

πŸ’‘ Note when using the GNU C library for collations, the C library's version is used as a proxy for the collation version. many Linux distributions change collation definitions only when upgrading the C library β€” but this approach is imperfect, because maintainers are free to back-port newer collation definitions to older C library releases. so it's giving "close enough" not "guaranteed" 🫠 and when using Windows for collations, version information is only available for collations defined with BCP 47 language tags such as en-US. πŸ‡ΊπŸ‡Έ

πŸ“ and also

currently, there is no version tracking for the database default collation. it's just out here living its life unmonitored 🌸

πŸ” the detective query

this following query can be used to identify all collations in the current database that need to be refreshed, plus the objects that depend on them:

SELECT pg_describe_object(refclassid, refobjid, refobjsubid) AS "Collation",
       pg_describe_object(classid, objid, objsubid) AS "Object"
  FROM pg_depend d JOIN pg_collation c
       ON refclassid = 'pg_collation'::regclass AND refobjid = c.oid
  WHERE c.collversion <> pg_collation_actual_version(c.oid)
  ORDER BY 1, 2;

πŸ”₯ EXAMPLES πŸ”₯

to rename the collation de_DE to german β€” glow-up complete πŸ‡©πŸ‡ͺ:

ALTER COLLATION "de_DE" RENAME TO german;

to change the owner of the collation en_US to joe β€” crown passed πŸ‘‘:

ALTER COLLATION "en_US" OWNER TO joe;

⭐ COMPATIBILITY ⭐

there is no ALTER COLLATION statement in the SQL standard. so if you were about to flex this on some other database… don't πŸ’€ PostgreSQL only, bestie.


🌈 SEE ALSO 🌈


and that's the page!! mwah πŸ’– this was brought to you by PostgreSQL 14.24, dated 2026, and lovingly filed under ALTER COLLATION(7) β€” go forth and refresh those versions responsibly bestie 🫢✨

πŸ“¦ where this page comes from