Re: Sleep functions

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Sleep functions
Date: 2005-08-22 04:40:14
Message-ID: 20050822044014.GA54329@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Aug 21, 2005 at 09:13:20PM -0400, Tom Lane wrote:
> Michael Fuhr <mike(at)fuhr(dot)org> writes:
> > What do people think of exposing pg_usleep() to the user?
>
> I'm not real enthused about it. Generally speaking, a sleep() on the
> database side means you are idling while holding locks, and that does
> not seem like something we want to encourage people to do.

I don't see how providing a server-side sleep() encourages idling
while holding locks any more than people can already do. In that
respect, is it any different than a client-side sleep() or going
to lunch with an open transaction in psql?

> As other responders noted, it's trivial to program this in any of the
> untrusted PL languages, So what you're really proposing is that we give
> sleep() to non-superusers, and that seems like a bit of a hard sell.
> Let's see a use-case or three.

Sure it's trivial in various languages, even in trusted PL/Tcl:

CREATE FUNCTION sleep(integer) RETURNS void AS $$
after [expr $1 * 1000]
$$ LANGUAGE pltcl STRICT;

So aside from the ways to idle I mentioned above, non-superusers
do have a way to perform a server-side sleep(), at least on systems
that use PL/Tcl. Or is allowing "after" a bug in trusted PL/Tcl?
In any case, I wonder how many people, not having a sleep() function,
effect a delay with a busy loop; an example of such has been posted
in response to the thread in pgsql-admin, and didn't the regression
tests do so until recently? That seems less desirable than a real
sleep().

A few use cases are learning, testing, and debugging: you might
want to slow down operations so you can more easily watch what's
happening, observe how the slowness affects other operations, or
look for application problems related to timing. With a server-side
sleep() those delays can be done with simple queries fed into psql
or another interface that doesn't provide a way to sleep, and a
client-side sleep() wouldn't help if you want to slow down operations
inside a PL/pgSQL function.

To others who've written their own sleep() function: what are you
using it for?

--
Michael Fuhr

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2005-08-22 07:30:01 Re: Sleep functions
Previous Message Satoshi Nagayasu 2005-08-22 02:40:42 Re: Pre-allocated free space for row updating (like PCTFREE)