database design - How many records can I store in 5 MB of PostgreSQL on Heroku? -


i'm going store records in single table 2 fields:

  • id -> 4 characters

  • password_hash -> 64 characters

how many records 1 above able store in 5mb postgresql on heroku?

p.s.: given single table x columns , length of y - how can calculate space take in database?

disk space occupied

calculating space on disk not trivial. have take account:

  • the overhead per table (small, entries in system catalog, may not affect on heroku).

  • the overhead per row (heaptupleheader) , per data page (pageheaderdata). details page layout in manual.

  • space lost data type alignment.

  • space null bitmap. free tables of 8 columns or less, irrelevant case.

  • dead rows after update / delete.

  • size of index(es). you'll have primary key, right? index size similar of table indexed columns , less overhead.

  • the actual space requirement of data, depending on respective data types. details character types (incl. fixed length types) in manual:

    the storage requirement short string (up 126 bytes) 1 byte plus actual string, includes space padding in case of character. longer strings have 4 bytes of overhead instead of 1

    more details types in system catalog pg_type.

  • the database encoding in particular character types. utf-8 uses 4 bytes store 1 character (but 7-bit-ascii characters occupy 1 byte, in utf-8.)

  • other small things may affect case, toast - should not affect 64 character strings.

calculate test case

a simple method find estimate create test table, fill dummy data , measure database object size functions::

select pg_size_pretty(pg_relation_size('tbl')); 

including indexes:

select pg_size_pretty(pg_total_relation_size('tbl')); 

a quick test shows following results:

create table test(a text, b text); insert test -- quick fake of matching rows select chr((g/1000 +32)) || to_char(g%1000, 'fm000')      , repeat (chr(g%120 + 32), 64)   generate_series(1,50000) g;  select pg_size_pretty(pg_relation_size('test'));       -- 5640 kb select pg_size_pretty(pg_total_relation_size('test')); -- 5648 kb 

after adding primary key:

alter table test add constraint test_pkey primary key(a);  select pg_size_pretty(pg_total_relation_size('test')); -- 6760 kb 

so, i'd expect maximum of around 44k rows without , around 36k rows primary key.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -