テーブルスペースとは
構文
作成
CREATE TABLESPACE テーブルスペース名 [OWNER {所有者名 | CURRENT_USER | SESSION_USER}] LOCATION 'テーブルスペース(ディレクトリ)' [WITH (テーブルスペースオプション=value [, ...])]
テーブルスペースの定義変更
テーブルスペースの所有者のみが実行できる
テーブルスペース名称変更
ALTER TABLESPACE テーブルスペース名 RENAME TO 新しいテーブルスペース名;
テーブルスペースの所有者を変更
ALTER TABLESPACE テーブルスペース名 OWNER TO {新しい所有者名 | CURRENT_USER | SESSION_USER};
テーブルスペースの削除
DROP TABLESPACE [IF EXISTS] テーブルスペース
テーブルスペースを使う
テーブルスペースを作成
新規テーブルスペース作成先を作成する
mkdir /var/lib/pgsql/11/data_test
現在のテーブルスペースを確認する
postgres=# SELECT * FROM pg_tablespace;
spcname | spcowner | spcacl | spcoptions
------------+----------+--------+------------
pg_default | 10 | |
pg_global | 10 | |
(2 行)
テーブルスペースを作成する
postgres=# CREATE TABLESPACE test_space OWNER postgres LOCATION '/var/lib/pgsql/11/data_test';
CREATE TABLESPACE
作成したテーブルスペースを確認
postgres=# SELECT * FROM pg_tablespace;
spcname | spcowner | spcacl | spcoptions
------------+----------+--------+------------
pg_default | 10 | |
pg_global | 10 | |
test_space | 10 | |
(3 行)
テーブルスペース名を変更する
現在のテーブルスペースを確認
postgres=# SELECT * FROM pg_tablespace;
spcname | spcowner | spcacl | spcoptions
------------+----------+--------+------------
pg_default | 10 | |
pg_global | 10 | |
test_space | 10 | |
(3 行)
テーブルスペース名の変更
postgres=# ALTER TABLESPACE test_space RENAME TO space;
ALTER TABLESPACE
テーブルスペース名変更を確認
postgres=# SELECT * FROM pg_tablespace;
spcname | spcowner | spcacl | spcoptions
------------+----------+--------+------------
pg_default | 10 | |
pg_global | 10 | |
space | 10 | |
(3 行)
テーブルスペースを削除する
テーブルスペースを確認
postgres=# SELECT * FROM pg_tablespace;
spcname | spcowner | spcacl | spcoptions
------------+----------+--------+------------
pg_default | 10 | |
pg_global | 10 | |
space | 10 | |
(3 行)
削除する
postgres=# DROP TABLESPACE space;
DROP TABLESPACE
削除されたテーブルスペースを確認
postgres=# SELECT * FROM pg_tablespace;
spcname | spcowner | spcacl | spcoptions
------------+----------+--------+------------
pg_default | 10 | |
pg_global | 10 | |
(2 行)