PostgreSQL Tablespace 생성

Tablespace

데이터베이스에서 Tablespace는 오라클과 PostgreSQL에서만 존재하는 개념입니다.

테이블스페이스가 존재 함으로 각 schema의 오브젝트 관리가 용이해지며, 데이터파일 관리 및 용량 관리에 있어서, 또는 성능 관리에 있어서 효과적인 관리가 가능해 집니다.

 

테이블 스페이스 확인

postgres=# select * from pg_tablespace;
  spcname   | spcowner | spcacl | spcoptions 
------------+----------+--------+------------
 pg_default |       10 |        | 
 pg_global  |       10 |        | 
(2 rows)
postgres=# \db
       List of tablespaces
    Name    |  Owner   | Location 
------------+----------+----------
 pg_default | postgres | 
 pg_global  | postgres | 
(2 rows)
postgres=# \db+
                                  List of tablespaces
    Name    |  Owner   | Location | Access privileges | Options |  Size  | Description 
------------+----------+----------+-------------------+---------+--------+-------------
 pg_default | postgres |          |                   |         | 29 MB  | 
 pg_global  | postgres |          |                   |         | 497 kB | 
(2 rows)

특별히 유저나 스키마에 테이블 스페이스를 지정하지 않고 pg_default 테이블스페이스를 이용 할 수 있습니다.
해당 디렉토리는 postgres의 권한을 가지고 있어야 합니다.

 

테이블스페이스 생성

Synopsis :
CREATE TABLESPACE tablespace_name
[ OWNER { new_owner | CURRENT_USER | SESSION_USER } ]
LOCATION ’directory’
[ WITH ( tablespace_option = value [, … ] ) ]

생성 예제

postgres@pgsqldb:~]$ psql -d postgres -U postgres
psql (9.6.11)
Type "help" for help.
postgres=# CREATE TABLESPACE mydb01 LOCATION '/postgresql/tbs';
CREATE TABLESPACE
postgres=#

 

Tablespace 조회

postgres=# \db
           List of tablespaces
    Name    |  Owner   |    Location     
------------+----------+-----------------
 mydb01     | postgres | /postgresql/tbs
 pg_default | postgres | 
 pg_global  | postgres | 
(3 rows)
postgres=# select * from pg_tablespace;
  spcname   | spcowner | spcacl | spcoptions 
------------+----------+--------+------------
 pg_default |       10 |        | 
 pg_global  |       10 |        | 
 mydb01     |       10 |        | 
(3 rows)
postgres=# \q
postgres@pgsqldb:~]$ ls -l /postgresql/tbs/
total 0
drwx------ 2 postgres postgres 6 Dec 27 14:03 PG_9.6_201608131
postgres@pgsqldb:~]ls−l
PGDATA/pg_tblspc
total 0
lrwxrwxrwx 1 postgres postgres 15 Dec 27 14:03 16392 -> /postgresql/tbs
postgres@pgsqldb:~]$

tablespace owner를 지정해서 생성 할 수도 있습니다.

경로를 지정하여 테이블스페이스를 생성하면, $PGDATA/pg_tblspc 밑에 OID로 심볼릭 링크가 생성됩니다.

실제 파일은 경로에 있고, 클러스터 홈 밑에 pg_tblspc에 링크가 생성되어 DB에 정보를 전달하는것 입니다.

Tablesapce 이름 변경

postgres=# ALTER TABLESPACE mydb RENAME TO mydb01;

Tablespace Owner 변경

postgres=# ALTER TABLESPACE mydb01 OWNER TO POSTGRES;

 

소셜 미디어로 공유하기

You may also like...

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.

 

새 블로그로 이사갑니다.

 

rastalion.dev

 

도메인 변경했어요. 현재 지속적으로 개선 중입니다.

 

This will close in 10 seconds