ALTER_SCHEMA(7pg17)
π
ALTER SCHEMA β the ALTER_SCHEMA(7pg17) glow-up, PostgreSQL 17.11 edition
okay so bestie, welcome to the ALTER_SCHEMA page. this is the one where you change the definition of a schema β think of it as a schema makeover, not a whole new schema. β¨
β¨ SYNOPSIS β¨
ALTER SCHEMA name RENAME TO new_name
ALTER SCHEMA name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
that's it. two moves. rename it or hand it to someone else. iconic, lowkey minimal. π
πΈ DESCRIPTION πΈ
so ALTER SCHEMA changes the definition of a schema. that's the whole thing. short and sweet, fr fr. π¦
now here's the part where you actually have to have the receipts:
- You must own the schema to use
ALTER SCHEMA. no ownership, no glow-up. π - To rename a schema you must also have the
CREATEprivilege for the database. - To alter the owner, you must be able to
SET ROLEto the new owning role, and that role must have theCREATEprivilege for the database.
and yes β superusers have all these privileges automatically, so if you're the main character with superuser energy, you're chilling. π
π§ PARAMETERS π§
nameβ the name of an existing schema. like, it has to already exist, bestie, we can't rename a vibe that isn't there. πnew_nameβ the new name of the schema. and here's the catch: the new name cannot begin withpg_, because those names are reserved for system schemas. sopg_my_slay_schema? not happening. πnew_ownerβ the new owner of the schema. hand it over, it's theirs now. π«Ά
π COMPATIBILITY π
there is no ALTER SCHEMA statement in the SQL standard. so if someone asks "is this standard SQL?" β nope, not even a little. it's giving PostgreSQL exclusive. π
π SEE ALSO π
CREATE SCHEMA(CREATE_SCHEMA(7))DROP SCHEMA(DROP_SCHEMA(7))
the holy trinity: make it, alter it, drop it. periodt. π₯
β lil reminder before you go: you need ownership to alter,CREATEon the database to rename, andSET ROLE+CREATEto change the owner. don't skip the vibe check on privileges or the server will simply say no. π
that's the whole page, bestie β you ate. π
this one's from the PostgreSQL 17.11 docs, dated 2026. go be iconic with your schemas. β¨ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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