ALTER_COLLATION(7)
๐ 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 ๐
CREATE COLLATION(CREATE_COLLATION(7))DROP COLLATION(DROP_COLLATION(7))
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
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms