Re: BUG #19456: # Unit-Labeling Issue: `pg_size_pretty()` Incorrectly Labels Binary Units as Decimal Units - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #19456: # Unit-Labeling Issue: `pg_size_pretty()` Incorrectly Labels Binary Units as Decimal Units
Date
Msg-id CAKFQuwa+ax2T6V1+FRf2CriNJVRKk-Md2eWYWRiGXxMompTRhg@mail.gmail.com
Whole thread
In response to BUG #19456: # Unit-Labeling Issue: `pg_size_pretty()` Incorrectly Labels Binary Units as Decimal Units  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs
On Wed, Apr 15, 2026 at 7:48 AM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      19456
Logged by:          GAUTAM KUMAR
Email address:      gautamkumar2764@gmail.com
PostgreSQL version: 16.8
Operating system:   LINUX
Description:       

The function appears to calculate sizes using binary (base-2) division

You don't need to infer this, you can just read the documentation.

"Converts a size in bytes into a more easily human-readable format with size units (bytes, kB, MB, GB, TB, or PB as appropriate). Note that the units are powers of 2 rather than powers of 10, so 1kB is 1024 bytes, 1MB is 10242 = 1048576 bytes, and so on."


Which means it is not a bug.  And it's not the kind of behavior we are going to change on people.

Maybe go write and submit a pg_size_iso(byte_count [, basis 2|10 default 10]) function.  I agree this is a gap that could be addressed.

I'd probably drop the pg_ prefix as well - that always just seemed odd to me.  We have plenty of functions that are non-standard that we don't prefix like this.

David J.
 

pgsql-bugs by date:

Previous
From: Andrei Lepikhov
Date:
Subject: TRAP: failed Assert("offsets[i] > offsets[i - 1]"), File: "tidstore.c"
Next
From: Daniel Schreiber
Date:
Subject: PostgreSQL 17: Bug in libpq when libpq is dlopened/closed multiple times