CREATE TABLESPACE registers a new cluster-wide tablespace.
PolarDB for Oracle does not support user-defined tablespaces. Neither privileged accounts nor standard accounts are permitted to create tablespaces. You can run CREATE TABLESPACE and reference a tablespace by name in CREATE DATABASE, CREATE TABLE, CREATE INDEX, and ADD CONSTRAINT, but objects are always stored in the pg_default tablespace. A NOTICE message is returned when you specify a tablespace for an object.
Prerequisites
Before you begin, ensure that you have:
The
polar_superuserrole
Synopsis
CREATE TABLESPACE tablespace_name
[ OWNER { new_owner | CURRENT_USER | SESSION_USER } ]
LOCATION 'directory'
[ WITH ( tablespace_option = value [, ... ] ) ]Parameters
| Parameter | Description |
|---|---|
tablespace_name | Name of the tablespace. Cannot start with pg_. |
OWNER | Owner of the tablespace. Defaults to the user running the statement. Only polar_superuser can run this statement. |
directory | Absolute path to an existing, empty directory for the tablespace. The directory must be owned by the PolarDB system user. CREATE TABLESPACE does not create the directory. |
tablespace_option | One or more tablespace-level cost parameters. Accepted values: seq_page_cost, random_page_cost, effective_io_concurrency, maintenance_io_concurrency. These override the query planner's default cost estimates and prefetch behavior for this tablespace, useful when the tablespace resides on a disk with different I/O characteristics from the rest of the system. |
Usage notes
CREATE TABLESPACEcannot run inside a transaction block.Tablespaces are only supported on systems that support symbolic links.
A tablespace cannot be used independently of the cluster in which it is defined.
A privileged account can specify a tablespace when creating objects, but objects are stored in
pg_defaultand aNOTICEmessage is returned. Standard accounts cannot specify a tablespace at all.
Examples
The following steps create a tablespace, verify it in the system catalog, and show the behavior when assigning it to a table.
Create a tablespace:
CREATE TABLESPACE test_tablespace LOCATION '/';Verify that the tablespace appears in the
pg_tablespacesystem catalog:SELECT spcname FROM pg_tablespace;Expected output:
spcname ----------------- pg_default pg_global test_tablespaceCreate a table and assign it to the tablespace:
CREATE TABLE test_table(a int) TABLESPACE test_tablespace;Expected output:
NOTICE: User defined tablespace is not supported, The tablespace set by the user will be ignored CREATE TABLEThe table is created successfully, but is stored in
pg_default, nottest_tablespace.