CREATE_TABLESPACE(7)
๐ CREATE_TABLESPACE(7) ๐
okay bestie, sit down, we're learning CREATE TABLESPACE โ it's the PostgreSQL 18.6 Documentation version, so you know it's fresh. this is a 7-section manual page and we are reading all of it. no skimming. i will know. ๐
โจ NAME โจ
CREATE_TABLESPACE โ define a new tablespace ๐
๐ธ SYNOPSIS ๐ธ
CREATE TABLESPACE tablespace_name
[ OWNER { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
LOCATION 'directory'
[ WITH ( tablespace_option = value [, ... ] ) ]
look at her. iconic structure. square brackets mean optional, bestie, don't forget. ๐
๐ฆ DESCRIPTION ๐ฆ
so CREATE TABLESPACE registers a new cluster-wide tablespace. and the name you pick? it must be distinct from the name of any existing tablespace in the database cluster. no duplicates, no copycats, we don't do that here. ๐
a tablespace is basically letting superusers define an alternative location on the file system where the data files holding database objects (think tables, think indexes, think the whole crew) get to live. it's giving "i want my data over there actually." โจ
and if you're a user with appropriate privileges, you can pass tablespace_name to CREATE DATABASE, CREATE TABLE, CREATE INDEX or ADD CONSTRAINT and boom โ the data files for those objects get stored inside the tablespace you picked. chef's kiss. ๐
โ ๏ธ Warning โ ๏ธ a tablespace cannot be used independently of the cluster in which it is defined. like, it's not a standalone girlie. see Section 22.6. periodt.
๐ PARAMETERS ๐
tablespace_nameโ the name of the tablespace you're creating. it cannot begin withpg_, because those names are reserved for system tablespaces. that's a hard no, bestie. ๐ซuser_nameโ the name of the user who will own the tablespace. if you omit it, it defaults to the user executing the command. and here's the tea: only superusers can create tablespaces, but they can totally hand ownership of tablespaces over to non-superusers. sharing is caring. ๐ซถdirectoryโ the directory that'll be used for the tablespace. okay so listen carefully:- the directory must exist โ
CREATE TABLESPACEwill not create it for you, she is not your assistant ๐ - it should be empty
- it must be owned by the PostgreSQL system user
- and it must be specified by an absolute path name
- the directory must exist โ
tablespace_optionโ a tablespace parameter to be set or reset. currently the only available parameters areseq_page_cost,random_page_cost,effective_io_concurrencyandmaintenance_io_concurrency. setting these values for a particular tablespace overrides the planner's usual estimate of the cost of reading pages from tables in that tablespace, plus how many concurrent I/Os are issued โ the usual behaviour comes from the configuration parameters of the same name (seeseq_page_cost,random_page_cost,effective_io_concurrency,maintenance_io_concurrency). this is lowkey useful when one tablespace sits on a disk that's faster or slower than the rest of the I/O subsystem. main character disk energy. ๐ซ
๐ NOTES ๐
CREATE TABLESPACE cannot be executed inside a transaction block. that's the rule. don't try it. ๐
๐ EXAMPLES ๐
okay so you wanna create a tablespace called dbspace at file system location /data/dbs? first, make the directory using operating system facilities and set the correct ownership:
mkdir /data/dbs
chown postgres:postgres /data/dbs
then issue the tablespace creation command inside PostgreSQL:
CREATE TABLESPACE dbspace LOCATION '/data/dbs';
and if you want a tablespace owned by a different database user, use a command like this:
CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
slay. look at you go. ๐
โญ COMPATIBILITY โญ
CREATE TABLESPACE is a PostgreSQL extension. she's homegrown, she's original, she's ours. ๐
๐ง SEE ALSO ๐ง
CREATE DATABASE(CREATE_DATABASE(7))CREATE TABLE(CREATE_TABLE(7))CREATE INDEX(CREATE_INDEX(7))DROP TABLESPACE(DROP_TABLESPACE(7))ALTER TABLESPACE(ALTER_TABLESPACE(7))
and that's the whole page bestie!! ๐ this was PostgreSQL 18.6, dated 2026, and yes the footer literally says CREATE TABLESPACE(7) again because the manpage said so and we respect the manpage. go forth and tablespace responsibly, i love you, bye!! ๐ธ๐
โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms