ALTER_COLLATION(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’– ALTER COLLATION ๐Ÿ’–

okay bestie, so this is the ALTER COLLATION page from the PostgreSQL 18.6 docs (it lives in the 7 manual section, iykyk) and it's literally all about โœจreshapingโœจ a collation after it already exists. no cap, let's get into it ๐Ÿฆ‹


โœจ NAME โœจ

ALTER_COLLATION โ€” change the definition of a collation ๐Ÿ’…


๐ŸŽ€ 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 it, that's the vibe, she's a glow-up command ๐Ÿ’–

but listen, you gotta own the collation to run ALTER COLLATION. periodt. and if you wanna change the owner? you need to be able to SET ROLE to that new owning role, and that role has to have CREATE privilege on the collation's schema. ๐Ÿซถ

why tho? because those restrictions make sure that changing the owner doesn't let you do anything you couldn't already do by dropping the collation and recreating it. it's giving โœจconsistentโœจ. that said โ€” a superuser can alter ownership of any collation anyway ๐Ÿ‘‘ no rules for them fr fr.

๐Ÿ’… PARAMETERS ๐Ÿ’…

  • name โ€” the name of an existing collation, and yes it can be optionally schema-qualified ๐ŸŽ€
  • new_name โ€” the new name of the collation, the rebrand, the fresh identity โญ
  • new_owner โ€” the new owner of the collation, hand over the keys bestie ๐Ÿ”‘
  • new_schema โ€” the new schema for the collation, moving her to a new home ๐Ÿก
  • REFRESH VERSION โ€” update the collation's version. see Notes below, don't skip ๐Ÿ‘€

๐Ÿฆ‹ NOTES ๐Ÿฆ‹

so when a collation object gets created, the provider-specific version of the collation is recorded in the system catalog. then whenever the collation is used, the current version gets checked against that recorded version โ€” and if they don't match, you get a warning. like this one right here ๐Ÿ˜ญ

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.

now here's the serious part, and I need you to actually read this one: 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 totally legitimate circumstances โ€” like upgrading the operating system to a new major version, or using pg_upgrade to upgrade to server binaries linked with a newer version of ICU. when it 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. that updates the system catalog to record the current collation version and makes the warning go away. ๐ŸŽ‰

โš ๏ธ note that this does not actually check whether all affected objects have been rebuilt correctly. it just... trusts you. so be correct, bestie ๐Ÿ™ˆ

when you're using collations provided by libc, version information is recorded on systems using the GNU C library (most Linux systems), FreeBSD and Windows. when you're using collations provided by ICU, the version information is provided by the ICU library and is available on all platforms. ๐ŸŒˆ

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 โ€” maintainers are free to back-port newer collation definitions to older C library releases. ๐Ÿซ  when using Windows for collations, version information is only available for collations defined with BCP 47 language tags such as en-US. ๐ŸชŸ

for the database default collation, there's an analogous command: ALTER DATABASE ... REFRESH COLLATION VERSION. โœจ

and here's a query you can use to identify all collations in the current database that need to be refreshed, plus the objects that depend on them. screenshot this, you'll want it:

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 edition:

ALTER COLLATION "de_DE" RENAME TO german;

to change the owner of the collation en_US to joe:

ALTER COLLATION "en_US" OWNER TO joe;

ate. no crumbs. ๐Ÿ”ฅ


๐Ÿงš COMPATIBILITY ๐Ÿงš

there is no ALTER COLLATION statement in the SQL standard. we're built different, she's custom ๐Ÿ’…


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘


and that's the whole page, bestie!! ๐ŸŽ€ this was PostgreSQL 18.6, dated 2026, from the ALTER COLLATION(7) manual page. go refresh some versions and stay iconic ๐Ÿ’–โœจ๐Ÿฆ‹๐ŸŒธ๐Ÿ’œ

๐Ÿ“ฆ where this page comes from