On Tue, Jul 12, 2016 at 01:36:38PM +0000, thomas.ber...@1und1.de wrote:
> The following bug has been logged on the website:
> Bug reference:      14244
> Logged by:          Thomas Berger
> Email address:      thomas.ber...@1und1.de
> PostgreSQL version: 9.5.3
> Operating system:   any
> Description:        
> pg_size_pretty uses the suffix "kB" (kilobyte, 10^3 byte), but the returned
> value is "KB", or "KiB" ( kibibyte, 2^10 byte). This is missleading and
> should be fixed. See also https://en.wikipedia.org/wiki/Kibibyte
> =# select pg_size_pretty(1024000::bigint);   
>  pg_size_pretty 
> ----------------
>  1000 kB

(Thread moved to hackers.)

The Postgres docs specify that kB is based on 1024 or 2^10:

        Note: The units kB, MB, GB and TB used by the functions
        pg_size_pretty and pg_size_bytes are defined using powers of 2 rather
        than powers of 10, so 1kB is 1024 bytes, 1MB is 10242 = 1048576 bytes,
        and so on.

These prefixes were introduced to GUC variable specification in 2006:

        commit b517e653489f733893d61e7a84c118325394471c
        Author: Peter Eisentraut <pete...@gmx.net>
        Date:   Thu Jul 27 08:30:41 2006 +0000
            Allow units to be specified with configuration settings.

and added to postgresql.conf:

        # Memory units:  kB = kilobytes        Time units:  ms  = milliseconds
        #                MB = megabytes                     s   = seconds
        #                GB = gigabytes                     min = minutes
        #                TB = terabytes                     h   = hours
        #                                                   d   = days

and the units were copied when pg_size_pretty() was implemented.  These
units are based on the International System of Units (SI)/metric.
However, the SI system is power-of-10-based, and we just re-purposed
them to be 1024 or 2^10-based.

However, that is not the end of the story.  Things have moved forward
since 2006 and there is now firm support for either KB or KiB to be
1024-based units.  This blog post explains the current state of prefix


and here is a summary for 1000/1024-based units:

        Kilobyte (Binary, JEDEC)        KB      1024
        Kilobyte (Decimal, Metric)      kB      1000
        Kibibyte (Binary, IEC)          KiB     1024

You will notice that none of these list kB as 1024, which explains this
bug report.

Yes, we have redefined kB, and documented its use in postgresql.conf and
pg_size_pretty(), but it does not match any recognized standard.

I am thinking Postgres 10 would be a good time to switch to KB as a
1024-based prefix.  Unfortunately, there is no similar fix for MB, GB,
etc.  'm' is 'milli' so there we never used mB, so in JEDEC and Metric,
MB is ambiguous as 1000-based or 1024-based.

IEC does give us a unique specification for 'mega', MiB, and GiB, which
might be what we want to use, but that might be too big a change, and I
rarely see those.

  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+                     Ancient Roman grave inscription +

Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to