ALTER_COLLATION(7pg17)

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

πŸ’… ALTER COLLATION β€” change the definition of a collation

okay so this is the ALTER COLLATION(7) page from the PostgreSQL 17.11 Documentation, and bestie, it's literally the glow-up manual for your collations ✨ (yes, the things that decide how text sorts and compares β€” very main character of them).


✨ 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 πŸ¦‹

You must own the collation to use ALTER COLLATION. and if you wanna alter the owner? you need to be able to SET ROLE to the new owning role, and that role needs CREATE privilege on the collation's schema. (these restrictions are literally there to enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the collation. however β€” plot twist β€” a superuser can alter ownership of any collation anyway πŸ‘‘)


🌸 PARAMETERS 🌸

  • name β€” the name of an existing collation, optionally schema-qualified. iykyk πŸ’–
  • new_name β€” the new name of the collation. fresh start energy.
  • new_owner β€” the new owner of the collation.
  • new_schema β€” the new schema for the collation.
  • REFRESH VERSION β€” update the collation's version. see Notes below, bestie, don't skip it πŸ™ˆ

⭐ NOTES ⭐

So when a collation object is created, the provider-specific version of the collation gets recorded in the system catalog. Then, when the collation is used, the current version is checked against the 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.
⚠️ okay this next part is serious, no cap: 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 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 this happens, all objects depending on the collation should be rebuilt, for example using REINDEX. and once that's done, the collation version can be refreshed 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 πŸ’€ so like... actually do the rebuild, bestie.

When using collations provided by libc, version information is recorded on systems using the GNU C library (most Linux systems), FreeBSD and Windows. when using collations provided by ICU, the version information comes from 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, because 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 this query right here can be used to identify all collations in the current database that need to be refreshed, plus the objects that depend on them β€” it's giving detective energy πŸ”:

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:

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;

slay. go give joe that collation πŸŽ€


πŸ¦‹ COMPATIBILITY πŸ¦‹

There is no ALTER COLLATION statement in the SQL standard. we're built different πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘


mwah πŸ’– that's the whole page β€” brought to you by PostgreSQL 17.11, dated 2026, and this iconic little ALTER COLLATION(7) manual entry. stan the docs, bestie, they ate 🌟

πŸ“¦ where this page comes from