ALTER_TABLESPACE(7pg13)

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

✨ ALTER TABLESPACE ✨

okay bestie, so this is the PostgreSQL 13.23 page for ALTER TABLESPACE β€” literally the glow-up command for your tablespaces πŸ’… it's the one that changes the definition of a tablespace (not its vibes, its actual definition, but honestly both tbh).


πŸŽ€ SYNOPSIS πŸŽ€

ALTER TABLESPACE name RENAME TO new_name
ALTER TABLESPACE name OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
ALTER TABLESPACE name SET ( tablespace_option = value [, ... ] )
ALTER TABLESPACE name RESET ( tablespace_option [, ... ] )

four whole flavors, pick your fighter πŸ¦‹


🌸 DESCRIPTION 🌸

ALTER TABLESPACE can be used to change the definition of a tablespace. that's the whole arc, no cap.

but β€” and this is the part where you gotta pay attention, bestie β€” you must own the tablespace to change its definition. want to alter the owner? you also have to be a direct or indirect member of the new owning role. (superusers get these privileges automatically, because of course they do πŸ‘‘ main character energy fr.)


πŸ’– PARAMETERS πŸ’–

  • name β€” the name of an existing tablespace. you know, the one you're about to mess with 🫢
  • new_name β€” the new name of the tablespace. 🚨 important: the new name cannot begin with pg_, because those names are reserved for system tablespaces. do not try it, she will not allow it πŸ™ˆ
  • new_owner β€” the new owner of the tablespace. hand over the keys, king πŸ‘‘
  • tablespace_option β€” a tablespace parameter to be set or reset. currently the only available parameters are:
    • seq_page_cost
    • random_page_cost
    • effective_io_concurrency
    • maintenance_io_concurrency

setting these values for a particular tablespace will override the planner's usual estimate of the cost of reading pages from tables in that tablespace, and the executor's prefetching behavior, as established by the configuration parameters of the same name. (peep seq_page_cost, random_page_cost, effective_io_concurrency, maintenance_io_concurrency for the full lore πŸ“š) this is genuinely useful if one tablespace lives on a disk that's faster or slower than the rest of the I/O subsystem β€” like, that one SSD carrying the whole team while the spinning rust does its thing πŸ’€


πŸ”₯ 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;

slay, mary. it's her tablespace now πŸ’…


🌈 COMPATIBILITY 🌈

there is no ALTER TABLESPACE statement in the SQL standard. so if anyone asks, this is Postgres being iconic and doing her own thing ✨


⭐ SEE ALSO ⭐

the holy trinity: make it, alter it, drop it πŸŽ€


and that's the whole page, bestie!! brought to you by the PostgreSQL 13.23 Documentation, dated 2025 β€” go forth and rename tablespaces responsibly πŸ§šβ€β™€οΈπŸ’œπŸ“

πŸ“¦ where this page comes from