Re: sleep?

Lists: pgsql-admin
From: Don Drake <dondrake(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: sleep?
Date: 2005-08-21 19:22:25
Message-ID: 6c21003b050821122278e3d7d5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Is there a sleep function in plpgsql? I need to wait a period time (60
seconds) in a while loop.

I didn't see anything in the docs.

Thanks.

-Don

--
Donald Drake
President
Drake Consulting
http://www.drakeconsult.com/
http://www.MailLaunder.com/
http://www.mobilemeridian.com/
312-560-1574


From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-21 20:03:03
Message-ID: 0817d53432c7b8dc53a6cc9c014261e9@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> Is there a sleep function in plpgsql? I need to wait a period time
> 60 seconds) in a while loop.

You will need to us another language, such as plperl. You could
certainly create a sleep function and have your plpgsql call that:

CREATE FUNCTION sleep(INT) RETURNS TEXT LANGUAGE plperl AS
$$
select(undef,undef,undef,shift);
return "Time to wake up!";
$$;

SELECT sleep(2);

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200508211601
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFDCN3BvJuQZxSWSsgRAhtJAKD0QDRWb6kk+AGWHMPQqM7lwRAXKACgpHM0
EkA+7aOQoI3BzgLhkva53mQ=
=hD9m
-----END PGP SIGNATURE-----


From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-21 20:26:14
Message-ID: 4308E366.5020608@presinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Don Drake wrote:
> Is there a sleep function in plpgsql? I need to wait a period time (60
> seconds) in a while loop.
>
> I didn't see anything in the docs.
>
> Thanks.
>
> -Don
>

create or replace function sleep(integer) returns void as $$
return sleep(shift)
$$ language plperlu immutable strict;

select sleep(5);
--(sleeps for 5 seconds)


From: Guido Barosio <gbarosio(at)gmail(dot)com>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-21 21:09:49
Message-ID: f7f6b4c705082114094f41bff7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Don't know about such thing, but I guess that a plpgsql function could help
using datetime var's.
Just a guess, don't know if the optimal solution.
Best wishes,
G.-

On 8/21/05, Don Drake <dondrake(at)gmail(dot)com> wrote:
>
> Is there a sleep function in plpgsql? I need to wait a period time (60
> seconds) in a while loop.
>
> I didn't see anything in the docs.
>
> Thanks.
>
> -Don
>
> --
> Donald Drake
> President
> Drake Consulting
> http://www.drakeconsult.com/
> http://www.MailLaunder.com/ <http://www.maillaunder.com/>
> http://www.mobilemeridian.com/
> 312-560-1574
>
>

--
"Adopting the position that you are smarter than an automatic
optimization algorithm is generally a good way to achieve less
performance, not more" - Tom Lane.


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-21 22:41:33
Message-ID: 20050821224133.GB31904@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Sun, Aug 21, 2005 at 02:22:25PM -0500, Don Drake wrote:
> Is there a sleep function in plpgsql? I need to wait a period time (60
> seconds) in a while loop.

SELECT oid::regprocedure
FROM pg_proc
WHERE proname ILIKE '%sleep%' OR prosrc ILIKE '%sleep%';
oid
-----
(0 rows)

When I need a sleep function on the server side I write one in C,
PL/Perl, PL/Tcl, PL/Python, etc. PostgreSQL 8.0 and later have an
internal pg_usleep() function but it's not exposed to the user. I
asked about exposing it recently but didn't see any replies (it was
in response to a message in pgsql-committers; I suppose I should
have asked in pgsql-hackers instead).

--
Michael Fuhr


From: John DeSoi <desoi(at)pgedit(dot)com>
To: Guido Barosio <gbarosio(at)gmail(dot)com>
Cc: Don Drake <dondrake(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-22 01:43:55
Message-ID: D9712202-F287-4CCF-A9C2-EE8A7E11AD83@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin


On Aug 21, 2005, at 5:09 PM, Guido Barosio wrote:

> Don't know about such thing, but I guess that a plpgsql function
> could help using datetime var's.
>
> Just a guess, don't know if the optimal solution.

Yes, you can write one in plpgsql using timeofday, but it is horribly
inefficient wastes CPU cycles busy looping. I use the version below
for some simple testing, but it is not useful for a production
system. It would be nice to have a sleep function that does not
require anything beyond plpgsql.

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL

create or replace function sleep (integer) returns time as '
declare
seconds alias for $1;
later time;
thetime time;
begin
thetime := timeofday()::timestamp;
later := thetime + (seconds::text || '' seconds'')::interval;
loop
if thetime >= later then
exit;
else
thetime := timeofday()::timestamp;
end if;
end loop;

return later;
end;
' language plpgsql;


From: Don Drake <dondrake(at)gmail(dot)com>
To: John DeSoi <desoi(at)pgedit(dot)com>
Cc: Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-22 13:34:29
Message-ID: 6c21003b05082206341411de2d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Thanks for all of the replies. I recompiled my DB with plperlu and am using
perl's sleep function.

I agree that a basic function (non-CPU intensive sleep) like this should be
built in.

Thanks again.

-Don

On 8/21/05, John DeSoi <desoi(at)pgedit(dot)com> wrote:
>
>
> On Aug 21, 2005, at 5:09 PM, Guido Barosio wrote:
>
> > Don't know about such thing, but I guess that a plpgsql function
> > could help using datetime var's.
> >
> > Just a guess, don't know if the optimal solution.
>
>
> Yes, you can write one in plpgsql using timeofday, but it is horribly
> inefficient wastes CPU cycles busy looping. I use the version below
> for some simple testing, but it is not useful for a production
> system. It would be nice to have a sleep function that does not
> require anything beyond plpgsql.
>
>
> John DeSoi, Ph.D.
> http://pgedit.com/
> Power Tools for PostgreSQL
>
>
>
> create or replace function sleep (integer) returns time as '
> declare
> seconds alias for $1;
> later time;
> thetime time;
> begin
> thetime := timeofday()::timestamp;
> later := thetime + (seconds::text || '' seconds'')::interval;
> loop
> if thetime >= later then
> exit;
> else
> thetime := timeofday()::timestamp;
> end if;
> end loop;
>
> return later;
> end;
> ' language plpgsql;
>

--
Donald Drake
President
Drake Consulting
http://www.drakeconsult.com/
http://www.MailLaunder.com/
http://www.mobilemeridian.com/
312-560-1574


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: John DeSoi <desoi(at)pgedit(dot)com>, Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-22 14:01:33
Message-ID: 20050822140133.GA60020@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Mon, Aug 22, 2005 at 08:34:29AM -0500, Don Drake wrote:
> I agree that a basic function (non-CPU intensive sleep) like this should be
> built in.

It's being discussed in pgsql-hackers:

http://archives.postgresql.org/pgsql-hackers/2005-08/msg00633.php

Do you have any use cases in addition to what's already been
mentioned? Sleeping isn't really a database operation, so there
needs to be some justification for making it a standard function.

--
Michael Fuhr


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: Don Drake <dondrake(at)gmail(dot)com>, John DeSoi <desoi(at)pgedit(dot)com>, Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-22 14:24:37
Message-ID: 200508221424.j7MEObk10012@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Michael Fuhr wrote:
> On Mon, Aug 22, 2005 at 08:34:29AM -0500, Don Drake wrote:
> > I agree that a basic function (non-CPU intensive sleep) like this should be
> > built in.
>
> It's being discussed in pgsql-hackers:
>
> http://archives.postgresql.org/pgsql-hackers/2005-08/msg00633.php
>
> Do you have any use cases in addition to what's already been
> mentioned? Sleeping isn't really a database operation, so there
> needs to be some justification for making it a standard function.

Well, we needed it for our own regression tests, so I assume others
would need it as well.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, Don Drake <dondrake(at)gmail(dot)com>, John DeSoi <desoi(at)pgedit(dot)com>, Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-22 15:56:39
Message-ID: 16418.1124726199@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Michael Fuhr wrote:
>> Do you have any use cases in addition to what's already been
>> mentioned? Sleeping isn't really a database operation, so there
>> needs to be some justification for making it a standard function.

> Well, we needed it for our own regression tests, so I assume others
> would need it as well.

... and you'll notice that the regression test that uses it is still
failing intermittently on some of the buildfarm machines, which rather
calls the whole approach into question ...

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, Don Drake <dondrake(at)gmail(dot)com>, John DeSoi <desoi(at)pgedit(dot)com>, Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-22 16:24:17
Message-ID: 200508221624.j7MGOHg12583@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Michael Fuhr wrote:
> >> Do you have any use cases in addition to what's already been
> >> mentioned? Sleeping isn't really a database operation, so there
> >> needs to be some justification for making it a standard function.
>
> > Well, we needed it for our own regression tests, so I assume others
> > would need it as well.
>
> ... and you'll notice that the regression test that uses it is still
> failing intermittently on some of the buildfarm machines, which rather
> calls the whole approach into question ...

It means that our use of sleep() wasn't the fix, but we need it to try,
didn't we?

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Don Drake <dondrake(at)gmail(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: John DeSoi <desoi(at)pgedit(dot)com>, Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-23 14:42:27
Message-ID: 6c21003b05082307427ea67279@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Sorry for the delay in replying.

The use-case that I have is the following. I'm writing a job-control
tracking sub-system that will store when jobs are started, finished, failed,
etc. I would like to have the ability to have a process that is requesting
to start, to actually wait a specified period time before starting. It could
wait for another job to finish. I'm writing this in plpgsql since I'm
storing status in the db.

-Don

On 8/22/05, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
>
> On Mon, Aug 22, 2005 at 08:34:29AM -0500, Don Drake wrote:
> > I agree that a basic function (non-CPU intensive sleep) like this should
> be
> > built in.
>
> It's being discussed in pgsql-hackers:
>
> http://archives.postgresql.org/pgsql-hackers/2005-08/msg00633.php
>
> Do you have any use cases in addition to what's already been
> mentioned? Sleeping isn't really a database operation, so there
> needs to be some justification for making it a standard function.
>
> --
> Michael Fuhr
>

--
Donald Drake
President
Drake Consulting
http://www.drakeconsult.com/
http://www.MailLaunder.com/
http://www.mobilemeridian.com/
312-560-1574


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, John DeSoi <desoi(at)pgedit(dot)com>, Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-23 15:07:40
Message-ID: 430B3BBC.7010607@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Don Drake wrote:

> Sorry for the delay in replying.
>
> The use-case that I have is the following. I'm writing a job-control
> tracking sub-system that will store when jobs are started, finished,
> failed, etc. I would like to have the ability to have a process that
> is requesting to start, to actually wait a specified period time
> before starting. It could wait for another job to finish. I'm
> writing this in plpgsql since I'm storing status in the db.

I would write a userspace daemon that ran outside of PostgreSQL to call
your procedures as you need them to run.

Sincerely,

Joshua D. Drake


From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Don Drake <dondrake(at)gmail(dot)com>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, John DeSoi <desoi(at)pgedit(dot)com>, Guido Barosio <gbarosio(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-23 18:34:36
Message-ID: 20050823183436.GM43820@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On a related note, you might be interested in
http://pgfoundry.org/projects/pgjob/

On Tue, Aug 23, 2005 at 09:42:27AM -0500, Don Drake wrote:
> Sorry for the delay in replying.
>
> The use-case that I have is the following. I'm writing a job-control
> tracking sub-system that will store when jobs are started, finished, failed,
> etc. I would like to have the ability to have a process that is requesting
> to start, to actually wait a specified period time before starting. It could
> wait for another job to finish. I'm writing this in plpgsql since I'm
> storing status in the db.
>
> -Don
>
> On 8/22/05, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
> >
> > On Mon, Aug 22, 2005 at 08:34:29AM -0500, Don Drake wrote:
> > > I agree that a basic function (non-CPU intensive sleep) like this should
> > be
> > > built in.
> >
> > It's being discussed in pgsql-hackers:
> >
> > http://archives.postgresql.org/pgsql-hackers/2005-08/msg00633.php
> >
> > Do you have any use cases in addition to what's already been
> > mentioned? Sleeping isn't really a database operation, so there
> > needs to be some justification for making it a standard function.
> >
> > --
> > Michael Fuhr
> >
>
>
>
> --
> Donald Drake
> President
> Drake Consulting
> http://www.drakeconsult.com/
> http://www.MailLaunder.com/
> http://www.mobilemeridian.com/
> 312-560-1574

--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com 512-569-9461