Re: Parameter value from (mb/gb) to bytes - Mailing list pgsql-general

From Raul Kaubi
Subject Re: Parameter value from (mb/gb) to bytes
Date
Msg-id CAO_+3-BykyKSPaa6z3f-4-BbzLBg0b7okZg32ycrJEEDFDbnXQ@mail.gmail.com
Whole thread Raw
In response to Re: Parameter value from (mb/gb) to bytes  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi

Thanks for all the replies.

So at first, I did this:
select (pg_size_bytes(setting) * (select setting from pg_settings where name = 'block_size')::int) as shared_buffers from pg_settings where name = 'shared_buffers';

But as I understood, that the preferred way would be this, correct..?  (at least, it seems a lot simpler, I agree)
SELECT pg_size_bytes(current_setting('shared_buffers'))  

Regards
Raul

Kontakt Tom Lane (<tgl@sss.pgh.pa.us>) kirjutas kuupäeval K, 14. oktoober 2020 kell 18:23:
Magnus Hagander <magnus@hagander.net> writes:
> On Wed, Oct 14, 2020 at 5:10 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> It's fairly annoying that this doesn't work:
>> regression=# select pg_size_bytes(setting||' '||unit) from pg_settings
>> where name = 'shared_buffers';

> Actually thinking though, surely *this* particular case can be spelled as:
> SELECT  pg_size_bytes(current_setting('shared_buffers'))

Yeah, that might be the most recommendable way.

> Or if doing it off pg_settings:
> SELECT setting::bigint * pg_size_bytes(unit) from pg_settings where
> name='shared_buffers'

No, because that will fail for any unit other than '8kB', eg

regression=# select pg_size_bytes('MB');
ERROR:  invalid size: "MB"

> I'm not sure having pg_size_bytes() parse "16384 8kB" is reasonable, I have
> a feeling that could lead to a lot of accidental entries giving the wrong
> results.

Yeah, that's definitely a risk.  Given that current_setting() already does
what's needed, that's probably a better answer.

                        regards, tom lane


pgsql-general by date:

Previous
From: Jonathan Strong
Date:
Subject: Re: What's your experience with using Postgres in IoT-contexts?
Next
From: Magnus Hagander
Date:
Subject: Re: Parameter value from (mb/gb) to bytes