728x90
728x170

파티션 테이블을 사용하는 방법입니다.

먼저 모테이블을 생성합니다.

create table test.test_partitioned
(
      dt timestamp  tz,
      message   text,
      code  int
)  partition by range(dt);

시간 기준으로 파티션이 설정되었습니다.

자식테이블을 생성합니다.

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

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

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

2023_01 , 2023_02 자식 파티션 테이블이 생성되었습니다.


자식 파티션 테이블을 생성하는 명령은 아래와 같습니다.

alter table test.test_partitioned attach partition test.test_2023_03 for values from ('2023-03-01') to ('2023-04-01')


자식 파티션 테이블을 삭제하는 명령은 아래와 같습니다.

alter table test.test_partitioned detach partition test.test_2023_02;


아래처럼 데이터를 insert 하게되면 해당 데이터는 시간 값에 범위에있는 파티션 테이블에 저장됩니다.

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

 

728x90
그리드형

'DB' 카테고리의 다른 글

[MySQL] MySql 설치하기 - Install MySql  (0) 2023.12.20
[Postgresql] Lock  (0) 2023.11.08
[DB/PostgreSQL] 병렬쿼리 (Parallel Query)  (0) 2023.10.16
[DB/PostgreSQL] 모니터링을 위한 쿼리문 모음  (0) 2023.10.16
[DB/PostgreSQL] Vacuum  (0) 2023.10.11
Posted by kjun
,