| From: | Magnus Hagander <magnus(at)hagander(dot)net> | 
|---|---|
| To: | Thomas Kellerer <shammat(at)gmx(dot)net> | 
| Cc: | pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> | 
| Subject: | Re: Parameter value from (mb/gb) to bytes | 
| Date: | 2020-10-14 15:01:33 | 
| Message-ID: | CABUevEyfWsWTUu67v+t2pE+mU2YUxQXmpw60AwhX=Ew5AveH4A@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
On Wed, Oct 14, 2020 at 3:57 PM Thomas Kellerer <shammat(at)gmx(dot)net> wrote:
> Thomas Kellerer schrieb am 14.10.2020 um 15:55:
> > Raul Kaubi schrieb am 14.10.2020 um 12:22:
> >> Is there a simple way to dynamically get for example parameter
> >> „shared buffers“ value (megabytes or gigabytes) to bytes, for
> >> monitoring perspective..?>
> >>
> >>
> >> At the moment, this gives me value in GB.
> >>
> >> # psql -U postgres -Atc "show shared_buffers;"
> >> 1GB
> >>
> >> This value may as well be in MB. So I am looking a way to dynamically
> get the value in bytes.
> >
> > Instead of using "show" you can use a SELECT with pg_size_bytes():
> >
> >   select pg_size_bytes(setting)
> >   from pg_settings
> >   where name = 'shared_buffers';
>
> Ah, forgot that shared_buffers is in 8K pages.
>
> So you actually need:
>
>    select pg_size_bytes(setting) * 8192
>    from pg_settings
>    where name = 'shared_buffers';
>
Actually, it doesn't have to be in 8k pages, that depends on the build
options. So if you want to be perfectly correct, you should probably
multiply with current_setting('block_size') instead of a hardcoded 8192 :)
-- 
 Magnus Hagander
 Me: https://www.hagander.net/ <http://www.hagander.net/>
 Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2020-10-14 15:10:39 | Re: Parameter value from (mb/gb) to bytes | 
| Previous Message | Andreas Kretschmer | 2020-10-14 14:53:29 | bug in PG13? |