Re: [BUGS] BUG #14244: wrong suffix for pg_size_pretty()

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [BUGS] BUG #14244: wrong suffix for pg_size_pretty()
Дата
Msg-id 20160730001838.GA22405@momjian.us
обсуждение исходный текст
Ответы Re: [BUGS] BUG #14244: wrong suffix for pg_size_pretty()  (Bruce Momjian <bruce@momjian.us>)
Re: [BUGS] BUG #14244: wrong suffix for pg_size_pretty()  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: [BUGS] BUG #14244: wrong suffix for pg_size_pretty()  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
On Tue, Jul 12, 2016 at 01:36:38PM +0000, thomas.berger@1und1.de wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      14244
> Logged by:          Thomas Berger
> Email address:      thomas.berger@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:
https://www.postgresql.org/docs/9.6/static/functions-admin.htmlNote: The units kB, MB, GB and TB used by the
functionspg_size_prettyand pg_size_bytes are defined using powers of 2 ratherthan powers of 10, so 1kB is 1024 bytes,
1MBis 10242 = 1048576 bytes,and so on.
 

These prefixes were introduced to GUC variable specification in 2006:
commit b517e653489f733893d61e7a84c118325394471cAuthor: Peter Eisentraut <peter_e@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
specification:
http://pchelp.ricmedia.com/kilobytes-megabytes-gigabytes-terabytes-explained/

and here is a summary for 1000/1024-based units:
Kilobyte (Binary, JEDEC)    KB    1024Kilobyte (Decimal, Metric)    kB    1000Kibibyte (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  <bruce@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 +



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: [Patch] Temporary tables that do not bloat pg_catalog (a.k.a fast temp tables)
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [BUGS] BUG #14244: wrong suffix for pg_size_pretty()