Обсуждение: pgsql: Add pg_size_bytes() to parse human-readable size strings.

Поиск
Список
Период
Сортировка

pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Dean Rasheed
Дата:
Add pg_size_bytes() to parse human-readable size strings.

This will parse strings in the format produced by pg_size_pretty() and
return sizes in bytes. This allows queries to be written with clauses
like "pg_total_relation_size(oid) > pg_size_bytes('10 GB')".

Author: Pavel Stehule with various improvements by Vitaly Burovoy
Discussion: http://www.postgresql.org/message-id/CAFj8pRD-tGoDKnxdYgECzA4On01_uRqPrwF-8LdkSE-6bDHp0w@mail.gmail.com
Reviewed-by: Vitaly Burovoy, Oleksandr Shulgin, Kyotaro Horiguchi,
    Michael Paquier and Robert Haas

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/53874c5228fe16589a4d01b3e1fab3678e0fd8e3

Modified Files
--------------
doc/src/sgml/func.sgml               |  32 +++++++-
src/backend/utils/adt/dbsize.c       | 149 +++++++++++++++++++++++++++++++++++
src/include/catalog/catversion.h     |   2 +-
src/include/catalog/pg_proc.h        |   2 +
src/include/utils/builtins.h         |   1 +
src/test/regress/expected/dbsize.out | 109 +++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql      |  39 +++++++++
7 files changed, 331 insertions(+), 3 deletions(-)


Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Michael Paquier
Дата:
On Sat, Feb 20, 2016 at 7:07 PM, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> Add pg_size_bytes() to parse human-readable size strings.
>
> This will parse strings in the format produced by pg_size_pretty() and
> return sizes in bytes. This allows queries to be written with clauses
> like "pg_total_relation_size(oid) > pg_size_bytes('10 GB')".
>
> Author: Pavel Stehule with various improvements by Vitaly Burovoy
> Discussion: http://www.postgresql.org/message-id/CAFj8pRD-tGoDKnxdYgECzA4On01_uRqPrwF-8LdkSE-6bDHp0w@mail.gmail.com
> Reviewed-by: Vitaly Burovoy, Oleksandr Shulgin, Kyotaro Horiguchi,
>     Michael Paquier and Robert Haas

Happy first commit.
--
Michael


Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Michael Paquier
Дата:
On Sat, Feb 20, 2016 at 7:12 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> On Sat, Feb 20, 2016 at 7:07 PM, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
>> Add pg_size_bytes() to parse human-readable size strings.
>>
>> This will parse strings in the format produced by pg_size_pretty() and
>> return sizes in bytes. This allows queries to be written with clauses
>> like "pg_total_relation_size(oid) > pg_size_bytes('10 GB')".
>>
>> Author: Pavel Stehule with various improvements by Vitaly Burovoy
>> Discussion: http://www.postgresql.org/message-id/CAFj8pRD-tGoDKnxdYgECzA4On01_uRqPrwF-8LdkSE-6bDHp0w@mail.gmail.com
>> Reviewed-by: Vitaly Burovoy, Oleksandr Shulgin, Kyotaro Horiguchi,
>>     Michael Paquier and Robert Haas
>
> Happy first commit.

And happy first buildfarm breakage :)
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=termite&dt=2016-02-20%2010%3A10%3A07
--
Michael


Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Dean Rasheed
Дата:
On 20 February 2016 at 10:12, Michael Paquier <michael.paquier@gmail.com> wrote:
> Happy first commit.

Arg. Not so much.

Looks like I broke something -- looking into it now :-(

Regards,
Dean


Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Vik Fearing
Дата:
On 02/20/2016 11:17 AM, Dean Rasheed wrote:
> On 20 February 2016 at 10:12, Michael Paquier <michael.paquier@gmail.com> wrote:
>> Happy first commit.
>
> Arg. Not so much.
>
> Looks like I broke something -- looking into it now :-(

Happy first commit anyway!
--
Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support


Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Michael Paquier
Дата:
On Sat, Feb 20, 2016 at 7:17 PM, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> On 20 February 2016 at 10:12, Michael Paquier <michael.paquier@gmail.com> wrote:
>> Happy first commit.
>
> Arg. Not so much.
>
> Looks like I broke something -- looking into it now :-(

The terabyte conversion is at fault:
Expected:
!  -1tb      |    -1099511627776
Result:
!  -1tb      |            -1

+       else if (pg_strcasecmp(strptr, "gb") == 0)
+           multiplier = 1024 * 1024 * 1024;
+       else if (pg_strcasecmp(strptr, "tb") == 0)
+           multiplier = 1024 * 1024 * 1024 * 1024L;
Why adding an 'L' here?
--
Michael


Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Dean Rasheed
Дата:
On 20 February 2016 at 10:33, Michael Paquier <michael.paquier@gmail.com> wrote:
> On Sat, Feb 20, 2016 at 7:17 PM, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
>> On 20 February 2016 at 10:12, Michael Paquier <michael.paquier@gmail.com> wrote:
>>> Happy first commit.
>>
>> Arg. Not so much.
>>
>> Looks like I broke something -- looking into it now :-(
>
> The terabyte conversion is at fault:
> Expected:
> !  -1tb      |    -1099511627776
> Result:
> !  -1tb      |            -1
>
> +       else if (pg_strcasecmp(strptr, "gb") == 0)
> +           multiplier = 1024 * 1024 * 1024;
> +       else if (pg_strcasecmp(strptr, "tb") == 0)
> +           multiplier = 1024 * 1024 * 1024 * 1024L;
> Why adding an 'L' here?

Ah, looks like it needs to be 'LL' because it needs to be a 64-bit literal.

Regards,
Dean


Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Pavel Stehule
Дата:


2016-02-20 11:07 GMT+01:00 Dean Rasheed <dean.a.rasheed@gmail.com>:
Add pg_size_bytes() to parse human-readable size strings.

This will parse strings in the format produced by pg_size_pretty() and
return sizes in bytes. This allows queries to be written with clauses
like "pg_total_relation_size(oid) > pg_size_bytes('10 GB')".

Author: Pavel Stehule with various improvements by Vitaly Burovoy
Discussion: http://www.postgresql.org/message-id/CAFj8pRD-tGoDKnxdYgECzA4On01_uRqPrwF-8LdkSE-6bDHp0w@mail.gmail.com
Reviewed-by: Vitaly Burovoy, Oleksandr Shulgin, Kyotaro Horiguchi,
    Michael Paquier and Robert Haas

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/53874c5228fe16589a4d01b3e1fab3678e0fd8e3

Modified Files
--------------
doc/src/sgml/func.sgml               |  32 +++++++-
src/backend/utils/adt/dbsize.c       | 149 +++++++++++++++++++++++++++++++++++
src/include/catalog/catversion.h     |   2 +-
src/include/catalog/pg_proc.h        |   2 +
src/include/utils/builtins.h         |   1 +
src/test/regress/expected/dbsize.out | 109 +++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql      |  39 +++++++++
7 files changed, 331 insertions(+), 3 deletions(-)

great :)

Thank you very much

Regards

Pavel
 


--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

Re: pgsql: Add pg_size_bytes() to parse human-readable size strings.

От
Joe Conway
Дата:
On 02/20/2016 02:32 AM, Vik Fearing wrote:
> On 02/20/2016 11:17 AM, Dean Rasheed wrote:
>> On 20 February 2016 at 10:12, Michael Paquier <michael.paquier@gmail.com> wrote:
>>> Happy first commit.
>>
>> Arg. Not so much.
>>
>> Looks like I broke something -- looking into it now :-(
>
> Happy first commit anyway!
>

+1

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development


Вложения