From Raul.Kaubi@rik.ee Wed Oct 14 10:22:03 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSh80-0000HV-LQ for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 13:47:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSh7z-0000lX-Jj for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 13:47:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSdvA-0003RX-CR for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 10:22:12 +0000 Received: from mail1.just.ee ([213.184.53.9]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSdv6-0004nc-Im for pgsql-general@postgresql.org; Wed, 14 Oct 2020 10:22:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; d=rik.ee; s=s20190418; c=relaxed/relaxed; q=dns/txt; i=@rik.ee; t=1602670924; x=1605262924; h=From:Date:Subject:Message-ID:To:MIME-Version; bh=fX4nO7etnLIFSY5rRdqKHL1rv9RqAaPUlUh6VZWt6qc=; b=Yw4tOpbUkFQRGDKP/A97aN/C4mMCMhPha8mObB5Q1lIsCV2s0UZFadBmRW5mMvUq q5WQLwQxvHQXffjhhsrn0eHLv8xKH9uiHLZJh/V0hLDhzQo5CSu1ZgPdh247AuVZ 5eMZHLT+tfUOu+MBZnkQw46tehNKepsLfL8LwKQ1XgI=; X-AuditID: d5b83509-bedff700000058f1-a3-5f86d14c40ca From: Raul Kaubi To: "pgsql-general@postgresql.org" Subject: Parameter value from (mb/gb) to bytes Thread-Topic: Parameter value from (mb/gb) to bytes Thread-Index: AdaiE2jCr+H+T95yQQCIyYP3ySD/xw== Date: Wed, 14 Oct 2020 10:22:03 +0000 Message-ID: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> Accept-Language: et-EE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-exclaimer-md-config: 0ffde1e1-0574-4cb5-b117-7534ebede067 Content-Type: multipart/alternative; boundary="_000_6cbca2bcda734464a1be9f7d7380ff33rikee_" MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKLMWRmVeSWpSXmKPExsXCxWh2WNfnYlu8wcWVbBbT725lc2D0uLBv GnsAYxSXTUpqTmZZapG+XQJXxo/t3YwFq6Uqni2ayN7A2CnexcjJISFgIvF+3iXWLkYODjYB FYknOxVAwiICjhKL739hBrGFBfQkWnv3MEPEjSUenPzGAmHrSWxqvwZmswioSrRdPcIEYvMK mEpM2DebEcRmFJCVWLJxAVicWUBc4taT+UwQawUkluw5zwxhi0q8fPwP7AQJAWuJSQ89Icpj JQ5d/MoOMVJQ4uTMJywTGPlnIZk0C0nZLCRlEHEdiQW7P7FB2NoSyxa+Zoaxzxx4zIQsvoCR fRUjb25iZo6hXlZpcYleauomRmDQXt1hyrmD8esvw0OMTByMhxglOJiVRHhfSbfFC/GmJFZW pRblxxeV5qQWH2KU5mBREuddat4SLySQnliSmp2aWpBaBJNl4uCUamCcsnrz9s+KAns/V7dN bO6UVnQ5al/4pFjqHYfZnsIFi9iy4wV7F/2qO/FzUjpb17Lfbm9P57m9NQ+J1gl69+fW8+Qt y33DmddNmmUuwPlbj7+7MfCk08ZqKaFlyjHi7IfPbzNOV3V9wZV9eu6zTvu8Cw0/evvWd+pL WjW1uodEOi9OXbL1Y60SS3FGoqEWc1FxIgCRCDkJSAIAAA== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --_000_6cbca2bcda734464a1be9f7d7380ff33rikee_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Is there a simple way to dynamically get for example parameter "shared buff= ers" 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 t= he value in bytes. Regards Raul --_000_6cbca2bcda734464a1be9f7d7380ff33rikee_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi

 

Is there a simple way to dynamically get for example= parameter „shared buffers“ value (megabytes or gigabytes) to b= ytes, for monitoring perspective..?

 

At the moment, this gives me value in GB.=

 

# psql -U postgres -Atc "show shared_buffers;&q= uot;

1GB

 

This value may as well be in MB. So I am looking a w= ay to dynamically get the value in bytes.

 

Regards

Raul

--_000_6cbca2bcda734464a1be9f7d7380ff33rikee_-- From shammat@gmx.net Wed Oct 14 13:55:41 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShFt-0000ZG-D9 for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 13:55:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kShFq-0003Qw-Ez for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 13:55:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShFq-0003Qp-5p for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 13:55:46 +0000 Received: from mout.gmx.net ([212.227.17.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShFo-0008WT-3Q for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 13:55:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1602683742; bh=dBA5szvgUmdD6vgs250Ujz6DkvLm12o1ui4edPrYd9E=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=Mvm+UW31Cs8CwruY6JAZIbhnyR3KPf4cD8bB7QWNC6FJ37e5JV6PcLcrjHv0Z9hDm CIzPlkAqY36SVPNtBgQvscfuNPet6IM4vjPETJ/KHdwNdAPVPQL3xnPQbKV8MAOKIM B2VANdhdI/vU5DRzIuc8vQB4bc0f541pwn41tipU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.1.35.238] ([185.40.248.10]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mxm3K-1kGHWy2Byw-00zF5j for ; Wed, 14 Oct 2020 15:55:42 +0200 Subject: Re: Parameter value from (mb/gb) to bytes To: pgsql-general@lists.postgresql.org References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> From: Thomas Kellerer Message-ID: Date: Wed, 14 Oct 2020 15:55:41 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:qua9LxEnn5neI4ASJdm9Jd3uJqkZ0ISUIMVxdEz6B9ewreCokTs VuH/J+cSRD+ZZuB2FVzsRF7mMMjw+o310rg0mVxYua92bVjF6Mu/vkS2cvixiW66LU+2ffF Z0Q8ep4c1bvTX7Wq5+ZRKw3iQgYR08UCbmnJKlMd6S+qte7biAjuM4uC/E70mYLC5X8MYS3 dRqPBuWQoVRa1hJAuA3iQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:0uFJ5kac5zY=:rQaGZivlwLOLr/GmW3DTl/ oLAptNQ3Auo7Xqmt+ThoXhp5SywL2kPI7yieCYIkgyZHX1yVH6ZMHTk0QTlntqjM2YSWWwdzp NoR4RcGPeqeZ76CXDZpscFmCW9n9D7iNvRIE7XDN2/fiiiwelWKHwwHQPSP0r/y3YeF+b6suP NmixDtYlUBC7FhR5lBylJ6l2+AR4CLsBMvdK/7s8kWwdUfe2ohN9dnTLflEMG7Z5C38yB5OuB YpSYma/BUIeeM9n/piYcAVRSStbJcVy2+nk3sk6NzuJgapcS9Wihe10LYZyX1ncHhZlmYUEGd XVmiCvgD/8XmFWpScwiFBd1LGHfxjl2EGsiDOfP7ocSk+cB66+nLpoFWuAMqDXcBbL/9v1iyn RZXZJSt1UMV1I/51+dXciN1ogL4aXWIEE5akso+V3HRKsVBBCct1gOh0KVCWMUZ+9TZvGxJv1 eJbAt1+7hirgIr7B5ArQ0Ki/dC3RODmt0BSabi0KQa+WJwMEAwcjlJrGkGFipGwme/K0i+mJX eWyF6Qt5Q4xa/dU5ieisLO2RW2+uLwr4kE3h/SyjE+A10fJZYCRrnChZri84r0xVsBE983a7n gjtfvEQvQAH4wtBwnIeALIZQ79WdOH2t9KHkmAAN/CCzJPVhxNpIAvdH+STDDznn4PQ9GgHTo rUBvPC+B7tVSfbdVJnWByBXEEyx9B3XeALxoesSi8cn/vnnSOT3ZoSQewmfUTSouZUorrOE5M Q+uPo115qRgnbWkrwUavjbWgdPWyZpLB4JnIxKkGoR8rHdJz9JyofcpI5lMey9/AT3+mtDQj7 4MyWH9NOVz3sFoM7IZaqMmXCreNJYYgsjf9FJL+vwENiTWS4xVCpkaAa1Dh/QfM+HR2ANwrvo V5kpkt23FKBTyFKBXICg== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Raul Kaubi schrieb am 14.10.2020 um 12:22: > Is there a simple way to dynamically get for example parameter > =E2=80=9Eshared buffers=E2=80=9C value (megabytes or gigabytes) to bytes= , for > monitoring perspective..?> > =C2=A0 > > 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 ge= t 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 =3D 'shared_buffers'; From shammat@gmx.net Wed Oct 14 13:57:45 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShHq-0000cp-JF for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 13:57:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kShHp-0007E3-H5 for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 13:57:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShHp-0007Dw-9B for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 13:57:49 +0000 Received: from mout.gmx.net ([212.227.17.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kShHn-00006F-9d for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 13:57:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1602683866; bh=YMEBtR6laHJooKHOuSmtYltCmseYFcb0Mro+O9So3tY=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=hBTop/IhurmMcgEnB4zi+mBJKo6uIss8yOSWjMJhstxUpSk/0Enx/jhfUKetLbjTo kMVncHhbxQF5GKKB0xTQ3W47PT2R/2KfR+n1/9+GUs4/QICjCmY19udzWOBHvRlNb8 OKIf6iF3CjdYX5Vr4US9bSXSUjCLHu80SA+osCTc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.1.35.238] ([185.40.248.10]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N8ofO-1kMuHU293e-015o0P for ; Wed, 14 Oct 2020 15:57:46 +0200 Subject: Re: Parameter value from (mb/gb) to bytes To: pgsql-general@lists.postgresql.org References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> From: Thomas Kellerer Message-ID: Date: Wed, 14 Oct 2020 15:57:45 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:DnTlkLGk3Lr96YVkxpCOwgcjmlWYEZrzBaX7FpJmYReyps8yD0o 6JgvLhNH1RfrqAiQl+azRL6AlgBJKtYD67AV+hZCHtnfuUuUiMa91RZWstN+CApd8j9XcFW RpwiqxpHRQ2FgMNdFaNfzTBgYRyHqu4lYh0qCOYGu00blrhq6t0OHcjtcWvsTfEipidcJLg 2u6kiZZKiR61SmgcOkqVg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:2JJRHnxuonI=:wrg/FqT5PDLAey9cGHcy58 Fxv8lj6OirIdUYjA7xgwYVW2Q5uoWBFkzM4eLAyUGNke8nisX4w/1dFiFJoZzAx1n8SffHqMn +oc6Wrl+2m7zwFZ6spk2Nf+cBUcDxM7KNpnj5T+CSXhSJdTE4BmlilG/MlOupZDAMdxaOP+Q3 BOB36jBsAg1dBcBq1bce+rBAhAhceAzUhf9Z6kvaPugtY0c2iSmXOJipUBDB5Dt1N5Ncp9OA0 dXGwCxRstFXYTv3MDcjTK58IMttnVa2LF8PI/rtBvOAYjtuN+tfMKcWJe0LtTacpEZ00783hp E6xpR2h4Mi9aXlZyIPG/Z/qsmhlpxN5GriZLUiE/ZlyGTZ84QhOy91bOn5hIr9ynXkopppN5Q Ib0P1plr80VXsjtV084PQWI0qgF24ja6vEAVHvUxpTap4Bc9aVZSb/U6HM7fmXgMykL2qryu3 3npb7RlLbMrcO3ZYiznwckfXKVaJIf1u22LKX8lKecNZrr+wBZDJNy7gkR8DRZmDUv4f5QauK zUY6ZGPe60dXHomnLa36YvtxEWHxZS4My03clAejsTgQm+0ERCRWgchtNQSfIo5UPI/MWaqLn mZ41SFZARjP/jjnVdWzcgorZTNB4oHz62oTLP1DyoJTmLpHCmp7F75TwDUbyJzp775a8R3XAJ jpzPddMbQQAXleC4TKNrrhFt0pKfqKuhcaW4RMxdBhBGKDsPkfhY+xuqb+16wcfmx4UrV7B5O ptUMMd1PtRcnfRd7Lu3oa1WoFaTv8fQmjUBQ+F5xkuz6PCqxFFbNHDNKf8dYu/LygQkA7ygwM LGI3p87XQJpIHW8PR4KDWj5iJVOOdjKfKC/Zg3vYfgUeNnyczcx+M+G14zKzXFOmOfoDBGdva 6qHD2Oy5PoWku5rT9+2w== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 >> =E2=80=9Eshared buffers=E2=80=9C value (megabytes or gigabytes) to byte= s, for >> monitoring perspective..?> >> =C2=A0 >> >> 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 g= et 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 =3D '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 =3D 'shared_buffers'; From magnus@hagander.net Wed Oct 14 15:01:33 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiHy-0002z9-F5 for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:02:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSiHv-000470-VI for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:01:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiHv-00046r-IV for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:01:59 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSiHo-00071l-Mp for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:01:58 +0000 Received: by mail-lf1-x12d.google.com with SMTP id v6so4013651lfa.13 for ; Wed, 14 Oct 2020 08:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hagander-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TPADAWXEmCH7+0vNzPbxxzXLM1YcM1nGIqSAhf6vI6k=; b=sbayWNnMygKK8aVxRdPguSfDFHOR7gwmy1p8IyDEoKf9bPrIPOV3McARZh1xRQAQgr 9c0elBkQRFlFOjKewr0y9LYbiQ4frsjdjb1M3PZvqYabpy7I4jSZnyQB1NFQPWkbuFul XaaRjnmJA/bAWOwDq668HsFegwn+0IXjo6zDcssGp5QFgJFX5HZLld1ZKimd9amGolHl wuS6NtzXhv6ZYAwzQrNPEFifme1eavug+o9Mxh/vs6mNDsWArITWn8clRi1R8XmGiA+A x18+ypfhsYSjBAZHCfKUylMuiKIIE4b7KFs7/BCigOODucLTZQEO404qK1TrGBXPeSYL YKSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TPADAWXEmCH7+0vNzPbxxzXLM1YcM1nGIqSAhf6vI6k=; b=UgDRsUaNCviWXxrlgdXRVLQk2LuQbs6o4QgesNE0oP9iYscjfUPV6AbN8lYT8wdtzF Yh4KfvnibtF2yD00T2J0fTfsmf/0iTq28bNJTYmuo1ff99Lllh+eDJoSNfJn7yI0kF5n l0uwQ3DjmzaSkRiG2IQ37RgCccO2MVWeEr288xlXClvfyWHuy9+Ej5DTaIUooI/5g1Uk duULBxqqIfJqmugfD3MAtLHw3aNVQQy0xJky0tFD2P/L19AciQej3JNdWfFdmv+mqHE7 UV9+SieKQivX6PZC1ktc9faV6cS1VJFDJCfpEerNlN9yV8qGkeGesgIPppibCI5s52ss 4pFA== X-Gm-Message-State: AOAM530G14TyjAlXADSezQKodkZQJXFAnRG1cqi4rfUBCMXc5y8U5AV3 oawmjLY9luVzlo8eDWG/m4euiIzfOtFYDqMd5RFJ5lZJu+4= X-Google-Smtp-Source: ABdhPJzJPUCtHJMNFDJgQagNdwjQUMfOeFGgNqSM6k3LMuKTmGszyEz1jrwQ4QB/wVyxlCg61JSvmphmxA5oimL2oTo= X-Received: by 2002:a19:2294:: with SMTP id i142mr1427295lfi.579.1602687710361; Wed, 14 Oct 2020 08:01:50 -0700 (PDT) MIME-Version: 1.0 References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> In-Reply-To: From: Magnus Hagander Date: Wed, 14 Oct 2020 17:01:33 +0200 Message-ID: Subject: Re: Parameter value from (mb/gb) to bytes To: Thomas Kellerer Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000a9911205b1a2cf24" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000a9911205b1a2cf24 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Oct 14, 2020 at 3:57 PM Thomas Kellerer 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 > >> =E2=80=9Eshared buffers=E2=80=9C value (megabytes or gigabytes) to byt= es, 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 =3D '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 =3D '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 :) --=20 Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/ --000000000000a9911205b1a2cf24 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Oct 14, 2020 at 3:57 PM Thoma= s Kellerer <shammat@gmx.net> w= rote:
Thomas Kel= lerer 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
>> =E2=80=9Eshared buffers=E2=80=9C value (megabytes or gigabytes) to= bytes, for
>> monitoring perspective..?>
>> =C2=A0
>>
>> 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 dynamica= lly get the value in bytes.
>
> Instead of using "show" you can use a SELECT with pg_size_by= tes():
>
>=C2=A0 =C2=A0select pg_size_bytes(setting)
>=C2=A0 =C2=A0from pg_settings
>=C2=A0 =C2=A0where name =3D 'shared_buffers';

Ah, forgot that shared_buffers is in 8K pages.

So you actually need:

=C2=A0 =C2=A0select pg_size_bytes(setting) * 8192
=C2=A0 =C2=A0from pg_settings
=C2=A0 =C2=A0where name =3D 'shared_buffers';
=
Actually, it doesn't have to be in 8k pages, that depends on the bu= ild options. So if you want to be perfectly correct, you should probably mu= ltiply with current_setting('block_size') instead of a hardcoded 81= 92 :)

--
=C2=A0Magnus Hagander
=C2=A0Me: https://www.hagander.net/=C2=A0Work: = https://www.redpill-linpro.com/
--000000000000a9911205b1a2cf24-- From tgl@sss.pgh.pa.us Wed Oct 14 15:10:39 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiQX-0003Oi-9A for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:10:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSiQV-0003oh-Sg for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:10:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiQV-0003oa-Lk for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:10:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiQP-0000km-C2 for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:10:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 09EFAdm33601487; Wed, 14 Oct 2020 11:10:39 -0400 From: Tom Lane To: Magnus Hagander cc: Thomas Kellerer , pgsql-general Subject: Re: Parameter value from (mb/gb) to bytes In-reply-to: References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> Comments: In-reply-to Magnus Hagander message dated "Wed, 14 Oct 2020 17:01:33 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3601485.1602688239.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 14 Oct 2020 11:10:39 -0400 Message-ID: <3601486.1602688239@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Magnus Hagander writes: > On Wed, Oct 14, 2020 at 3:57 PM Thomas Kellerer wrote: >> select pg_size_bytes(setting) * 8192 >> from pg_settings >> where name =3D '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 = :) It's fairly annoying that this doesn't work: regression=3D# select pg_size_bytes(setting||' '||unit) from pg_settings w= here name =3D 'shared_buffers'; ERROR: invalid size: "16384 8kB" DETAIL: Invalid size unit: "8kB". HINT: Valid units are "bytes", "kB", "MB", "GB", and "TB". Maybe we should teach pg_size_bytes to cope with that. regards, tom lane From pavel.stehule@gmail.com Wed Oct 14 15:15:44 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiVv-0003dw-PZ for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:16:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSiVu-0002l3-Mq for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:16:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiVu-0002k0-Ch for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:16:26 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSiVs-0000my-AC for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:16:26 +0000 Received: by mail-pg1-x533.google.com with SMTP id b23so977525pgb.3 for ; Wed, 14 Oct 2020 08:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0jeFrcxsRaE8QUaqWLHrxfAjtcvm9T+Qa7BySa0iV4g=; b=WQ8sgdTY7GU8Ary5DH1Z+eSV4GILeThbSGbBqysPjQiEsiq4/HFyoTEoCFg7weBqyt Uxl8UsrpH2rjSMpHnoCKgYNX658idIjeiZZPSuskDrUI03rI1LM2VAWJZuqHbfJTWb3k miwSB076kEQjegu5UeUTpSFtlQepvUFkJWQy5qyRtW5I0Xzk9kDWTVVnGvC+z9UV1AII uu6MZ2e19s2DLevLoKDzM2p1Sgp1sMOxfPP1AiQ1fjl4cLjdvC/FbqQnJiam7bY/U4DQ CN68QqdOtAa+3DPWPHSTYMP4c8GoGtplAxpRLVE/VyIMa0XT+VMJJn2UUVtGYXFVjB7l ZVmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0jeFrcxsRaE8QUaqWLHrxfAjtcvm9T+Qa7BySa0iV4g=; b=bbmTqwNM3kmdhQMaSJfJbEecniyBtOUQIpyJEjeQKPOs0dAuywTI6iOr0/mkBLBnBf 38ovDLEOtxnlmikJQi5x6/NMuTCWEPHq3G4ar4PFBNGxJekbH5GgUdsWDSEYu1dfcYQR Xd7OwWXCI5QTRf0nwJd9xxRtU9FaCovT0PPEvv2FEuE2ZBoHZpicOq4JaFGVvTB20JMV d8W9tvG0UXdNBIK9Sp7yTRISlf8XLOapzf+xc5PAGHl8sb8HGbgA1nh4ySktVv6EHXWk tnStczG2jthGpgQKMq8bMfcJVsQV34PvPNGmu1GbnwnLjETylMsQfhrt4ul4KuEZT8f7 VT0A== X-Gm-Message-State: AOAM530W7bd+oEm8m4Lw0VQ/5vjeFCePS541CeRjsjC5gAfpZO9OexJH /syo3a857HH4B2YIeBIlgD7YZiTv68dEmBO3+VI= X-Google-Smtp-Source: ABdhPJyw+5/tCbrLEZWjk9TtveDXRuSk/kzhidOrRjVzEvdWYkqHH7fx5CgUXwALLDlZwDbe12GmoQJlakNt2J5KASY= X-Received: by 2002:aa7:9e4a:0:b029:152:54d1:bffa with SMTP id z10-20020aa79e4a0000b029015254d1bffamr4573561pfq.6.1602688581592; Wed, 14 Oct 2020 08:16:21 -0700 (PDT) MIME-Version: 1.0 References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> <3601486.1602688239@sss.pgh.pa.us> In-Reply-To: <3601486.1602688239@sss.pgh.pa.us> From: Pavel Stehule Date: Wed, 14 Oct 2020 17:15:44 +0200 Message-ID: Subject: Re: Parameter value from (mb/gb) to bytes To: Tom Lane Cc: Magnus Hagander , Thomas Kellerer , pgsql-general Content-Type: multipart/alternative; boundary="000000000000976d8405b1a30362" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000976d8405b1a30362 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable st 14. 10. 2020 v 17:10 odes=C3=ADlatel Tom Lane napsal= : > Magnus Hagander writes: > > On Wed, Oct 14, 2020 at 3:57 PM Thomas Kellerer wrote= : > >> select pg_size_bytes(setting) * 8192 > >> from pg_settings > >> where name =3D '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 > :) > > It's fairly annoying that this doesn't work: > > regression=3D# select pg_size_bytes(setting||' '||unit) from pg_settings > where name =3D 'shared_buffers'; > ERROR: invalid size: "16384 8kB" > DETAIL: Invalid size unit: "8kB". > HINT: Valid units are "bytes", "kB", "MB", "GB", and "TB". > > Maybe we should teach pg_size_bytes to cope with that. > "8kB" is strange unit - maybe we can introduce new - "page" > regards, tom lane > > > --000000000000976d8405b1a30362 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
st 14. 10. 2020 v=C2=A017:10 odes=C3= =ADlatel Tom Lane <tgl@sss.pgh.pa.u= s> napsal:
magnus@hagander.net> writes:
> On Wed, Oct 14, 2020 at 3:57 PM Thomas Kellerer <shammat@gmx.net> wrote:
>> select pg_size_bytes(setting) * 8192
>> from pg_settings
>> where name =3D 'shared_buffers';

> Actually, it doesn't have to be in 8k pages, that depends on the b= uild
> options. So if you want to be perfectly correct, you should probably > multiply with current_setting('block_size') instead of a hardc= oded 8192 :)

It's fairly annoying that this doesn't work:

regression=3D# select pg_size_bytes(setting||' '||unit) from pg_set= tings where name =3D 'shared_buffers';
ERROR:=C2=A0 invalid size: "16384 8kB"
DETAIL:=C2=A0 Invalid size unit: "8kB".
HINT:=C2=A0 Valid units are "bytes", "kB", "MB&quo= t;, "GB", and "TB".

Maybe we should teach pg_size_bytes to cope with that.

"8kB" is strange unit - maybe we can introduce ne= w - "page"



=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane


--000000000000976d8405b1a30362-- From magnus@hagander.net Wed Oct 14 15:16:57 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiWg-0003gG-OF for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:17:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSiWf-0000gz-Jv for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:17:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiWf-0000fo-CO for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:17:13 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSiWc-0000nj-Is for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:17:12 +0000 Received: by mail-lj1-x244.google.com with SMTP id h20so3590229lji.9 for ; Wed, 14 Oct 2020 08:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hagander-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uGJCHOnW+zwm9R2TQTwxju6MtPdQmwmUsiYc3zVxtjg=; b=DpySR4Gu+iagHsIKl0qsaoiHTFHwQGFVtwkxzgON/KPrz0jjrHHOEBePlB+vXWCfWo wBuYyMo7cdEDPBVszDjQRj/MGKiUGZvAxDclYhtEy5MyuiEKuk7qoBXrVBl/WR4DU+LU JB7GZ/KNCaBEjxZrXBSEJPCnRoGqeqg0cMDR6jYQDirzRyHpkndTTbUHVoyufirZTDJ9 nimA4SpXig3hTuIRwda84HbCWUU3LUqwr3/T1mamJcnIj1CnNxeyX7TDxJIkl7OzseWq aaq/5D2TXAYXCDlGuNAcRkBopO2ukAepacGYOytdBP11A37J6ld20JRbfG0J3Ol9RkWV XWQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uGJCHOnW+zwm9R2TQTwxju6MtPdQmwmUsiYc3zVxtjg=; b=sRp/l66LGKLjcI6IB4OwWCGLSFPpjUwlnIKa5dUynBJvVdmYpHuOB2kkBePEerYWiH jPzkDrz0gPrHmJS5sO6EU9FykxcBR/DcjmB60XzmpdeLZJBfPHMkt33PFEgXPmI4IMyp 1WwfCIgp/2K5CBv/+n06vuWAPXUTcmoxLI7Et7tbK6iwFmCJTL5fP7GrcKzwhPxutYwG obvuyVOeVBVSJT3basjCKqDHzDWFHPSvOLeZLAkA4VBML7Vbi7YUHkMUMEoN2wf3tJiN 9BtAthCv1ylP0Iazn0rfYkBafiz9G1AZrDDGe9jZ2Nu4CmVlLSDG0zPtmR3S3a8pz8wU VSlA== X-Gm-Message-State: AOAM531NHCHYDXVZOgOk/vnJF+sUUTKm8LhE0IxYN/0O1Z/MtYPheaHV bGS4FulXWe56jk4dFBXY8SZEP2xvmG3rOWfmT42sgA== X-Google-Smtp-Source: ABdhPJz07LaRrW78qA6Ankd7w/B9TPFFi/fUO3ooGggBm5vQM3jGaeg8SRhtt0wdD6Sa+csxa2c92E+KM8aREXiuRlM= X-Received: by 2002:a2e:984e:: with SMTP id e14mr1883845ljj.94.1602688629554; Wed, 14 Oct 2020 08:17:09 -0700 (PDT) MIME-Version: 1.0 References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> <3601486.1602688239@sss.pgh.pa.us> In-Reply-To: <3601486.1602688239@sss.pgh.pa.us> From: Magnus Hagander Date: Wed, 14 Oct 2020 17:16:57 +0200 Message-ID: Subject: Re: Parameter value from (mb/gb) to bytes To: Tom Lane Cc: Thomas Kellerer , pgsql-general Content-Type: multipart/alternative; boundary="000000000000735a4c05b1a30618" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000735a4c05b1a30618 Content-Type: text/plain; charset="UTF-8" On Wed, Oct 14, 2020 at 5:10 PM Tom Lane wrote: > Magnus Hagander writes: > > On Wed, Oct 14, 2020 at 3:57 PM Thomas Kellerer wrote: > >> 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 > :) > > It's fairly annoying that this doesn't work: > > regression=# select pg_size_bytes(setting||' '||unit) from pg_settings > where name = 'shared_buffers'; > ERROR: invalid size: "16384 8kB" > DETAIL: Invalid size unit: "8kB". > HINT: Valid units are "bytes", "kB", "MB", "GB", and "TB". > > Maybe we should teach pg_size_bytes to cope with that. > Actually thinking though, surely *this* particular case can be spelled as: SELECT pg_size_bytes(current_setting('shared_buffers')) Or if doing it off pg_settings: SELECT setting::bigint * pg_size_bytes(unit) from pg_settings where name='shared_buffers' 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. -- Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/ --000000000000735a4c05b1a30618 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Oct 14, 2020 at 5:10 PM Tom L= ane <tgl@sss.pgh.pa.us> wrot= e:
Magnus Hagand= er <magnus@haga= nder.net> writes:
> On Wed, Oct 14, 2020 at 3:57 PM Thomas Kellerer <shammat@gmx.net> wrote:
>> select pg_size_bytes(setting) * 8192
>> from pg_settings
>> where name =3D 'shared_buffers';

> Actually, it doesn't have to be in 8k pages, that depends on the b= uild
> options. So if you want to be perfectly correct, you should probably > multiply with current_setting('block_size') instead of a hardc= oded 8192 :)

It's fairly annoying that this doesn't work:

regression=3D# select pg_size_bytes(setting||' '||unit) from pg_set= tings where name =3D 'shared_buffers';
ERROR:=C2=A0 invalid size: "16384 8kB"
DETAIL:=C2=A0 Invalid size unit: "8kB".
HINT:=C2=A0 Valid units are "bytes", "kB", "MB&quo= t;, "GB", and "TB".

Maybe we should teach pg_size_bytes to cope with that.

Actually thinking though, surely *this* particular ca= se can be spelled as:
SELECT=C2=A0=C2=A0pg_size_bytes(current= _setting('shared_buffers'))

Or if doing it= off pg_settings:

SELECT=C2=A0setting::bigint * pg= _size_bytes(unit) from pg_settings where name=3D'shared_buffers'

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.

--
=C2=A0Magnus= Hagander
=C2=A0Me: https://www.hagander.net/
=C2=A0Work: https://www.redpill-linpro.com/
=
--000000000000735a4c05b1a30618-- From cmt@burggraben.net Wed Oct 14 15:17:26 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiWy-0003h4-0J for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:17:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSiWw-0003aW-Tq for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:17:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiWw-0003aP-Mh for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:17:30 +0000 Received: from smtp.burggraben.net ([2a01:4f8:140:510a::3]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSiWu-0000nt-BN for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:17:30 +0000 Received: from elch.exwg.net (elch.exwg.net [IPv6:2001:470:7120:1:127b:44ff:fe4f:148d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "elch.exwg.net", Issuer "Christoph Moench-Tegeder" (verified OK)) by smtp.burggraben.net (Postfix) with ESMTPS id EC3E5C0031C; Wed, 14 Oct 2020 17:17:26 +0200 (CEST) Received: by elch.exwg.net (Postfix, from userid 1000) id 71FBA13987A; Wed, 14 Oct 2020 17:17:26 +0200 (CEST) Date: Wed, 14 Oct 2020 17:17:26 +0200 From: Christoph Moench-Tegeder To: Magnus Hagander Cc: Thomas Kellerer , pgsql-general Subject: Re: Parameter value from (mb/gb) to bytes Message-ID: <20201014151726.GA50753@elch.exwg.net> References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.14.7 (2020-08-29) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ## Magnus Hagander (magnus@hagander.net): > 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 :) More self-contained: select pg_size_bytes(setting) * pg_size_bytes(unit) from pg_settings where name = 'shared_buffers'; I guess that's what that unit column is there for. Regards, Christoph -- Spare Space From tgl@sss.pgh.pa.us Wed Oct 14 15:23:20 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSicl-0003t6-21 for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:23:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSicj-00080e-6k for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:23:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSici-00080K-Vk for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:23:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSicg-0000qj-Ah for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:23:28 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 09EFNKuT3602056; Wed, 14 Oct 2020 11:23:20 -0400 From: Tom Lane To: Magnus Hagander cc: Thomas Kellerer , pgsql-general Subject: Re: Parameter value from (mb/gb) to bytes In-reply-to: References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> <3601486.1602688239@sss.pgh.pa.us> Comments: In-reply-to Magnus Hagander message dated "Wed, 14 Oct 2020 17:16:57 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3602054.1602689000.1@sss.pgh.pa.us> Date: Wed, 14 Oct 2020 11:23:20 -0400 Message-ID: <3602055.1602689000@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Magnus Hagander writes: > On Wed, Oct 14, 2020 at 5:10 PM Tom Lane 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 From raulkaubi@gmail.com Wed Oct 14 15:34:55 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSioW-0004P7-W2 for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:35:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSioV-0001WM-3G for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:35:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSioU-0001WE-Oa for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:35:38 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSioO-0007Hg-Bm for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:35:37 +0000 Received: by mail-ot1-x333.google.com with SMTP id 32so32699otm.3 for ; Wed, 14 Oct 2020 08:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8vHKn8hBw8OHEO2jiFXzFq/xHIHcw4PMkw73EDHfJSM=; b=eknFe6HcKY0KMqLxxxBiwAv4PDFmZjQ7yD9bduqd5VvMk1fnsL2qkab2ZKDiiIDCCa TAge36lWX338vaL0dBFnt5IbrUES/DsilqiZf7AHdneu47PGaCMVtVJOCErs+6DyDTvE yhk10c/ALa3GSnsgWiLBTXkBYaoyRHRvHm+EzntVNbDAS8HbqFGavIeebHUqVsJGIUIE tm/ZShYc4x2yqa6qNM4WvhqdhbUf5JiTBD01kyguyNCOruOT3MUsQuqQ71wSkX25zRRq zGr/eKqB7byqbUpS9HKWBNZM0mDkXBg/3euE5aU7uSJfis1QWWXPimV1s1vhb8YmhwKr hCdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8vHKn8hBw8OHEO2jiFXzFq/xHIHcw4PMkw73EDHfJSM=; b=Cz1zHGfgR9kPjwpMwIoyhCBc7+aJ2ECidXO3BqNczsz9dVaJ66Jhk699ajNPs7TCKX owolwZKs3IS689Iwlb4u49sjsyUeliZRkTOh5LRb5hjDdokK5BGWDErBDmY/VNy8WFYz rPkJWBU6gls3v1hwlvD0ZbkENso+vaTPC06SUX8fTvjx1mD/GeLMpDGvkjCAycCjkx3Y 5nfTE+Xsc37+XiHw++McGTXSYufJlNb9qNyB+3M5XpWYnMfbsquDA3Xt76dk9IedrrKG C/7jwa4bU7FoiNiGbJfE+VUKuzatkDjRgfRiKbes+QywzS5fe0UeIWl+E9C504zj98Nl S2EA== X-Gm-Message-State: AOAM530/W7qDJFCXWy6xpAo4g/PCZVq53mPhIcZafTNFsYdVzeMHPCHf iq0yngbMJQOrEhhWmliVxgqv1lRSw+jyWfhNUbA= X-Google-Smtp-Source: ABdhPJwFMuDgrzeOTeG8s/oEFMDJKD7GnCvXb6ijBnajduqWlY84/PtqrtLsvO5PZ+zJnKoq+yxXQGm9uOD+vlKeo7c= X-Received: by 2002:a05:6830:310f:: with SMTP id b15mr3974152ots.208.1602689731670; Wed, 14 Oct 2020 08:35:31 -0700 (PDT) MIME-Version: 1.0 References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> <3601486.1602688239@sss.pgh.pa.us> <3602055.1602689000@sss.pgh.pa.us> In-Reply-To: <3602055.1602689000@sss.pgh.pa.us> From: Raul Kaubi Date: Wed, 14 Oct 2020 18:34:55 +0300 Message-ID: Subject: Re: Parameter value from (mb/gb) to bytes To: Tom Lane Cc: Magnus Hagander , Thomas Kellerer , pgsql-general Content-Type: multipart/alternative; boundary="00000000000024372605b1a3480d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --00000000000024372605b1a3480d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Thanks for all the replies. So at first, I did this: select (pg_size_bytes(setting) * (select setting from pg_settings where name =3D 'block_size')::int) as shared_buffers from pg_settings where name = =3D '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 () kirjutas kuup=C3=A4eval K, 14. oktoo= ber 2020 kell 18:23: > Magnus Hagander writes: > > On Wed, Oct 14, 2020 at 5:10 PM Tom Lane wrote: > >> It's fairly annoying that this doesn't work: > >> regression=3D# select pg_size_bytes(setting||' '||unit) from pg_settin= gs > >> where name =3D '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=3D'shared_buffers' > > No, because that will fail for any unit other than '8kB', eg > > regression=3D# 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 wro= ng > > results. > > Yeah, that's definitely a risk. Given that current_setting() already doe= s > what's needed, that's probably a better answer. > > regards, tom lane > > > --00000000000024372605b1a3480d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

Thanks for all the replies.

So at first, I did this:
select (pg_size_bytes(s= etting) * (select setting from pg_settings where name =3D 'block_size&#= 39;)::int) as shared_buffers from pg_settings where name =3D 'shared_bu= ffers';

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

Regards
Raul

Konta= kt Tom Lane (<tgl@sss.pgh.pa.us= >) kirjutas kuup=C3=A4eval K, 14. oktoober 2020 kell 18:23:
Magnus Hagander <magnus@hagander.net&g= t; 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=3D# select pg_size_bytes(setting||' '||unit) fr= om pg_settings
>> where name =3D 'shared_buffers';

> Actually thinking though, surely *this* particular case can be spelled= as:
> SELECT=C2=A0 pg_size_bytes(current_setting('shared_buffers'))<= br>
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=3D'shared_buffers'

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

regression=3D# select pg_size_bytes('MB');
ERROR:=C2=A0 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 wr= ong
> results.

Yeah, that's definitely a risk.=C2=A0 Given that current_setting() alre= ady does
what's needed, that's probably a better answer.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane


--00000000000024372605b1a3480d-- From magnus@hagander.net Wed Oct 14 15:38:02 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSir4-0004UF-Nx for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:38:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kSir3-00063b-NB for pgsql-general@arkaria.postgresql.org; Wed, 14 Oct 2020 15:38:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSir3-00063U-Fw for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:38:17 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kSir0-0000xc-TY for pgsql-general@lists.postgresql.org; Wed, 14 Oct 2020 15:38:17 +0000 Received: by mail-lj1-x22d.google.com with SMTP id m20so3695405ljj.5 for ; Wed, 14 Oct 2020 08:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hagander-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/gtWnPrksQrlKkQMfuY2NKdswxHtNIsqoa+MHXAiDxY=; b=K99V04EAAREPr7qZ0EWMxMlqaXTGKDGr6M1HTOZ2yzXanMxuzptY/Kyy1S13HYSPkA WomQRooU041Z8AzlJaa1fEnXiG2C73EUaE30cdct45lvaji3i4kP6UzUS516IcXtRTZG JoZQc10sjn5w9pxetqEb72tLZyZdYnGVdmW0DXQ8xSSfEkZw5/PO7G5z9TU69DkAFOt6 HH33twvBvSQlj1/zo/IJVyz60c7WK1T6m2+KoqDvIL8poL9Fc8H03uU5Rd2eaTrahCdg tY/T/GS7YvSyIsg9mrmE6w3pktNhDccVRWrdzXQxa3HtDl09I29bY4DiUCsdkPTdXEru Xe9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/gtWnPrksQrlKkQMfuY2NKdswxHtNIsqoa+MHXAiDxY=; b=IC5CNqxB4oys9GV/Aj6zu4v/IBP+wJgVbGVLiBF2HTGQywQ7u+aBRasc/EUmy9oVlY 0hgjhzuXXLmACdsGF2pClzEMzy/gc7bd0llCgm0WPqTPqcLNWRUTNX2Opn4b4jYXYrIN Y80kkuYa0C9HEDu+b7OnHyJr4UZESWq+PC41iH7s2H7L+nAha04nJxM5FoLl7sqm6k7K 6R437DstTTtpKjvj0mh6oEgQtC6yLc7TegKFXMzKxzA3mZNQdZ6XmX5g0PBKf8XWf95R 3OkuuOl2/G4X4Z49CIBxYW5HZD1A798zhoO5iQxbohK/uXt6rP++ylevmVny2dJvbP0D JBSg== X-Gm-Message-State: AOAM5339tNs1k5H+bdBWE4NL2D+IGsGwphqsubj9GknvnAcs6PeJiCw5 SW6+JTdcvKB/Qj7Dhny4tY7KdHQzUKOHiaZDIOUdRg== X-Google-Smtp-Source: ABdhPJyW44x77YzBdW53i/4opAgx48yE16F/IGtX2in+8EOkWCZfCfhtyXxYCgdSoBt2MxAW986xq8RY8gjGvFWWXpE= X-Received: by 2002:a2e:984e:: with SMTP id e14mr1913945ljj.94.1602689894223; Wed, 14 Oct 2020 08:38:14 -0700 (PDT) MIME-Version: 1.0 References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> <3601486.1602688239@sss.pgh.pa.us> <3602055.1602689000@sss.pgh.pa.us> In-Reply-To: <3602055.1602689000@sss.pgh.pa.us> From: Magnus Hagander Date: Wed, 14 Oct 2020 17:38:02 +0200 Message-ID: Subject: Re: Parameter value from (mb/gb) to bytes To: Tom Lane Cc: Thomas Kellerer , pgsql-general Content-Type: multipart/alternative; boundary="000000000000d4c63b05b1a351b5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000d4c63b05b1a351b5 Content-Type: text/plain; charset="UTF-8" On Wed, Oct 14, 2020 at 5:23 PM Tom Lane wrote: > Magnus Hagander writes: > > On Wed, Oct 14, 2020 at 5:10 PM Tom Lane 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" > Right, but it would certainly work for *this* case using pg_asettings, is what I meant. That said, I think it'd then actually be better to teach pg_size_bytes to know that "MB" is the same as "1MB" and parse that. That might be something that would actually be useful in other cases as well -- basically as a way to get conversion units in general. Basically if the string is "unit only" then consider that as "1 unit". -- Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/ --000000000000d4c63b05b1a351b5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Oct 14, 2020 at 5:23 PM Tom L= ane <tgl@sss.pgh.pa.us> wrot= e:
Magnus Hagand= er <magnus@haga= nder.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=3D# select pg_size_bytes(setting||' '||unit) fr= om pg_settings
>> where name =3D 'shared_buffers';

> Actually thinking though, surely *this* particular case can be spelled= as:
> SELECT=C2=A0 pg_size_bytes(current_setting('shared_buffers'))<= br>
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=3D'shared_buffers'

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

regression=3D# select pg_size_bytes('MB');
ERROR:=C2=A0 invalid size: "MB"

Right, but it would certainly work for *this* case using pg_asettings, i= s what I meant.

That said, I think it'd then a= ctually be better to teach pg_size_bytes to know that "MB" is the= same as "1MB" and parse that. That might be something that would= actually be useful in other cases as well -- basically as a way to get con= version units in general. Basically if the string is "unit only" = then consider that as "1 unit".

--
=
=C2=A0Magn= us Hagander
=C2=A0Me: https://www.hagander.net/
=C2=A0Work: https://www.redpill-linpro.com/
--000000000000d4c63b05b1a351b5-- From raulkaubi@gmail.com Fri Nov 20 07:59:03 2020 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kg1Ka-0007NB-OE for pgsql-general@arkaria.postgresql.org; Fri, 20 Nov 2020 07:59:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kg1KZ-0006Yq-4T for pgsql-general@arkaria.postgresql.org; Fri, 20 Nov 2020 07:59:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kg1KY-0006Yh-Mp for pgsql-general@lists.postgresql.org; Fri, 20 Nov 2020 07:59:42 +0000 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kg1KW-0004XV-Aj for pgsql-general@lists.postgresql.org; Fri, 20 Nov 2020 07:59:41 +0000 Received: by mail-oi1-x22c.google.com with SMTP id m13so9495311oih.8 for ; Thu, 19 Nov 2020 23:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=97wmrmIiyiWsKKMaSQstG2QJ7rqu06NlxTrfxcIfcmo=; b=B6Xp4zfgkJGAe8RaMM+q6Tjwzbvree+ocBNSEjbv3iAnJmDHDT2rEpVEDEslnKcn2Q WdllPPsbDa9sHRykJpMCvrrv5xyz7WQ1qPg15/XWjzSU8WypbYXQLVmm8QbIBVqyEOJC X428sURyxhnvvujkregw/wxXcGtTM/ZBBb7CZCTJtdl3TpF/298u7WJKcFjjDuQPWtfv bQrgBsyFUXCr+PJTf+bsZLkEnXs94eZUpe8hpjfqOE59v3Bky3jq9HvEpe+7kkBpYvXA z3XcuMPdQcj08DuwnKH4+rzTE4OaJnJ6Qmza6B4Ym8WYqp/foJn2Vrk2j6+vOEcZE47v NdcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=97wmrmIiyiWsKKMaSQstG2QJ7rqu06NlxTrfxcIfcmo=; b=YFUeBO8rTOgBPKZSr1+xTKU7oRScQgQjbUvT502AHe0b8qAD4YftZTVVC8hLe1d+TF yqDTgfcOHUmXmtMgyxjcvnKS5lCOLtQGAPOjACHV/ecrR20qLa6wvr2c99r8nXBRfaEB MDHIYIjH95vmL07O/bKGuD7p8Tjbm0AqQqOWlSY+2gaTFCMR3skM6UCeYSLe5n6FVLKl KHNSENem+BOjBqMKZlNqB/m8R/is7WavlQ63dj4b536E/g+GrJTUDUTIq8C9/e+3jFwr 1JisGpuLhE4A4Qmtvag+6U4hZtFhlcb3N8qRDaz2w3sxnEnwUgn6ycdyxwO1d55HE2cr YJIw== X-Gm-Message-State: AOAM530sGKWGnxp3PEKsnSyP55nFTU+ev7sOd8SwgdEQeR7c22rBQtRn mGDRC8dhoTHhBK8mx8K+NiYFFw6YlR7OiwegHrQ= X-Google-Smtp-Source: ABdhPJwhREoEsI0CA00gLp/CLtJs0TczyuLbLlVK1WO3h6gbgTD78zeUPfdAemH/XiSeESwXqp/WizTIPuY5o0Z/8Jk= X-Received: by 2002:aca:5e57:: with SMTP id s84mr5693067oib.102.1605859179603; Thu, 19 Nov 2020 23:59:39 -0800 (PST) MIME-Version: 1.0 References: <6cbca2bcda734464a1be9f7d7380ff33@rik.ee> <3601486.1602688239@sss.pgh.pa.us> <3602055.1602689000@sss.pgh.pa.us> In-Reply-To: From: Raul Kaubi Date: Fri, 20 Nov 2020 09:59:03 +0200 Message-ID: Subject: Re: Parameter value from (mb/gb) to bytes To: Magnus Hagander Cc: Tom Lane , Thomas Kellerer , pgsql-general Content-Type: multipart/alternative; boundary="000000000000f5aae005b48539a4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000f5aae005b48539a4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Thanks, you solution works for most of the databases. But now I noticed that we have single 9.5 version also. And seems like this function *pg_size_bytes* came from 9.6 # psql -U postgres -Atc "select > pg_size_bytes(current_setting('shared_buffers'));" > ERROR: function pg_size_bytes(text) does not exist > LINE 1: select pg_size_bytes(current_setting('shared_buffers')); > ^ > HINT: No function matches the given name and argument types. You might > need to add explicit type casts. Do you perhaps happen to know a way how to get this to work in 9.5 also..? Thanks again. Regards Raul Kontakt Magnus Hagander () kirjutas kuup=C3=A4eval K, = 14. oktoober 2020 kell 18:38: > > > On Wed, Oct 14, 2020 at 5:23 PM Tom Lane wrote: > >> Magnus Hagander writes: >> > On Wed, Oct 14, 2020 at 5:10 PM Tom Lane wrote: >> >> It's fairly annoying that this doesn't work: >> >> regression=3D# select pg_size_bytes(setting||' '||unit) from pg_setti= ngs >> >> where name =3D '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=3D'shared_buffers' >> >> No, because that will fail for any unit other than '8kB', eg >> >> regression=3D# select pg_size_bytes('MB'); >> ERROR: invalid size: "MB" >> > > Right, but it would certainly work for *this* case using pg_asettings, is > what I meant. > > That said, I think it'd then actually be better to teach pg_size_bytes to > know that "MB" is the same as "1MB" and parse that. That might be somethi= ng > that would actually be useful in other cases as well -- basically as a wa= y > to get conversion units in general. Basically if the string is "unit only= " > then consider that as "1 unit". > > -- > Magnus Hagander > Me: https://www.hagander.net/ > Work: https://www.redpill-linpro.com/ > --000000000000f5aae005b48539a4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

Thanks, you solution works for most = of the databases. But now I noticed that we have single 9.5 version also.
And seems like this function=C2=A0pg_size_bytes=C2=A0came f= rom 9.6

# psql -U postgres -Atc "select pg_size_bytes(current_setting('= shared_buffers'));"
ERROR: =C2=A0function pg_size_bytes(text) d= oes not exist
LINE 1: select pg_size_bytes(current_setting('shared_b= uffers'));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0^<= br>HINT: =C2=A0No function matches the given name and argument types. You m= ight need to add explicit type casts.

Do yo= u perhaps happen to know a way how to get this to work in 9.5 also..?
=

Thanks again.

Regards
Raul

Kontakt Magnus Hagander (<magnus@hagander.net>) kirjutas kuup=C3=A4eval K, 14. oktoober 2= 020 kell 18:38:
=


=
On Wed, Oct 14, 2020 at 5:23 PM Tom L= ane <tgl@sss.pgh.= pa.us> wrote:
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=3D# select pg_size_bytes(setting||' '||unit) fr= om pg_settings
>> where name =3D 'shared_buffers';

> Actually thinking though, surely *this* particular case can be spelled= as:
> SELECT=C2=A0 pg_size_bytes(current_setting('shared_buffers'))<= br>
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=3D'shared_buffers'

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

regression=3D# select pg_size_bytes('MB');
ERROR:=C2=A0 invalid size: "MB"

Right, but it would certainly work for *this* case using pg_asettings, i= s what I meant.

That said, I think it'd then a= ctually be better to teach pg_size_bytes to know that "MB" is the= same as "1MB" and parse that. That might be something that would= actually be useful in other cases as well -- basically as a way to get con= version units in general. Basically if the string is "unit only" = then consider that as "1 unit".

--
=
=C2=A0Magnus Hagander
=C2=A0Me: <= a href=3D"http://www.hagander.net/" target=3D"_blank">https://www.hagander.= net/
=C2=A0Work: https://www.redpill-linpro.com/
--000000000000f5aae005b48539a4--