CREATE TABLESPACE
CREATE TABLESPACE — define a new tablespace
Synopsis
For global tablespaces only: CREATE TABLESPACEtablespace_name
[ OWNER {new_owner
| CURRENT_ROLE | CURRENT_USER | SESSION_USER } ] LOCATION 'template
' [ WITH (global = true
[tablespace_option
=value
[, ... ] ) ]
Description
Note that Postgres Pro Shardman only supports global tablspaces.
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.
Warning
A tablespace cannot be used independently of the cluster in which it is defined; see Section 22.7.
Parameters
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_name
The 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 system user. The directory must be specified by an absolute path name.global = true
Specifies 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
andcompression
. 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 section Chapter 32.
Notes
CREATE TABLESPACE
cannot be executed inside a transaction block.
Examples
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);
Compatibility
CREATE TABLESPACE
is a Postgres Pro extension.