Re: Add support for unit "B" to pg_size_pretty()

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add support for unit "B" to pg_size_pretty()
Date: 2023-02-20 14:34:52
Message-ID: 20230220143452.GM1653@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Feb 20, 2023 at 07:44:15AM +0100, Peter Eisentraut wrote:
> This patch adds support for the unit "B" to pg_size_pretty(). This makes it

It seems like what it actually does is to support "B" in pg_size_bytes()
- is that what you meant ?

pg_size_pretty() already supports "bytes", so this doesn't actually make
sizes any more pretty, or evidently change its output at all.

> diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
> index dbd404101f..9ecd5428c3 100644
> --- a/src/backend/utils/adt/dbsize.c
> +++ b/src/backend/utils/adt/dbsize.c
> @@ -49,6 +49,7 @@ struct size_pretty_unit
> /* When adding units here also update the error message in pg_size_bytes */
> static const struct size_pretty_unit size_pretty_units[] = {
> {"bytes", 10 * 1024, false, 0},
> + {"B", 10 * 1024, false, 0},

This adds a duplicate line (unitbits=0) where no other existing line
uses duplicates. If that's intentional, I think it deserves a comment
highlighting that it's an /*alias*/, and about why that does the right
thing, either here about or in the commit message.

> {"kB", 20 * 1024 - 1, true, 10},
> {"MB", 20 * 1024 - 1, true, 20},
> {"GB", 20 * 1024 - 1, true, 30},

--
Justin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2023-02-20 14:40:18 Re: psql \watch 2nd argument: iteration count
Previous Message Bharath Rupireddy 2023-02-20 14:30:00 Re: Add WAL read stats to pg_stat_wal