Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:58:40+00:00 2026-06-14T22:58:40+00:00

I got a large (>100M rows) Postgres table with structure {integer, integer, integer, timestamp

  • 0

I got a large (>100M rows) Postgres table with structure {integer, integer, integer, timestamp without time zone}. I expected the size of a row to be 3*integer + 1*timestamp = 3*4 + 1*8 = 20 bytes.

In reality the row size is pg_relation_size(tbl) / count(*) = 52 bytes. Why?

(No deletes are done against the table: pg_relation_size(tbl, 'fsm') ~= 0)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:58:41+00:00Added an answer on June 14, 2026 at 10:58 pm

    Calculation of row size is more complex than that.

    Storage is typically partitioned in data pages of 8 kB. There is a small fixed overhead per page, possible remainders not big enough to fit another tuple, and more importantly dead rows or a percentage initially reserved with the FILLFACTOR setting.

    And there is more overhead per row (tuple): an item identifier of 4 bytes at the start of the page, the HeapTupleHeader of 23 bytes and alignment padding. The start of the tuple header as well as the start of tuple data are aligned at a multiple of MAXALIGN, which is 8 bytes on a typical 64-bit machine. Some data types require alignment to the next multiple of 2, 4 or 8 bytes.

    Quoting the manual on the system table pg_type:

    typalign is the alignment required when storing a value of this type.
    It applies to storage on disk as well as most representations of the
    value inside PostgreSQL. When multiple values are stored
    consecutively, such as in the representation of a complete row on
    disk, padding is inserted before a datum of this type so that it
    begins on the specified boundary. The alignment reference is the
    beginning of the first datum in the sequence.

    Possible values are:

    • c = char alignment, i.e., no alignment needed.

    • s = short alignment (2 bytes on most machines).

    • i = int alignment (4 bytes on most machines).

    • d = double alignment (8 bytes on many machines, but by no means all).

    Read about the basics in the manual.

    Your example

    This results in 4 bytes of padding after your 3 integer columns, because the timestamp column requires double alignment and needs to start at the next multiple of 8 bytes.

    So, one row occupies:

       23   -- heaptupleheader
     +  1   -- padding or NULL bitmap
     + 12   -- 3 * integer (no alignment padding here)
     +  4   -- padding after 3rd integer
     +  8   -- timestamp
     +  0   -- no padding since tuple ends at multiple of MAXALIGN
    

    Plus item identifier per tuple in the page header (as pointed out by @A.H. in the comment):

     +  4   -- item identifier in page header
    ------
     = 52 bytes
    

    So we arrive at the observed 52 bytes.

    The calculation pg_relation_size(tbl) / count(*) is a pessimistic estimation. pg_relation_size(tbl) includes bloat (dead rows) and space reserved by fillfactor, as well as overhead per data page and per table. (And we didn’t even mention compression for long varlena data in TOAST tables, since it doesn’t apply here.)

    You can install the additional module pgstattuple and call SELECT * FROM pgstattuple('tbl_name'); for more information on table and tuple size.

    Related:

    • Table size with page layout
    • Calculating and saving space in PostgreSQL
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a very large SQLite table with over 500,000 rows with about 15
I've got a large table that lists out approximately 50 users and some simple
I've got a large table in a SQL Server 2005 database and I'd like
I've got a very large table (~100Million Records) in MySQL that contains information about
I've got a large set of data in Excel 2007, but the rows should
I've got a large table (~10,000) and I need one column to take up
I've got a large HTML data entry table, implemented as a large matrix of
I've got a large web app which writes many millions of rows into partitioned
I've got a large number of integer arrays. Each one has a few thousand
I got a large PHP website which I'm now about to take care of.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.