{"Entry":{"collection":"sql","key":"alter-statistics","name":"ALTER STATISTICS","aliases":["alterstatistics"],"metadata":{"aliases":["alterstatistics"],"changed_in":["13","14","17"],"changes":[{"from":"9.6","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"10"},{"from":"12","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":{"added":["ALTER STATISTICS name SET STATISTICS new_target"],"removed":[]},"to":"13"},{"from":"13","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"changed","synopsis":{"added":["ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }"],"removed":[]},"to":"14"},{"from":"15","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description"],"removed":[]},"status":"changed","synopsis":null,"to":"16"},{"from":"16","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":{"added":["ALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }"],"removed":[]},"to":"17"}],"content_hash":"0c04843ded31cbdaaada4d1ad467554da26bf830768544d3bd169ccc10199aa1","editorial":{},"first_version":"10","group":"index","imported_at":"2026-09-30T17:43:36.951554+08:00","last_version":"20","name":"ALTER STATISTICS","object":"STATISTICS","position":1005,"present_in":["10","11","12","13","14","15","16","17","18","19","20"],"purpose":"change the definition of an extended statistics object","purpose_zh":"","related":["create-statistics","drop-statistics"],"slug":"alter-statistics","source_rev":"a709ab85","synopsis":"ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER STATISTICS name RENAME TO new_name\nALTER STATISTICS name SET SCHEMA new_schema\nALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }","verb":"ALTER"}},"Definition":{"Collection":"sql","Key":"alter-statistics","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"alter-statistics","SourceRevision":"a709ab85","Facts":{"anchor":"SQL-ALTERSTATISTICS","file":"sql-alterstatistics.html","lang":"en","name":"ALTER STATISTICS","purpose":"change the definition of an extended statistics object","purpose_zh":"","related":["create-statistics","drop-statistics"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e changes the parameters of an existing extended statistics object. Any parameters not specifically set in the \u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e command retain their prior settings.\u003c/p\u003e\u003cp\u003eYou must own the statistics object to use \u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e. To change a statistics object's schema, you must also have \u003ccode class=\"literal\"\u003eCREATE\u003c/code\u003e privilege on the new schema. 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 statistics object's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the statistics object. However, a superuser can alter ownership of any statistics object 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 the statistics object to be altered.\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 user name of the new owner of the statistics object.\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 for the statistics object.\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 statistics object.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_target\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe statistic-gathering target for this statistics object for subsequent \u003ca href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\"\u003e\u003ccode class=\"command\"\u003eANALYZE\u003c/code\u003e\u003c/a\u003e operations. The target can be set in the range 0 to 10000. Set it to \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e to revert to using the system default statistics target (\u003ca href=\"/docs/18/runtime-config-query.html#GUC-DEFAULT-STATISTICS-TARGET\"\u003edefault_statistics_target\u003c/a\u003e). (Setting to a value of -1 is an obsolete way spelling to get the same outcome.) For more information on the use of statistics by the \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e query planner, refer to \u003ca href=\"/docs/18/planner-stats.html\" title=\"14.2. Statistics Used by the Planner\"\u003eSection 14.2\u003c/a\u003e.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eThere is no \u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e command in the SQL standard.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-statistics/?v=18\" title=\"CREATE STATISTICS\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE STATISTICS\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-statistics/?v=18\" title=\"DROP STATISTICS\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP STATISTICS\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"ALTER STATISTICS \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 STATISTICS \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 STATISTICS \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\nALTER STATISTICS \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e SET STATISTICS { \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_target\u003c/code\u003e\u003c/em\u003e | DEFAULT }","synopsis_text":"ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER STATISTICS name RENAME TO new_name\nALTER STATISTICS name SET SCHEMA new_schema\nALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"alter-statistics","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"ALTER STATISTICS","Summary":"更改扩展统计对象的定义","BodyHTML":"\u003cpre\u003eALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER STATISTICS name RENAME TO new_name\nALTER STATISTICS name SET SCHEMA new_schema\nALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eALTER STATISTICS\u003c/code\u003e修改现有扩展统计对象的参数。凡未在\u003ccode\u003eALTER STATISTICS\u003c/code\u003e命令中明确设置的参数，都会保留其原有设置。\u003c/p\u003e\u003cp\u003e要使用\u003ccode\u003eALTER STATISTICS\u003c/code\u003e，你必须拥有该统计对象。要更改统计对象的模式，你还必须在新模式上具有\u003ccode\u003eCREATE\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_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_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_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\u003cem\u003e\u003ccode\u003enew_target\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e该统计对象在后续\u003ca href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\" rel=\"nofollow\"\u003e\u003ccode\u003eANALYZE\u003c/code\u003e\u003c/a\u003e 操作中的统计信息收集目标。目标值可设置在 0 到 10000 的范围内。将其设置为\u003ccode\u003eDEFAULT\u003c/code\u003e可恢复为使用系统默认统计目标（\u003ca href=\"/docs/18/runtime-config-query.html#GUC-DEFAULT-STATISTICS-TARGET\" rel=\"nofollow\"\u003edefault_statistics_target\u003c/a\u003e）。将其设置为 -1 是得到相同结果的一种过时写法。有关\u003cspan\u003ePostgreSQL\u003c/span\u003e查询规划器如何使用统计信息的更多内容，请参见\u003ca href=\"/docs/18/planner-stats.html\" rel=\"nofollow\"\u003e第 14.2 节\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\u003eSQL 标准中没有\u003ccode\u003eALTER STATISTICS\u003c/code\u003e命令。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/create-statistics/?v=18\" title=\"CREATE STATISTICS\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE STATISTICS\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-statistics/?v=18\" title=\"DROP STATISTICS\" rel=\"nofollow\"\u003e\u003cspan\u003eDROP STATISTICS\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"30d2eb2b99dbaaf570b10c48f5d37a8c47eed0bd10434a1f495bb36913083da4","Payload":{"purpose_zh":"更改扩展统计对象的定义","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e修改现有扩展统计对象的参数。凡未在\u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e命令中明确设置的参数，都会保留其原有设置。\u003c/p\u003e\u003cp\u003e要使用\u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e，你必须拥有该统计对象。要更改统计对象的模式，你还必须在新模式上具有\u003ccode class=\"literal\"\u003eCREATE\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_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_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_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\u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_target\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e该统计对象在后续\u003ca href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\"\u003e\u003ccode class=\"command\"\u003eANALYZE\u003c/code\u003e\u003c/a\u003e 操作中的统计信息收集目标。目标值可设置在 0 到 10000 的范围内。将其设置为\u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e可恢复为使用系统默认统计目标（\u003ca href=\"/docs/18/runtime-config-query.html#GUC-DEFAULT-STATISTICS-TARGET\"\u003edefault_statistics_target\u003c/a\u003e）。将其设置为 -1 是得到相同结果的一种过时写法。有关\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e查询规划器如何使用统计信息的更多内容，请参见\u003ca href=\"/docs/18/planner-stats.html\" title=\"14.2. 规划器使用的统计信息\"\u003e第 14.2 节\u003c/a\u003e。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"参数"},{"html":"\u003cp\u003eSQL 标准中没有\u003ccode class=\"command\"\u003eALTER STATISTICS\u003c/code\u003e命令。\u003c/p\u003e","key":"compatibility","title":"兼容性"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/create-statistics/?v=18\" title=\"CREATE STATISTICS\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE STATISTICS\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-statistics/?v=18\" title=\"DROP STATISTICS\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP STATISTICS\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"另见"}],"sections_same_as":"","synopsis_html":"ALTER STATISTICS \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 STATISTICS \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 STATISTICS \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\nALTER STATISTICS \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e SET STATISTICS { \u003cem class=\"replaceable\"\u003e\u003ccode\u003enew_target\u003c/code\u003e\u003c/em\u003e | DEFAULT }","synopsis_text":"ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }\nALTER STATISTICS name RENAME TO new_name\nALTER STATISTICS name SET SCHEMA new_schema\nALTER STATISTICS name SET STATISTICS { new_target | DEFAULT }"}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
