ALTER_TABLESPACE(7pg18)
๐ ALTER_TABLESPACE โ change the definition of a tablespace
okay bestie, so this is ALTER_TABLESPACE, from the PostgreSQL 18.6 Documentation era, section 7 of the manual. it's giving "let me redecorate my storage" and honestly? iconic. let's get into it ๐
โจ SYNOPSIS โจ
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 [, ... ] )
look at those four little forms. four ways to glow up a tablespace. no cap. ๐
๐ฆ DESCRIPTION ๐ฆ
ALTER TABLESPACE is literally the command you use to change the definition of a tablespace. that's the whole vibe.
but listen โ there's a rule, and it's not optional. you must own the tablespace to change its definition. and if you're trying to change the owner? you also need to be able to SET ROLE to the new owning role. (also, small flex: superusers have these privileges automatically, no questions asked ๐)
๐ PARAMETERS ๐
nameโ the name of an existing tablespace. it has to actually exist, bestie, we can't rename a vibe that isn't there ๐new_nameโ the new name you're giving the tablespace. important: it can't begin withpg_, because names starting withpg_are reserved for system tablespaces. that prefix is taken, it's their thing, don't touch it ๐new_ownerโ the new owner of the tablespace. handing over the keys ๐tablespace_optionโ a tablespace parameter to be set or reset. rn the only available parameters areseq_page_cost,random_page_cost,effective_io_concurrencyandmaintenance_io_concurrency. setting these values for one specific tablespace overrides the planner's usual estimate of the cost of reading pages from tables in that tablespace, and overrides how many concurrent I/Os get issued โ the stuff that would normally be established by the configuration parameters of the same name (peepseq_page_cost,random_page_cost,effective_io_concurrency,maintenance_io_concurrency). this is lowkey useful when one tablespace lives on a disk that's faster or slower than the rest of the I/O subsystem. like, one disk is a sports car and the others are a bicycle, you know? ๐๐จ
๐ธ EXAMPLES ๐ธ
rename tablespace index_space to fast_raid:
ALTER TABLESPACE index_space RENAME TO fast_raid;
change the owner of tablespace index_space:
ALTER TABLESPACE index_space OWNER TO mary;
see how clean that is? ate and left no crumbs ๐
๐ COMPATIBILITY ๐
there is no ALTER TABLESPACE statement in the SQL standard. it's not a thing there. periodt.
๐ SEE ALSO ๐
CREATE TABLESPACE(CREATE_TABLESPACE(7))DROP TABLESPACE(DROP_TABLESPACE(7))
and that's the whole page, bestie ๐ซถ this was PostgreSQL 18.6, dated 2026, and yes โ ALTER TABLESPACE(7) really is the moment. go forth and rename responsibly โจ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms