Tablespaces
The main unit of storage for a PostgreSQL database is the tablespace. Tablespaces are described accurately by their name: they're a space to put tables (and indexes) in. The idea is that every logical disk you want to use for a distinct purpose gets assigned a tablespace name, and then when you create a table you refer that tablespace to put it there:
$ mkdir /disk/pgdata $ psql postgres=# CREATE TABLESPACE disk LOCATION '/disk/pgdata'; postgres=# CREATE TABLE t(i int) TABLESPACE disk;
Tablespaces are also implemented inside the database using symbolic links, and your OS needs to support them (or an equivalent like the NTFS junction) for this to work. Databases and tables are by default created in a virtual tablespace named pg_default
. You can change that by setting the default_tablespace
parameter in the server configuration. It's also possible to relocate an entire database by setting the TABLESPACE
parameter when running CREATE DATABASE
.