{"Entry":{"collection":"sql","key":"alter-collation","name":"ALTER COLLATION","aliases":["altercollation"],"metadata":{"aliases":["altercollation"],"changed_in":["9.5","10","14"],"changes":[{"from":"9.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"9.1"},{"from":"9.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"changed","synopsis":{"added":["ALTER COLLATION name OWNER TO { new_owner | CURRENT_USER | SESSION_USER }"],"removed":[]},"to":"9.5"},{"from":"9.6","purpose_changed":false,"renamed":null,"sections":{"added":["notes"],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":{"added":["ALTER COLLATION name REFRESH VERSION"],"removed":[]},"to":"10"},{"from":"12","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"13"},{"from":"13","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":{"added":["ALTER COLLATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }"],"removed":[]},"to":"14"},{"from":"14","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["notes"],"removed":[]},"status":"changed","synopsis":null,"to":"15"},{"from":"15","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"16"}],"content_hash":"fb86910d4ee926df2e6bdaa3935c543a9fe77bc56cc7d4e73d019c93d29ff8af","editorial":{},"first_version":"9.1","group":"type","imported_at":"2026-09-30T17:43:37.401949+08:00","last_version":"20","name":"ALTER COLLATION","object":"COLLATION","position":3003,"present_in":["9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"change the definition of a collation","purpose_zh":"","related":["create-collation","drop-collation"],"slug":"alter-collation","source_rev":"a709ab85","synopsis":"ALTER COLLATION name REFRESH VERSION\n\nALTER COLLATION name RENAME TO new_name\nALTER COLLATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER COLLATION name SET SCHEMA new_schema","verb":"ALTER"}},"Definition":{"Collection":"sql","Key":"alter-collation","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"alter-collation","SourceRevision":"a709ab85","Facts":{"anchor":"SQL-ALTERCOLLATION","file":"sql-altercollation.html","lang":"en","name":"ALTER COLLATION","purpose":"change the definition of a collation","purpose_zh":"","related":["create-collation","drop-collation"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eALTER COLLATION\u003c/code\u003e changes the definition of a collation.\u003c/p\u003e\u003cp\u003eYou must own the collation to use \u003ccode class=\"command\"\u003eALTER COLLATION\u003c/code\u003e. To alter the owner, you must be able to \u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e to the new owning role, and that role must have \u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e privilege on the collation's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the collation. However, a superuser can alter ownership of any collation anyway.)\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name (optionally schema-qualified) of an existing collation.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe new name of the collation.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_owner\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe new owner of the collation.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe new schema for the collation.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eREFRESH VERSION\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eUpdate the collation's version. See \u003ca href=\"/docs/18/sql-altercollation.html#SQL-ALTERCOLLATION-NOTES\" title=\"Notes\"\u003eNotes\u003c/a\u003e below.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eWhen a collation object is created, the provider-specific version of the collation is recorded in the system catalog. When the collation is used, the current version is checked against the recorded version, and a warning is issued when there is a mismatch, for example:\u003c/p\u003e\u003cpre class=\"screen\"\u003eWARNING:  collation \"xx-x-icu\" has version mismatch\nDETAIL:  The collation in the database was created using version 1.2.3.4, but the operating system provides version 2.3.4.5.\nHINT:  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.\n\u003c/pre\u003e\u003cp\u003eA 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, such as when upgrading the operating system to a new major version or when using \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e 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 \u003ccode class=\"command\"\u003eREINDEX\u003c/code\u003e. When that is done, the collation version can be refreshed using the command \u003ccode class=\"literal\"\u003eALTER COLLATION ... REFRESH VERSION\u003c/code\u003e. This will update the system catalog to record the current collation version and will make the warning go away. Note that this does not actually check whether all affected objects have been rebuilt correctly.\u003c/p\u003e\u003cp\u003eWhen using collations provided by \u003ccode class=\"literal\"\u003elibc\u003c/code\u003e, 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 is provided by the ICU library and is available on all platforms.\u003c/p\u003e\u003cdiv class=\"note\"\u003e\u003ch3\u003eNote\u003c/h3\u003e\u003cp\u003eWhen 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 as maintainers are free to back-port newer collation definitions to older C library releases.\u003c/p\u003e\u003cp\u003eWhen using Windows for collations, version information is only available for collations defined with BCP 47 language tags such as \u003ccode class=\"literal\"\u003een-US\u003c/code\u003e.\u003c/p\u003e\u003c/div\u003e\u003cp\u003eFor the database default collation, there is an analogous command \u003ccode class=\"literal\"\u003eALTER DATABASE ... REFRESH COLLATION VERSION\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eThe following query can be used to identify all collations in the current database that need to be refreshed and the objects that depend on them:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eSELECT pg_describe_object(refclassid, refobjid, refobjsubid) AS \"Collation\",\n       pg_describe_object(classid, objid, objsubid) AS \"Object\"\n  FROM pg_depend d JOIN pg_collation c\n       ON refclassid = 'pg_collation'::regclass AND refobjid = c.oid\n  WHERE c.collversion \u0026lt;\u0026gt; pg_collation_actual_version(c.oid)\n  ORDER BY 1, 2;\n\u003c/pre\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eTo rename the collation \u003ccode class=\"literal\"\u003ede_DE\u003c/code\u003e to \u003ccode class=\"literal\"\u003egerman\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eALTER COLLATION \"de_DE\" RENAME TO german;\n\u003c/pre\u003e\u003cp\u003eTo change the owner of the collation \u003ccode class=\"literal\"\u003een_US\u003c/code\u003e to \u003ccode class=\"literal\"\u003ejoe\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eALTER COLLATION \"en_US\" OWNER TO joe;\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThere is no \u003ccode class=\"command\"\u003eALTER COLLATION\u003c/code\u003e statement in the SQL standard.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-collation/?v=18\" title=\"CREATE COLLATION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE COLLATION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-collation/?v=18\" title=\"DROP COLLATION\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP COLLATION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"ALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e REFRESH VERSION\n\nALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e RENAME TO \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_name\u003c/code\u003e\u003c/em\u003e\nALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e OWNER TO { \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_owner\u003c/code\u003e\u003c/em\u003e | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e SET SCHEMA \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_schema\u003c/code\u003e\u003c/em\u003e","synopsis_text":"ALTER COLLATION name REFRESH VERSION\n\nALTER COLLATION name RENAME TO new_name\nALTER COLLATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER COLLATION name SET SCHEMA new_schema"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"alter-collation","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"ALTER COLLATION","Summary":"更改排序规则的定义","BodyHTML":"\u003cpre\u003eALTER COLLATION name REFRESH VERSION\n\nALTER COLLATION name RENAME TO new_name\nALTER COLLATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER COLLATION name SET SCHEMA new_schema\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eALTER COLLATION\u003c/code\u003e更改排序规则的定义。\u003c/p\u003e\u003cp\u003e要使用\u003ccode\u003eALTER COLLATION\u003c/code\u003e，你必须拥有该排序规则。要更改拥有者，你必须能够对新的拥有角色执行\u003ccode\u003eSET ROLE\u003c/code\u003e，并且该角色必须在该排序规则所在模式上具有\u003ccode\u003eCREATE\u003c/code\u003e权限。（这些限制确保更改拥有者不会做出任何你无法通过删除并重新创建该排序规则来完成的事情。不过，超级用户无论如何都可以更改任何排序规则的所有权。）\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e一个现有排序规则的名称（可以是模式限定的）。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003enew_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e排序规则的新名称。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003enew_owner\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e排序规则的新拥有者。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003enew_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e排序规则的新模式。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eREFRESH VERSION\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e刷新排序规则版本。参阅下面的\u003ca href=\"/docs/18/sql-altercollation.html#SQL-ALTERCOLLATION-NOTES\" title=\"注解\" rel=\"nofollow\"\u003e注解\u003c/a\u003e。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e创建排序规则对象时，会在系统目录中记录由提供程序确定的排序规则版本。使用该排序规则时，会将当前版本与记录的版本进行比较；如果二者不匹配，就会发出警告，例如：\u003c/p\u003e\u003cpre\u003eWARNING:  collation \u0026#34;xx-x-icu\u0026#34; has version mismatch\nDETAIL:  The collation in the database was created using version 1.2.3.4, but the operating system provides version 2.3.4.5.\nHINT:  Rebuild all objects affected by this collation and run ALTER COLLATION pg_catalog.\u0026#34;xx-x-icu\u0026#34; REFRESH VERSION, or build PostgreSQL with the right library version.\n\u003c/pre\u003e\u003cp\u003e排序规则定义的变化可能导致索引损坏及其他问题，因为数据库系统依赖已存储对象具有特定的排序顺序。一般来说应避免这种情况，但在某些合理情形下仍可能发生，例如将操作系统升级到新的主版本，或者使用 \u003ccode\u003epg_upgrade\u003c/code\u003e升级到链接了较新 ICU 版本的服务器二进制文件时。出现这种情况时，应重建所有依赖该排序规则的对象，例如使用 \u003ccode\u003eREINDEX\u003c/code\u003e。完成后，可以使用命令 \u003ccode\u003eALTER COLLATION ... REFRESH VERSION\u003c/code\u003e刷新排序规则版本。这样会更新系统目录，使其记录当前的排序规则版本，并让该警告消失。请注意，这实际上并不会检查所有受影响对象是否都已被正确重建。\u003c/p\u003e\u003cp\u003e当使用\u003ccode\u003elibc\u003c/code\u003e提供的排序规则时，在使用 GNU C 库（大多数 Linux 系统）、FreeBSD 和 Windows 的系统上会记录版本信息。当使用 ICU 提供的排序规则时，版本信息由 ICU 库提供，并且在所有平台上都可用。\u003c/p\u003e\u003cdiv\u003e\u003ch3\u003e注意\u003c/h3\u003e\u003cp\u003e当使用 GNU C 库提供的排序规则时，C 库版本会被用作排序规则版本的代理。许多 Linux 发行版只有在升级 C 库时才会更改排序规则定义，但这种方法并不完美，因为维护人员也可以自由地将较新的排序规则定义回移植到较旧的 C 库版本中。\u003c/p\u003e\u003cp\u003e在 Windows 上使用排序规则时，版本信息仅适用于用 BCP 47 语言标签定义的排序规则，例如\u003ccode\u003een-US\u003c/code\u003e。\u003c/p\u003e\u003c/div\u003e\u003cp\u003e对于数据库默认排序规则，有一个对应的命令 \u003ccode\u003eALTER DATABASE ... REFRESH COLLATION VERSION\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e以下查询可用于识别当前数据库中所有需要刷新的排序规则，以及依赖它们的对象：\u003c/p\u003e\u003cpre\u003eSELECT pg_describe_object(refclassid, refobjid, refobjsubid) AS \u0026#34;Collation\u0026#34;,\n       pg_describe_object(classid, objid, objsubid) AS \u0026#34;Object\u0026#34;\n  FROM pg_depend d JOIN pg_collation c\n       ON refclassid = \u0026#39;pg_collation\u0026#39;::regclass AND refobjid = c.oid\n  WHERE c.collversion \u0026lt;\u0026gt; pg_collation_actual_version(c.oid)\n  ORDER BY 1, 2;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e要将排序规则\u003ccode\u003ede_DE\u003c/code\u003e重命名为\u003ccode\u003egerman\u003c/code\u003e：\u003c/p\u003e\u003cpre\u003eALTER COLLATION \u0026#34;de_DE\u0026#34; RENAME TO german;\n\u003c/pre\u003e\u003cp\u003e要将排序规则\u003ccode\u003een_US\u003c/code\u003e的拥有者改为\u003ccode\u003ejoe\u003c/code\u003e：\u003c/p\u003e\u003cpre\u003eALTER COLLATION \u0026#34;en_US\u0026#34; OWNER TO joe;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003eSQL 标准中没有\u003ccode\u003eALTER COLLATION\u003c/code\u003e语句。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/create-collation/?v=18\" title=\"CREATE COLLATION\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE COLLATION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-collation/?v=18\" title=\"DROP COLLATION\" rel=\"nofollow\"\u003e\u003cspan\u003eDROP COLLATION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"b8befde00a5d7ddbdba7d1af0f54f823cbb415adeda58cec80b32ec328f886bf","Payload":{"purpose_zh":"更改排序规则的定义","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eALTER COLLATION\u003c/code\u003e更改排序规则的定义。\u003c/p\u003e\u003cp\u003e要使用\u003ccode class=\"command\"\u003eALTER COLLATION\u003c/code\u003e，你必须拥有该排序规则。要更改拥有者，你必须能够对新的拥有角色执行\u003ccode class=\"literal\"\u003eSET ROLE\u003c/code\u003e，并且该角色必须在该排序规则所在模式上具有\u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e权限。（这些限制确保更改拥有者不会做出任何你无法通过删除并重新创建该排序规则来完成的事情。不过，超级用户无论如何都可以更改任何排序规则的所有权。）\u003c/p\u003e","key":"description","title":"描述"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e一个现有排序规则的名称（可以是模式限定的）。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e排序规则的新名称。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_owner\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e排序规则的新拥有者。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_schema\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e排序规则的新模式。\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eREFRESH VERSION\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e刷新排序规则版本。参阅下面的\u003ca href=\"/docs/18/sql-altercollation.html#SQL-ALTERCOLLATION-NOTES\" title=\"注解\"\u003e注解\u003c/a\u003e。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"参数"},{"html":"\u003cp\u003e创建排序规则对象时，会在系统目录中记录由提供程序确定的排序规则版本。使用该排序规则时，会将当前版本与记录的版本进行比较；如果二者不匹配，就会发出警告，例如：\u003c/p\u003e\u003cpre class=\"screen\"\u003eWARNING:  collation \"xx-x-icu\" has version mismatch\nDETAIL:  The collation in the database was created using version 1.2.3.4, but the operating system provides version 2.3.4.5.\nHINT:  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.\n\u003c/pre\u003e\u003cp\u003e排序规则定义的变化可能导致索引损坏及其他问题，因为数据库系统依赖已存储对象具有特定的排序顺序。一般来说应避免这种情况，但在某些合理情形下仍可能发生，例如将操作系统升级到新的主版本，或者使用 \u003ccode class=\"command\"\u003epg_upgrade\u003c/code\u003e升级到链接了较新 ICU 版本的服务器二进制文件时。出现这种情况时，应重建所有依赖该排序规则的对象，例如使用 \u003ccode class=\"command\"\u003eREINDEX\u003c/code\u003e。完成后，可以使用命令 \u003ccode class=\"literal\"\u003eALTER COLLATION ... REFRESH VERSION\u003c/code\u003e刷新排序规则版本。这样会更新系统目录，使其记录当前的排序规则版本，并让该警告消失。请注意，这实际上并不会检查所有受影响对象是否都已被正确重建。\u003c/p\u003e\u003cp\u003e当使用\u003ccode class=\"literal\"\u003elibc\u003c/code\u003e提供的排序规则时，在使用 GNU C 库（大多数 Linux 系统）、FreeBSD 和 Windows 的系统上会记录版本信息。当使用 ICU 提供的排序规则时，版本信息由 ICU 库提供，并且在所有平台上都可用。\u003c/p\u003e\u003cdiv class=\"note\"\u003e\u003ch3\u003e注意\u003c/h3\u003e\u003cp\u003e当使用 GNU C 库提供的排序规则时，C 库版本会被用作排序规则版本的代理。许多 Linux 发行版只有在升级 C 库时才会更改排序规则定义，但这种方法并不完美，因为维护人员也可以自由地将较新的排序规则定义回移植到较旧的 C 库版本中。\u003c/p\u003e\u003cp\u003e在 Windows 上使用排序规则时，版本信息仅适用于用 BCP 47 语言标签定义的排序规则，例如\u003ccode class=\"literal\"\u003een-US\u003c/code\u003e。\u003c/p\u003e\u003c/div\u003e\u003cp\u003e对于数据库默认排序规则，有一个对应的命令 \u003ccode class=\"literal\"\u003eALTER DATABASE ... REFRESH COLLATION VERSION\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e以下查询可用于识别当前数据库中所有需要刷新的排序规则，以及依赖它们的对象：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eSELECT pg_describe_object(refclassid, refobjid, refobjsubid) AS \"Collation\",\n       pg_describe_object(classid, objid, objsubid) AS \"Object\"\n  FROM pg_depend d JOIN pg_collation c\n       ON refclassid = 'pg_collation'::regclass AND refobjid = c.oid\n  WHERE c.collversion \u0026lt;\u0026gt; pg_collation_actual_version(c.oid)\n  ORDER BY 1, 2;\n\u003c/pre\u003e","key":"notes","title":"注解"},{"html":"\u003cp\u003e要将排序规则\u003ccode class=\"literal\"\u003ede_DE\u003c/code\u003e重命名为\u003ccode class=\"literal\"\u003egerman\u003c/code\u003e：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eALTER COLLATION \"de_DE\" RENAME TO german;\n\u003c/pre\u003e\u003cp\u003e要将排序规则\u003ccode class=\"literal\"\u003een_US\u003c/code\u003e的拥有者改为\u003ccode class=\"literal\"\u003ejoe\u003c/code\u003e：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eALTER COLLATION \"en_US\" OWNER TO joe;\n\u003c/pre\u003e","key":"examples","title":"示例"},{"html":"\u003cp\u003eSQL 标准中没有\u003ccode class=\"command\"\u003eALTER COLLATION\u003c/code\u003e语句。\u003c/p\u003e","key":"compatibility","title":"兼容性"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-collation/?v=18\" title=\"CREATE COLLATION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE COLLATION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-collation/?v=18\" title=\"DROP COLLATION\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP COLLATION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"另见"}],"sections_same_as":"","synopsis_html":"ALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e REFRESH VERSION\n\nALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e RENAME TO \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_name\u003c/code\u003e\u003c/em\u003e\nALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e OWNER TO { \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_owner\u003c/code\u003e\u003c/em\u003e | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER COLLATION \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e SET SCHEMA \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_schema\u003c/code\u003e\u003c/em\u003e","synopsis_text":"ALTER COLLATION name REFRESH VERSION\n\nALTER COLLATION name RENAME TO new_name\nALTER COLLATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER COLLATION name SET SCHEMA new_schema"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
