From: Benjamin Krajmalnik <kraj@illumen.com>
To: pgsql-admin@postgresql.org
Subject: Inserting a timed delay in a pl/pgsql procedure
Date: Fri, 18 Aug 2006 13:26:24 -0600
Message-ID: <BF337097BDD9D849A2F4B818DDB27987252603@stash.stackdump.local> (raw)
I have a problem right now where the execution time of a scheduled
stored procedure is creating an issue with our background data logging
system.
Initially I thought it may be caused due to table locks or the like, but
after much testing I have ruled that out, since data is being inserted
while the scheduled SP runs.
The problem cause is one over which unfortunately I have no control.
However, I wanted to run a test and see if I cuold minimize the problem
by inserting a delay in the stored procedure so that after each loop of
the data aggregation, it "sleeps" for a second or so to let the
backround logger despool its queue.
I tried the following:
FOR myrecord in select * from tblkstests where stats = true and
accountno=423 LOOP
returndate := fn_calcteststats(myrecord.kstestssysid);
nextexecdate := returndate + interval '0.25 second';
LOOP
EXIT when current_timestamp > nextexecdate;
END LOOP;
END LOOP;
However, it appears that current_timestamp is not being recalculated.
Any ideas? While normally we want the stored procedures to run as
quickly as possible, this is a case where I need to insert a delay.
I guess an option would be to place a counter and loop through it, but
it does not allow me the control I relly need.
I am not sure this will resolve the problem, but it's a start.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: kraj@illumen.com
Subject: Re: Inserting a timed delay in a pl/pgsql procedure
In-Reply-To: <BF337097BDD9D849A2F4B818DDB27987252603@stash.stackdump.local>
References: <BF337097BDD9D849A2F4B818DDB27987252603@stash.stackdump.local>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox