1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【PostgreSQL】テーブルスペースを触ってみた

Posted at

テーブルスペースとは

PostgreSQL 11.5

構文

作成

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 )
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?