attach_tablespace()
Attach a tablespace to a hypertable
Attach a tablespace to a hypertable and use it to store chunks. A tablespace is a directory on the filesystem that allows control over where individual tables and indexes are stored on the filesystem. A common use case is to create a tablespace for a particular storage disk, allowing tables to be stored there. To learn more, see the PostgreSQL documentation on tablespaces.
TimescaleDB can manage a set of tablespaces for each hypertable, automatically spreading chunks across the set of tablespaces attached to a hypertable. If a hypertable is hash partitioned, TimescaleDB tries to place chunks that belong to the same partition in the same tablespace. Changing the set of tablespaces attached to a hypertable may also change the placement behavior. A hypertable with no attached tablespaces has its chunks placed in the database’s default tablespace.
Samples
Section titled “Samples”Attach the tablespace disk1 to the hypertable conditions:
SELECT attach_tablespace('disk1', 'conditions');SELECT attach_tablespace('disk2', 'conditions', if_not_attached => true);Arguments
Section titled “Arguments”The syntax is:
SELECT attach_tablespace( tablespace = '<tablespace_name>', hypertable = '<hypertable_name>', if_not_attached = true | false);| Name | Type | Default | Required | Description |
|---|---|---|---|---|
tablespace | TEXT | - | ✔ | Name of the tablespace to attach. |
hypertable | REGCLASS | - | ✔ | Hypertable to attach the tablespace to. |
if_not_attached | BOOLEAN | false | ✖ | Set to true to avoid throwing an error if the tablespace is already attached to the table. A notice is issued instead. Defaults to false. |
Tablespaces need to be created before
being attached to a hypertable. Once created, tablespaces can be
attached to multiple hypertables simultaneously to share the
underlying disk storage. Associating a regular table with a tablespace
using the TABLESPACE option to CREATE TABLE, prior to calling
create_hypertable, has the same effect as calling
attach_tablespace immediately following create_hypertable.
Returns
Section titled “Returns”This function returns void.