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


총 게시물 73건, 최근 0 건
   

AUTOVACUUM

글쓴이 : PostgresDBA 날짜 : 2012-12-31 (월) 09:25 조회 : 9326
PostgreSQL 9.0 부터 Autovacuum 이 디폴트로 활성화되어 있습니다.
즉, 이전버전에는 VACUUM 을 매뉴얼하게 수행해주어야 했는데, 9.0 부터는 자동화 할수 있다는 얘깁니다.

PostgreSQL 사용자라면 vacuum 에 대해 알고 계실겁니다.
vaccum 은 간단히 말하자면, 테이블들에 대한 가버지(garbage)를 청소하는 행위라고 보시면 됩니다. 
가령 update 시에, PostgreSQL 에서는, 기존 로우는 삭제 flag 를 박아넣고, 새 로우를 insert 하는 행위를 하게 됩니다. (내부적으로 PostgreSQL 에서의 update 는 일종의 insert 입니다. 그래서 update 가 빠릅니다.) 이때 삭제 flag 가 표시된 공간이 재 사용되기 위해서는 반드시 vacuum 에 의해서 정리가 되어야 합니다. (vacuum 개념은,  타 데이터베이스 DBA 기준으로 볼때, PostgreSQL 을 사용하게 될때 덤(?) 으로 신경써주어야 하는 매우 귀찮은 행위(?) 입니다.)

아래와 같이 확인할수 있습니다.

postgres@[local]:5432:postgres] 
SQL> show autovacuum;
 autovacuum 
------------
 on
(1 row)

postgres@[local]:5432:postgres] 
SQL> show track_counts;
 track_counts 
--------------
 on
(1 row)

참고로, VACUUM 수행시, INSERT/UPDATE/DELETE 는 허용하지만, ALTER TABLE 이나 CREATE INDEX 같은 DDL 문은 허용하지 않습니다.
단, VACUUM FULL 경우에는 빈공간을 삭제후 테이블을 SHRINK 하는 행위가 동반되고, 관련 인덱스까지 리빌드 하기 때문에, 그 테이블에 SELECT/INSERT/UPDATE/DELETE 등이 허용되지 않습니다.

참고로 특정테이블을 AUTOVACUUM 의 대상에서 빼기 위해서는 아래와 같이 해주면 됩니다.

SQL> create table test(x int);
CREATE TABLE
scott@[local]:5432:scottdb] 
SQL> alter table test set (autovacuum_enabled=off);
ALTER TABLE
scott@[local]:5432:scottdb] 
SQL> \d+ test;
                         Table "public.test"
 Column |  Type   | Modifiers | Storage | Stats target | Description 
--------+---------+-----------+---------+--------------+-------------
 x      | integer |           | plain   |              | 
Has OIDs: no
Options: autovacuum_enabled=off

scott@[local]:5432:scottdb] 
SQL> select relowner, relname, reloptions from pg_catalog.pg_class where relname='test';
 relowner | relname |       reloptions        
----------+---------+-------------------------
    16544 | test    | {autovacuum_enabled=off}
(1 row)

AUTOVACCUM 은 백그라운드 프로세스들에 의해 수행되며, 이때 최대로 동시에 수행되는 백그라운드 프로세스의 갯수는 아래 패러미터에 의해 좌우됩니다.

scott@[local]:5432:scottdb]
SQL> show  autovacuum_max_workers;
 autovacuum_max_workers 
------------------------
 3
(1 row)

AUTOVACUUM 에 대해 간단히 알아봤습니다.

이제 2012년도 저물어 가는군요.

PostgresDBA 2015-11-25 (수) 10:04
vacuum (verbose, analyze) xxx;
vacuum (verbose, full) xxx;

SQL> vacuum (verbose,analyze) x;
INFO:  vacuuming "mig.x"
INFO:  "x": removed 20971520 row versions in 92795 pages
INFO:  "x": found 20971520 removable, 20971520 nonremovable row versions in 185589 out of 185589 pages
DETAIL:  0 dead row versions cannot be removed yet.
There were 74 unused item pointers.
0 pages are entirely empty.
CPU 0.56s/4.02u sec elapsed 6.18 sec.
INFO:  analyzing "mig.x"
INFO:  "x": scanned 30000 of 185589 pages, containing 3397910 live rows and 0 dead rows; 30000 rows in sample, 20979436 estimated total rows
VACUUM

SQL> vacuum (verbose,full) x;
INFO:  vacuuming "mig.x"
INFO:  "x": found 0 removable, 20971520 nonremovable row versions in 185589 pages
DETAIL:  0 dead row versions cannot be removed yet.
CPU 1.84s/7.04u sec elapsed 10.79 sec.
VACUUM
댓글주소
   

postgresdba.com