5

I am an oracle dba and recently started learning postgres database administration. In one of our postgres databases, pg_largeobject table is of 30G and I want to reclaim disk space by unlinking and vacuuming the large objects which are not used by any tables in the database. For this, I would like to know the tables in the database which are using these large objects. Is there any query or procedure to achieve this?

Update: I tried using vacuumlo but it returned 0 objects to be removed. It means that the large objects are not orphaned but we don't have any table in the database which references majority of the objects in the pg_largeobject table. Then how come these objects are not orphaned?

3
  • I don't even know if there's a facility to do that, but there's no need -- standard table maintenance (vacuuming) will attend to both the core table and the TOAST objects attached to it, transparently. Commented May 15, 2019 at 16:40
  • What is the DDL for the pg_largeobject table? How many FK are there and how is the FK delete action defined? Commented May 15, 2019 at 17:39
  • @AntoanMilkov pg_largeobject is kind of postgres maintained system table for all large objects of that are in the database.It only has three columns: large object id of type oid, page no of type integer and data of type bytea. Commented May 15, 2019 at 19:06

1 Answer 1

5

Normally, applications should unlink the large objects that are no longer needed, but in the case they don't, PostgreSQL ships with an utility named vacuumlo that does exactly what you're asking for.

Description:

vacuumlo is a simple utility program that will remove any “orphaned” large objects from a PostgreSQL database. An orphaned large object (LO) is considered to be any LO whose OID does not appear in any oid or lo data column of the database.


If there's a single table with an oid pointing to large objects, the orphaned large objects can be found directly with this query (PostgreSQL 9.0 or newer):

select oid from pg_largeobject_metadata m where not exists
 (select 1 from name_of_table  where m.oid=name_of_oid_column);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I have used vacuumlo and it is showing 0 objects to be removed. With this I'm sure that these objects in pg_largeobject table are not orphaned. But we do have a small number of tables, so I went through the description of each and every table but I found only once column of type oid and it has relatively small number of rows. So in conclusion I don't have any table in the database that references majority of the large objects in the pg_largeobject table and yet they are not orphaned. Any ideas on how to proceed?
@RaviTejaAdabala: each large object has many entries in pg_largeobject because it holds one row per segment, not one row per object. Maybe that's what makes you overevaluate the number of large objects. See count(*) from pg_largeobject_metadata for the real number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.