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

What is the overhead for an array in Postgres?

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

Problem

What is the additional overhead of an array compared to a normal column of that same datatype? In other words, if an array will almost always have one value in it, how much space would I be "wasting" by using an array instead of a normal column?

Solution

You can check that using pg_column_size():

select pg_column_size(1::integer) as int_size, 
       pg_column_size(array[1]::integer[]) as array_size


returns:

int_size | array_size
---------+-----------
4 | 28


So the overhead is substantial for just a single value.

Code Snippets

select pg_column_size(1::integer) as int_size, 
       pg_column_size(array[1]::integer[]) as array_size

Context

StackExchange Database Administrators Q#156423, answer score: 6

Revisions (0)

No revisions yet.