설문조사
PostgreSQL/PPAS 관련 듣고 싶은 교육은


총 게시물 94건, 최근 0 건
   

UNLOGGED TABLE

글쓴이 : PostgresDBA 날짜 : 2013-02-14 (목) 18:54 조회 : 7749
오라클처럼 PostgreSQL 도 아카이브 모드에서 대량의 데이터를 insert 하면 
아카이브 화일이 많이 생기면서 insert 속도가 저하 됩니다.

그래서 아카이브 화일을 생성시키지 않으면서 대량의 데이터를 빠르게 insert 하고자 한다면
PostgreSQL 9.1 에서 도입된 unlogged 속성의 테이블을 생성하면 됩니다.
(오라클의 nologging 옵션하고 비슷합니다만 큰 차이가 있습니다.)

하지만 굉장히 조심히 사용하셔야 합니다. 중요한 테이블 생성시에는 이 속성을 사용하시면 절대 안됩니다. 아카이브 화일이 없으므로, 그 테이블에 대해서는 데이터 복구가 불가능합니다.
(이부분은 오라클의 nologging 테이블 이나 PostgreSQL 의 unlogged 테이블 이나 공통된 사항입니다.)

하지만 PostgreSQL 의 unlogged 는 위험한 속성을 하나 더 가지고 있습니다.


scott@[local]:5432:scottdb] 
SQL> create unlogged table test_unlogged (x int);
CREATE TABLE
scott@[local]:5432:scottdb] 
SQL> insert into test_unlogged values(100);  -- 100 이란 데이터가 들어가 있습니다.
INSERT 0 1
scott@[local]:5432:scottdb] 

* 참고
PostgreSQL 의 shutdown 방식에 대해서는
요기를 참고하세요.

 -- PostgreSQL 서버를 정상적으로 RESTART 한후에 테이블을 조회합니다.
[postgres@pg-00:/var/lib/pgsql]$ pg_ctl -D  /var/lib/pgsql/9.2/data -m smart stop
waiting for server to shut down.... done
server stopped
[postgres@pg-00:/var/lib/pgsql]$ su - 
Password: 
[root@pg-00:/root]#/etc/rc.d/init.d/postgresql-9.2 start
Starting postgresql-9.2 service: [  OK  ]
[root@pg-00:/root]#exit
logout
[postgres@pg-00:/var/lib/pgsql]$ scott  ## scott 계정으로 로그인 alias 입니다^^
Null display is "NULL".
Timing is off.
Pager usage is off.
psql (9.2.2)
Type "help" for help.

scott@[local]:5432:scottdb] 
SQL> select * from test_unlogged;  ## 데이터가 여전히 보입니다.
  x  
-----
 100
(1 row)

scott@[local]:5432:scottdb] 
SQL> 

 -- PostgreSQL 서버를 비정상적으로 종료후 재기동한후에, 테이블을 조회합니다.
[postgres@pg-00:/var/lib/pgsql]$ pg_ctl -D  /var/lib/pgsql/9.2/data -m immediate stop
waiting for server to shut down... done
server stopped

[root@pg-00:/root]#/etc/rc.d/init.d/postgresql-9.2 start
Starting postgresql-9.2 service: [  OK  ]

[postgres@pg-00:/var/lib/pgsql]$ scott
scott@[local]:5432:scottdb] 
SQL> select * from test_unlogged;  ## 어라! 데이터가 모두 사라졌습니다.
 x 
---
(0 rows)

scott@[local]:5432:scottdb] 
SQL> 

이상에서 보듯이 UNLOGGED 테이블의 데이터는 서버 전원이 나가거나 해서
PostgreSQL 이 비정상적으로 죽었다 살아난 경우, 데이터가 사라집니다.
(오라클의 NOLOGGING 테이블 경우에는  데이터가 사라지지는 않습니다.)

주의해서 사용하세요!!

   

postgresdba.com