postgres.rst
changeset 2436 41f79c1242b2
parent 2422 242e08fa2c73
child 2479 ab3f4aad1b37
equal deleted inserted replaced
2435:27921ee2c781 2436:41f79c1242b2
   463   select tbl.relname, toast.relname, toast.relpages
   463   select tbl.relname, toast.relname, toast.relpages
   464   from pg_class tbl, pg_class toast
   464   from pg_class tbl, pg_class toast
   465   where tbl.reltoastrelid = toast.oid
   465   where tbl.reltoastrelid = toast.oid
   466   order by toast.relpages desc;
   466   order by toast.relpages desc;
   467 
   467 
   468 Size of types::
       
   469 
       
   470   SELECT pg_column_size(5::smallint);
       
   471   SELECT pg_column_size(5::int);
       
   472   SELECT pg_column_size(5::bigint);
       
   473 
       
   474 Index size::
   468 Index size::
   475 
   469 
   476   SELECT pg_indexes_size('my_ix');
   470   SELECT pg_indexes_size('my_ix');
   477 
   471 
   478 Largest index::
   472 Largest index::
   486   join pg_index ix on ix.indexrelid = i.oid
   480   join pg_index ix on ix.indexrelid = i.oid
   487   join pg_class t on t.oid = ix.indrelid
   481   join pg_class t on t.oid = ix.indrelid
   488   where i.relkind = 'i'
   482   where i.relkind = 'i'
   489   order by pg_relation_size(i.oid) desc;
   483   order by pg_relation_size(i.oid) desc;
   490 
   484 
       
   485 Size of types::
       
   486 
       
   487   SELECT pg_column_size(5::smallint);
       
   488   SELECT pg_column_size(5::int);
       
   489   SELECT pg_column_size(5::bigint);
       
   490 
       
   491 Size of column::
       
   492 
       
   493   SELECT sum(pg_column_size(col)) FROM tbl;
       
   494 
       
   495 Total of all ``pg_column_size`` is less then ``pg_relation_size`` because table is using pages to
       
   496 store rows and we might have gaps inside pages.
       
   497 
   491 https://www.postgresql.org/docs/9.6/functions-admin.html
   498 https://www.postgresql.org/docs/9.6/functions-admin.html
   492   Database Object Management Functions.
   499   Database Object Management Functions.
   493 https://wiki.postgresql.org/wiki/Disk_Usage
   500 https://wiki.postgresql.org/wiki/Disk_Usage
   494   Finding the size of various object in your database.
   501   Finding the size of various object in your database.
   495 https://wiki.postgresql.org/wiki/Index_Maintenance
   502 https://wiki.postgresql.org/wiki/Index_Maintenance