mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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
This commit is contained in:
@ -17766,6 +17766,9 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
|
||||
<indexterm>
|
||||
<primary>pg_relation_size</primary>
|
||||
</indexterm>
|
||||
<indexterm>
|
||||
<primary>pg_size_bytes</primary>
|
||||
</indexterm>
|
||||
<indexterm>
|
||||
<primary>pg_size_pretty</primary>
|
||||
</indexterm>
|
||||
@ -17836,6 +17839,15 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
|
||||
Shorthand for <literal>pg_relation_size(..., 'main')</literal>
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
<literal><function>pg_size_bytes(<type>text</type>)</function></literal>
|
||||
</entry>
|
||||
<entry><type>bigint</type></entry>
|
||||
<entry>
|
||||
Converts a size in human-readable format with size units into bytes
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
<literal><function>pg_size_pretty(<type>bigint</type>)</function></literal>
|
||||
@ -17968,10 +17980,26 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
|
||||
|
||||
<para>
|
||||
<function>pg_size_pretty</> can be used to format the result of one of
|
||||
the other functions in a human-readable way, using kB, MB, GB or TB as
|
||||
appropriate.
|
||||
the other functions in a human-readable way, using bytes, kB, MB, GB or TB
|
||||
as appropriate.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<function>pg_size_bytes</> can be used to get the size in bytes from a
|
||||
string in human-readable format. The input may have units of bytes, kB,
|
||||
MB, GB or TB, and is parsed case-insensitively. If no units are specified,
|
||||
bytes are assumed.
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
The units kB, MB, GB and TB used by the functions
|
||||
<function>pg_size_pretty</> and <function>pg_size_bytes</> are defined
|
||||
using powers of 2 rather than powers of 10, so 1kB is 1024 bytes, 1MB is
|
||||
1024<superscript>2</> = 1048576 bytes, and so on.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<para>
|
||||
The functions above that operate on tables or indexes accept a
|
||||
<type>regclass</> argument, which is simply the OID of the table or index
|
||||
|
Reference in New Issue
Block a user