ALTER_STATISTICS(7pg14)
π ALTER STATISTICS (7pg14) β the PostgreSQL 14.24 glow-up guide
okay so bestie, welcome to the page where we take an extended statistics object that already exists and give it a whole new vibe. yes, this is the ALTER STATISTICS page from the PostgreSQL 14.24 Documentation, and we're gonna read it together like it's a group chat at 1am π«Ά
β¨ NAME β¨
ALTER_STATISTICS β literally the command that changes the definition of an extended statistics object. that's it, that's the whole thing. iconic. π
π¦ SYNOPSIS π¦
here's the whole menu, no cap β copy these exactly, i'm not about to let you typo your way through this:
ALTER STATISTICS name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER STATISTICS name RENAME TO new_name
ALTER STATISTICS name SET SCHEMA new_schema
ALTER STATISTICS name SET STATISTICS new_target
four whole forms. pick your fighter. π
πΈ DESCRIPTION πΈ
so ALTER STATISTICS changes the parameters of an existing extended statistics object. the key deets: any parameters you don't specifically set in the ALTER STATISTICS command retain their prior settings. so it's not a "reset everything" situation β it's a "tweak what i say" situation. lowkey polite of it tbh.
and now the permission part, which is the part everyone skips and then gets mad about π:
- you must own the statistics object to use
ALTER STATISTICS. - to change a statistics object's schema, you must also have
CREATEprivilege on the new schema. - to alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have
CREATEprivilege on the statistics object's schema.
and why all these restrictions? because they enforce that altering the owner doesn't do anything you couldn't already do by dropping and recreating the statistics object. it's a "no sneaky backdoor ownership laundering" rule. love that for us.
plot twist though: a superuser can alter ownership of any statistics object anyway. main character energy fr fr π
π PARAMETERS π
here's the whole cast, one by one:
nameβ the name of the statistics object you're altering, optionally schema-qualified. (so likemyschema.mystatsis valid, iykyk β¨)new_ownerβ the user name of the new owner of the statistics object. handing over the keys πnew_nameβ the new name for the statistics object. rebrand era πnew_schemaβ the new schema for the statistics object. moving neighborhoods π¦new_targetβ the statistic-gathering target for this statistics object for subsequentANALYZEoperations. okay so here's the tea:- the target can be set in the range 0 to 10000
- alternatively, set it to
-1to revert to using the maximum of the statistics target of the referenced columns, if set, or the system default statistics target (default_statistics_target) - for more info on how the PostgreSQL query planner uses statistics, go read Section 14.2
like, that's the whole range. zero to ten thousand. go off i guess π
π§ COMPATIBILITY π§
there is no ALTER STATISTICS command in the SQL standard. so if someone asks "is this standard SQL?" β nope, it's a PostgreSQL original, and honestly? it ate. π
β SEE ALSO β
CREATE STATISTICS(CREATE_STATISTICS(7)) β for when you don't have one yet πDROP STATISTICS(DROP_STATISTICS(7)) β for when the vibes are off and it has to go π
heads up bestie: nothing on this page is deprecated or dangerous, it's all just permissions and target tuning. but do read the ownership rules again before you start handing out OWNER TO like friendship bracelets, ok? π
and that's the page!! no notes, you understood all of it, i'm so proud π₯Ή
PostgreSQL 14.24 Β· dated 2026 Β· ALTER STATISTICS(7) β xoxo, your local unix bestie π
β¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms