CREATE TABLESPACE — define a new tablespace
For global tablespaces only: CREATE TABLESPACEtablespace_name[ OWNER {new_owner| CURRENT_ROLE | CURRENT_USER | SESSION_USER } ] LOCATION 'template' [ WITH (global = true[tablespace_option=value[, ... ] ) ]
Note that Postgres Pro Shardman only supports global tablspaces.
For sharded systems, when creating a tablespace use {rgid}
under location and a keyword with (global).
Postgres Pro Shardman extension of the CREATE TABLESPACE
syntax enables creation of a new cluster-wide tablespace. All tablespaces in a
Postgres Pro Shardman cluster must be cluster-wide. The cluster-wide tablespace is
created on each cluster node with the location derived from the
template parameter.
A tablespace allows database administrators to define an alternative location
on the file system where the data files containing database objects (such as
tables and indexes) can reside. Only superusers and users with the privileges
of the pg_create_tablespace
role can create tablespaces, but they can assign ownership of tablespaces to
non-superusers.
A user with appropriate privileges can pass
tablespace_name to
CREATE DATABASE, CREATE TABLE,
CREATE INDEX or ADD CONSTRAINT to have the data
files for these objects stored within the specified tablespace.
A tablespace cannot be used independently of the cluster in which it is defined; see Section 21.7.
tablespace_name
The name of a tablespace to be created. The name cannot
begin with pg_, as such names
are reserved for system tablespaces.
user_nameThe name of the user who will own the tablespace. If omitted, defaults to the user executing the command.
directory
The directory that will be used for the tablespace. The directory
must exist (CREATE TABLESPACE will not create it),
should be empty, and must be owned by the
Postgres Pro Shardman system user. The directory must be
specified by an absolute path name.
global = trueSpecifies that the created tablespace must be global.
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, compression,
and encryption.
Setting cost value 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 (see seq_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. Compression is discussed in the Compressed File System (CFS) section.
CREATE TABLESPACE cannot be executed inside a transaction
block.
To create a tablespace dbspace under the file system location
/data/dbs, first create the directory using operating system facilities on all
nodes and set the correct ownership (or ensure that postgres user has permissions to
create it):
mkdir /data/dbs chown postgres:postgres /data/dbs
Then issue the tablespace creation command
CREATE TABLESPACE dbspace LOCATION '/data/dbs/ts-{rgid}' WITH (global = true);
To create a tablespace owned by a different database user, use a command like this:
CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';
CREATE TABLESPACE is a Postgres Pro Shardman
extension.