vacuumlo_repro.txt

text/plain

Filename: vacuumlo_repro.txt
Type: text/plain
Part: 0
Message: Vacuumlo improvements
vacuumlo removing user domain type
----------------------------------
-- 1. Setup: create a domain over oid and a table using it

CREATE DOMAIN my_lo AS oid;

CREATE TABLE documents (
    id serial PRIMARY KEY,
    name text,
    content my_lo  -- stores large object references
);

-- 2. Create a large object and store its OID

-- create a dummy file
echo "test" > test.txt

SELECT lo_create(0);          -- returns an OID, e.g. 12345
-- (use the returned OID below)

INSERT INTO documents (name, content) VALUES ('test.txt', 12345);

-- Verify the LO exists
SELECT oid FROM pg_largeobject_metadata;

-- 3. Run vacuumlo in dry-run mode to see the problem:
--    $ vacuumlo -n -v <dbname>
--
-- Expected: LO 12345 should NOT appear in the removal list
--           (it is referenced by documents.content)
-- Actual:   LO 12345 DOES appear as "would remove" because
--           vacuumlo does not scan the `my_lo` (domain) column

-- 4. If run without -n, the large object is deleted:
--    $ vacuumlo <dbname>
--
-- After this, the OID in documents.content is now a dangling reference:
SELECT lo_get(content) FROM documents WHERE name = 'test.txt';
-- ERROR: large object 12345 does not exist