RDB/PostreSQL

PostgreSQL 파티션

세모데 2020. 3. 23. 01:15

10버전 이후부터 trigger 방식이 아닌 parent 및 child 형태로 사용 가능  ( trigger 사용가능)

1) 파티션 parent 생성

create table test.test_partitioned

(

      dt timestamp  tz,

      message   text,

      code  int

)  partition by range(dt);

2) child 테이블 생성

create table test.test_2019_01 partition of test.test_partitioned for values from ('2019-01-01') to ('2019-02-01');

create table test.test_2019_02 partition of test.test_partitioned for values from ('2019-02-01') to ('2019-03-01');

create table test.test_default partition of test.test_partitioned default;

#파티션 삭제

alter table test.test_partitioned detach partition test.test_2019_02;

#파티션 추가

alter table test.test_partitioned attach partition test.test_2019_02 for values from ('2019-02-01') to ('2019-03-01')

 

3) 데이터 insert

insert into test.test_partitioned values ('2019-01-10', 'message...', 10);