HiveBrain v1.2.0
Get Started
← Back to all entries
principlesqlMinor

PostgreSQL: Separate tables vs single table to perserve disk space?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqltablesspacediskseparateperservesingletable

Problem

I have 2 tables with the below schemas with equal number of rows. When I run the SELECT relname, relpages FROM pg_class ORDER BY relpages DESC command, they show up as 23GB each even though the data types (total number of bytes) for thew two schemas result in different sizes . What is the best way to figure out how much space I would save by combining tables? Also, is there any way to determine, how much space each row is actually taking up?

Table "public.table1"
Column        |           Type           |                      Modifiers                      
--------------+--------------------------+-----------------------------------------------------

 field1       | smallint                 | 
 field2       | smallint                 | 
 field3       | integer                  | 
 field4       | smallint                 | 
 timestamp    | timestamp with time zone | 
 user_id      | integer                  | 
 status       | boolean                  | 
 id           | integer                  | not null default 

                                  Table "public.table2"
 Column          |           Type           |                     Modifiers                      
 ----------------+--------------------------+----------------------------------------------------
 user_id         | integer                  | 
 begin_timestamp | timestamp with time zone | 
 end_timestamp   | timestamp with time zone | 
 field           | smallint                 | not null
 id              | integer                  | not null default

Solution

Because the resulting combined table would have unused rows for records from each respective table, the likelihood is that you would not gain space, but lose it.

More importantly than that, I would highly discourage making an architecture decision of that nature for reasons of disk-space. Disks are cheap--a well designed and functional application is not. If there is an issue of run-time performance (ie all 46 gb is being loaded into memory/swap space) then you may have an optimization and tuning issue on your hands.

Context

StackExchange Database Administrators Q#4392, answer score: 3

Revisions (0)

No revisions yet.