Size of columns.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Mon, 12 Oct 2020 13:17:14 +0300
changeset 2436 41f79c1242b2
parent 2435 27921ee2c781
child 2437 d5f98b5fdcb8
Size of columns.
postgres.rst
--- a/postgres.rst	Mon Oct 12 01:08:41 2020 +0300
+++ b/postgres.rst	Mon Oct 12 13:17:14 2020 +0300
@@ -465,12 +465,6 @@
   where tbl.reltoastrelid = toast.oid
   order by toast.relpages desc;
 
-Size of types::
-
-  SELECT pg_column_size(5::smallint);
-  SELECT pg_column_size(5::int);
-  SELECT pg_column_size(5::bigint);
-
 Index size::
 
   SELECT pg_indexes_size('my_ix');
@@ -488,6 +482,19 @@
   where i.relkind = 'i'
   order by pg_relation_size(i.oid) desc;
 
+Size of types::
+
+  SELECT pg_column_size(5::smallint);
+  SELECT pg_column_size(5::int);
+  SELECT pg_column_size(5::bigint);
+
+Size of column::
+
+  SELECT sum(pg_column_size(col)) FROM tbl;
+
+Total of all ``pg_column_size`` is less then ``pg_relation_size`` because table is using pages to
+store rows and we might have gaps inside pages.
+
 https://www.postgresql.org/docs/9.6/functions-admin.html
   Database Object Management Functions.
 https://wiki.postgresql.org/wiki/Disk_Usage