Defines a new tablespace.
CREATE TABLESPACE tablespace_name [OWNER username] LOCATION '/path/to/dir' [WITH (contentID_1='/path/to/dir1'[, contentID_2='/path/to/dir2' ... ])]
CREATE TABLESPACE registers and configures a new tablespace for your Greenplum Database system. The tablespace name must be distinct from the name of any existing tablespace in the system. A tablespace is a Greenplum Database system object (a global object), you can use a tablespace from any database if you have appropriate privileges.
A tablespace allows superusers to define an alternative host file system location where the data files containing database objects (such as tables and indexes) reside.
In Greenplum Database, the file system location must exist on all hosts including the hosts running the master, standby mirror, each primary segment, and each mirror segment.
- The name of a tablespace to be created. The name cannot begin with pg_ or gp_, as such names are reserved for system tablespaces.
- OWNER username
- The name of the user who will own the tablespace. If omitted, defaults to the user executing the command. Only superusers can create tablespaces, but they can assign ownership of tablespaces to non-superusers.
- LOCATION '/path/to/dir'
- The absolute path to the directory (host system file location) that will be the root directory for the tablespace. When registering a tablepace, the directory should be empty and must be owned by the Greenplum Database system user. The directory must be specified by an absolute path name.
- For each segment instance, you can specify a different directory for the tablespace in the WITH clause.
- The value ID_i is the content ID for the segment instance. /path/to/dir_i is the absolute path to the host system file location that the segment instance uses as the root directory for the tablespace. You cannot specify the content ID of the master instance (-1). You can specify the same directory for multiple segments.
- If a segment instance is not listed in the WITH clause, Greenplum Database uses the directory specified in the LOCATION clause.
- When registering a tablepace, the directories should be empty and must be owned by the Greenplum Database system user.
Tablespaces are only supported on systems that support symbolic links.
CREATE TABLESPACE cannot be executed inside a transaction block.
When creating tablespaces, ensure that file system locations have sufficient I/O speed and available disk space.
CREATE TABLESPACE creates symbolic links from the pg_tblspc directory in the master and segment instance data directory to the directories specified in the command.
SELECT oid, spcname, spcowner FROM pg_tablespace ;
SELECT * FROM gp_tablespace_location(16385)
Create a new tablespace and specify the file system location for the master and all segment instances:
CREATE TABLESPACE mytblspace LOCATION '/gpdbtspc/mytestspace' ;
Create a new tablespace and specify a location for segment instances with content ID 0 and 1. For the master and segment instances not listed in the WITH clause, the file system location for the tablespace is specified in the LOCATION clause.
CREATE TABLESPACE mytblspace LOCATION '/gpdbtspc/mytestspace' WITH (content0='/temp/mytest', content1='/temp/mytest');
The example specifies the same location for the two segment instances. You can a specify different location for each segment.
CREATE TABLESPACE is a Greenplum Database extension.