title: Physical size of int2, int4, int8 in PostgreSQL
body: <p>I am not understand differents between storage size of INTs (all this types has fixed size)</p>
  
  <p>In official manual I see this description:</p>
  
  <blockquote>
    <p>The types smallint, integer, and bigint store whole numbers, that is,
    numbers without fractional components, of various ranges. Attempts to
    store values outside of the allowed range will result in an error.</p>
    
    <p>The type integer is the common choice, as it offers the best balance
    between range, storage size, and performance. The smallint type is
    generally only used if disk space is at a premium. The bigint type is
    designed to be used when the range of the integer type is
    insufficient.</p>
    
    <p>SQL only specifies the integer types integer (or int), smallint, and
    bigint. The type names int2, int4, and int8 are extensions, which are
    also used by some other SQL database systems.</p>
  </blockquote>
  
  <p>However simple test shows that change type of column do not change table size</p>
  
  <pre><code>create table test_big_table_int (
    f_int integer
  );
  
  INSERT INTO test_big_table_int (f_int )
      SELECT ceil(random() * 1000)
          FROM generate_series(1,1000000);
  
  
   SELECT
     pg_size_pretty(pg_total_relation_size(relid)) As "Size_of_table"
   FROM pg_catalog.pg_statio_user_tables 
   where relname = 'test_big_table_int';
   --"35 MB";
  
  
   alter table test_big_table_int ALTER COLUMN f_int TYPE bigint;
  
  
   SELECT
     pg_size_pretty(pg_total_relation_size(relid)) As "Size_of_table"
   FROM pg_catalog.pg_statio_user_tables 
   where relname = 'test_big_table_int';
  --"35 MB";
  
    alter table test_big_table_int ALTER COLUMN f_int TYPE smallint;
  
  
   SELECT
     pg_size_pretty(pg_total_relation_size(relid)) As "Size_of_table"
   FROM pg_catalog.pg_statio_user_tables 
   where relname = 'test_big_table_int';
   --"35 MB";"0 bytes"
  </code></pre>
  
  <p>Everytime I get  size of my table - 35MB. So where the profit to use integer or smallint  insthead int8? </p>
  
  <p>And second question - why postgee is doing rewrite tuple while change type of int  (int2&lt;->int4&lt;->int8)?</p>