ALTER_STATISTICS(7pg13)
β¨ ALTER_STATISTICS β¨
Okay so bestie, welcome to the glow-up page for your extended statistics objects π This is from the PostgreSQL 13.23 Documentation, and it's literally all about tweaking the definition of an extended statistics object. No cap, it's giving "main character energy" for your query planner.
SYNOPSIS
ALTER STATISTICS name OWNER TO { new_owner | 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
DESCRIPTION π¦
So ALTER STATISTICS is the command that changes the parameters of an existing extended statistics object. The way that any parameters you don't specifically set in the ALTER STATISTICS command just retain their prior settings? Iconic. It's like when you only touch up your eyeliner and leave the rest of the face beat π
You must own the statistics object to use ALTER STATISTICS. Periodt. To change a statistics object's schema, you must also have CREATE privilege on the new schema. And 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. These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the statistics object. However β and this is lowkey important β a superuser can alter ownership of any statistics object anyway π
PARAMETERS πΈ
nameβ The name (optionally schema-qualified) of the statistics object to be altered. It's giving "who is she" but make it technical.new_ownerβ The user name of the new owner of the statistics object. Handing over the keys to the kingdom, fr fr.new_nameβ The new name for the statistics object. A rebrand, if you will β¨new_schemaβ The new schema for the statistics object. Moving neighborhoods, no biggie.new_targetβ The statistic-gathering target for this statistics object for subsequentANALYZE(7)operations. The target can be set in the range0to10000. 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 information on the use of statistics by the PostgreSQL query planner, refer to Section 14.2. This is the "how much attention should I pay to you" dial, and honestly, same.
COMPATIBILITY π
There is no ALTER STATISTICS command in the SQL standard. Not me finding out it's built different π It's a PostgreSQL original, iykyk.
SEE ALSO π«Ά</hidden>
CREATE STATISTICS (CREATE_STATISTICS(7))β for when you're ready to make it official.DROP STATISTICS (DROP_STATISTICS(7))β for when it's time to say goodbye π
And that's the whole vibe check, bestie! π This page was brought to you by PostgreSQL 13.23, dated 2025 β go off and alter those statistics like the icon you are π β¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-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