PostgreSQL - inserting string of 30,000 characters doesn't change size? -


via command

 select     relname "table",    pg_size_pretty(pg_total_relation_size(relid)) "size",    pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) "external size"    pg_catalog.pg_statio_user_tables order pg_total_relation_size(relid) desc; 

i can retrieve size of tables. (according this article) works. came weird conclusion. inserting multiple values contain approx 30,000 characters each, doesn't change size.

when executing before inserting

tablename   | size text |external size text ------------------------------------------- participant |   264kb   |  256kb 

after inserting (btw base64 encoded images) , executing select command, exact same sizes returned.

i figured couldn't correct wondering, command wrong? or postgresql special large strings?

(in pgadminiii strings not show in 'view data' view shown when executing select base64image participant).

and next wondering (not main question nice have answered) if best practice (since app generates base64 images) or should f.e. convert them image on backend , store images remotely on server instead of in database?

storage management

when insert (or update) data requires more space on disk uses, postgres (or any dbms) allocate space store new data.

when delete data either setting column smaller or deleting rows, space not released operating system. assumption that space re-used subsequent updates or inserts , extending file relatively expensive operation database tries avoid (again dbms do).

if space allocated bigger space stored, can influence speed of retrieval - table scans ("seq scan" in execution plan) more blocks necessary need read harddisk. known "table bloat".

it possible shrink space used using statement vacuum full. should used if suspect problem "bloat". this blog post explains in more details.

storing binary data in database

if want store images in database, means use bytea instead of string value. image encoded in base64 takes twice spaces raw data would.

there pros , cons regarding question if binary data (images, documents) should stored in database or not. subjective decision make , depends on lot of external factors.

see e.g. here: which best method store files on server (in database or storing location alone)?


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -