ads=#select pg_column_size(5::smallint);
pg_column_size
----------------
2
(1row)
ads=#select pg_column_size(5::int);
pg_column_size
----------------
4
(1row)
ads=#select pg_column_size(5::bigint);
pg_column_size
----------------
8
(1row)
ads=#select pg_column_size('This is a string'::varchar);
pg_column_size
----------------
20
(1row)
ads=#select length('This is a string'::varchar);
length
--------
16
(1row)
The 4 byte difference between the column size and the string length is the storage overhead needed for varchar columns.
The size for a tablespace can be found out with pg_tablespace_size(), but I don’t have a machine with configured tablespace at hand to show an example.