ALTER_STATISTICS(7pg14)

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

πŸ’… 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 CREATE privilege 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 CREATE privilege 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 like myschema.mystats is 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 subsequent ANALYZE operations. okay so here's the tea:
    • the target can be set in the range 0 to 10000
    • alternatively, set it to -1 to 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 ⭐


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