Re: proposal: rounding up time value less than its unit.

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Tomonari Katsumata <katsumata(dot)tomonari(at)po(dot)ntts(dot)co(dot)jp>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: rounding up time value less than its unit.
Date: 2014-08-21 12:00:11
Message-ID: 53F5DF4B.7020602@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 07/10/2014 09:52 AM, Tomonari Katsumata wrote:
> Hi,
>
> Several couple weeks ago, I posted a mail to pgsql-doc.
> http://www.postgresql.org/message-id/53992FF8.2060702@po.ntts.co.jp
>
> In this thread, I concluded that it's better to
> round up the value which is less than its unit.
> Current behavior (rounding down) has undesirable setting risk,
> because some GUCs have special meaning for 0.
>
> And then I made a patch for this.
> Please check the attached patch.

The patch also rounds a zero up to one. A naked zero with no unit is not
affected, but e.g if you have "log_rotation_age=0s", it will not disable
the feature as you might expect, but set it to 1 minute. Should we do
something about that?

If we're going to explain the rounding up in the manual, we also need to
explain the normal rule, which is to round down. How about this:

--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -44,6 +44,15 @@
(seconds), <literal>min</literal> (minutes), <literal>h</literal>
(hours), and <literal>d</literal> (days). Note that the multiplier
for memory units is 1024, not 1000.
+
+ <para>
+ If a memory or time setting is specified with more precision than the
+ implicit unit of the setting, it is rounded down. However, if
rounding
+ down would yield a zero, it is rounded up to one instead. For
example,
+ the implicit unit of <varname>log_rotation_age</varname is
minutes, so if
+ you set it to <literal>150s</literal>, it will be rounded down to two
+ minutes. However, if you set it to <literal>10s</literal>, it will be
+ rounded up to one minute.
</para>

- Heikki

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2014-08-21 13:18:22 Re: Removing dependency to wsock32.lib when compiling code on WIndows
Previous Message Heikki Linnakangas 2014-08-21 11:21:13 Re: plpgsql.extra_warnings='num_into_expressions'