1

hi i'm trying to find the size of all blobs. I always used this

SELECT sum(pg_column_size(pg_largeobject)) lob_size FROM pg_largeobject

but while my database is growing ~40GB this takes several hours and loads the cpu too much.

is there any more efficent way?

4
  • Isn't pg_table_size('pg_largeobject') good enough? Commented May 8, 2014 at 17:39
  • seems good, but why do they give different results? SELECT pg_table_size('pg_largeobject'), sum(pg_column_size(pg_largeobject)) lob_size FROM pg_largeobject 750MB/545MB Commented May 9, 2014 at 7:43
  • pg_table_size includes the padding between rows, the dead rows, row headers... that's the real size on disk. Commented May 9, 2014 at 8:53
  • ok, then pleas write this as answer so i can accept it Commented May 9, 2014 at 9:07

1 Answer 1

2

Some of the functions mentioned in Database Object Management Functions give an immediate result for the entire table.

I'd suggest pg_table_size(regclass) which is defined as:

Disk space used by the specified table, excluding indexes (but including TOAST, free space map, and visibility map)

It differs from sum(pg_column_size(tablename)) FROM tablename because it counts entire pages, so that includes the padding between the rows, the dead rows (updated or deleted and not reused), and the row headers.

Sign up to request clarification or add additional context in comments.

Comments

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.