what's the calculation with fillfactor in postgresql



  • create table big(id integer primary key generated always as identity, s char(1000)) with(fillfactor = 10);
    
     insert into big(s) values('foo');
     insert into big(s) values('foo');
     select ctid, id from big;
    

    return:

     ctid  | id
    -------+----
     (0,1) |  1
     (1,1) |  2
    (2 rows)
    

    I don't know how to do calculation with fillfactor, so that the above table will be structured as one record/row one page?

    -- return 2064,2
    SELECT sum(pg_column_size(t.*)) as filesize, count(*) as filerow FROM big as t; 
    --return 1004
    select pg_column_size(s) from big; --1004
    

    Only info i get from manual.

    fillfactor (integer)
    The fillfactor for a table is a percentage between 10 and 100. 100 (complete packing) is the default. When a smaller fillfactor is specified, INSERT operations pack table pages only to the indicated percentage; the remaining space on each page is reserved for updating rows on that page. This gives UPDATE a chance to place the updated copy of a row on the same page as the original, which is more efficient than placing it on a different page. For a table whose entries are never updated, complete packing is the best choice, but in heavily updated tables smaller fillfactors are appropriate. This parameter cannot be set for TOAST tables.

    Further reference: https://drive.google.com/file/d/1Bobgebpb07ctCM-Jk9XBxmY8k9CZkorn/view?usp=sharing Page: 190.



  • Looks like your rows are larger than 10% of one 8kB block, so they end up in different blocks. char(1000) is mean, because it is padded with blanks, and the size is to small to trigger TOAST compression.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2