F.20. lo

lo 모듈은 대형 객체(흔이 LO 또는 BLOB이라고 한다)를 관리하기 위한 제반 기능을 제공한다. 이 모듈에는 lo 자료형과 lo_manage 트리거 함수가 포함되어있다.

F.20.1. 개발 배경

JDBC 드라이버(ODBC 드라이버도 같음)의 한가지 문제점은 BLOB(이진 대형 객체)을 사용할 때, 그와 관련된 테이블의 내용이 바뀌게 되면, 그 BLOB 자료를 삭제해 버리는 것을 규약으로 하고 있다는 것이다.

PostgreSQL 경우, 위와 같은 문제가 발생하지는 않는다. 대형 객체는 자기 스스로 독립 객체로 존재하며, 이 객체를 참조하는 테이블에서는 객체의 OID만 참조하는 방식이다. 즉, 이런 방식은 같은 대형 객체 OID에 대해서 여러 테이블이 함께 사용할 수 있어, 그것을 참조하는 한 로우가 삭제된다고 해도 그것과 관련된 대형 객체를 삭제하지 않는다.

이 모듈은 PostgreSQL JDBC 또는 ODBC 드라이버를 사용해서 응용프로그램을 쓸 때, 이런 대형 객체에 대해서 관련 자료가 변경되거나 삭제 될 경우 그에 맞는 작업을 트리거로 진행할 수 있도록 한다. 그래서 참조 관계를 잃은 디스크 공간만 차지하는 대형 객체가 없도록 한다.

The lo module allows fixing this by attaching a trigger to tables that contain LO reference columns. The trigger essentially just does a lo_unlink whenever you delete or modify a value referencing a large object. When you use this trigger, you are assuming that there is only one database reference to any large object that is referenced in a trigger-controlled column!

The module also provides a data type lo, which is really just a domain of the oid type. This is useful for differentiating database columns that hold large object references from those that are OIDs of other things. You don't have to use the lo type to use the trigger, but it may be convenient to use it to keep track of which columns in your database represent large objects that you are managing with the trigger. It is also rumored that the ODBC driver gets confused if you don't use lo for BLOB columns.

F.20.2. 사용법

사용법은 아래와 같다:

CREATE TABLE image (title TEXT, raster lo);

CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
    FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster);

For each column that will contain unique references to large objects, create a BEFORE UPDATE OR DELETE trigger, and give the column name as the sole trigger argument. You can also restrict the trigger to only execute on updates to the column by using BEFORE UPDATE OF column_name. If you need multiple lo columns in the same table, create a separate trigger for each one, remembering to give a different name to each trigger on the same table.

F.20.3. 한계

F.20.4. 만든이

Peter Mount