ALTER_TABLESPACE(7pg16)
π« ALTER TABLESPACE π«
okay so bestie, welcome to ALTER TABLESPACE(7) β that's the PostgreSQL 16.15 documentation page for the statement that lets you change the definition of a tablespace. Tablespace glow-ups, basically. Renting out new real estate, renaming the place, handing over the keys. π β¨
β¨ SYNOPSIS β¨
Here's the whole vibe in four lines, no cap:
ALTER TABLESPACE name RENAME TO new_name
ALTER TABLESPACE name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER TABLESPACE name SET ( tablespace_option = value [, ... ] )
ALTER TABLESPACE name RESET ( tablespace_option [, ... ] )
Pick your fighter: rename it, re-own it, set some options, or reset some options. Slay. π
π¦ DESCRIPTION π¦
ALTER TABLESPACE is literally the statement you use to change the definition of a tablespace. That's it, that's the whole job description. β¨
Now the important part β the permissions vibe check: you must own the tablespace to change its definition. And if you're changing the owner, you also have to be able to SET ROLE to the new owning role. (Also, note that superusers have these privileges automatically β main character energy, they don't have to ask. π)
fr fr, don't try to alter a tablespace you don't own. It's giving "trespassing" and the server will not be nice about it. π
π PARAMETERS π
nameβ the name of an existing tablespace. That's the one you're about to alter, bestie.new_nameβ the new name of the tablespace. Massive caveat: the new name cannot begin withpg_, because those names are reserved for system tablespaces. Like, respect the reserved parking spots. π«new_ownerβ the new owner of the tablespace. Handing over the crown. πtablespace_optionβ a tablespace parameter to be set or reset. Hiii, so right now the only available parameters areseq_page_cost,random_page_cost,effective_io_concurrencyandmaintenance_io_concurrency. When you set these values for a particular tablespace, they override the planner's usual estimate of the cost of reading pages from tables in that tablespace, and the executor's prefetching behavior β both of which are normally established by the configuration parameters of the same name (peepseq_page_cost,random_page_cost,effective_io_concurrency,maintenance_io_concurrency). This may be useful if one tablespace is located on a disk which is faster or slower than the remainder of the I/O subsystem. ππ’ lowkey one of the most underrated tuning tricks, iykyk.
πΈ EXAMPLES πΈ
Rename tablespace index_space to fast_raid β rebranding era:
ALTER TABLESPACE index_space RENAME TO fast_raid;
Change the owner of tablespace index_space β here's to new management:
ALTER TABLESPACE index_space OWNER TO mary;
π COMPATIBILITY π
Not to be dramatic, but there is no ALTER TABLESPACE statement in the SQL standard. So this is a PostgreSQL-only moment. π
π«Ά SEE ALSO π«Ά
CREATE TABLESPACE(CREATE_TABLESPACE(7))DROP TABLESPACE(DROP_TABLESPACE(7))
π okay that's the whole page bestie, go forth and alter responsibly π
PostgreSQL 16.15, dated 2026 β mwah, love u, bye! ππ¦β¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-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