X-Original-To: pgsql-admin-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F27349FB214 for ; Fri, 18 Aug 2006 16:31:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 83473-03-4 for ; Fri, 18 Aug 2006 16:29:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from stash.illumen.com (unknown [64.207.29.137]) by postgresql.org (Postfix) with ESMTP id 5E49B9FB3EF for ; Fri, 18 Aug 2006 16:26:26 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Inserting a timed delay in a pl/pgsql procedure Date: Fri, 18 Aug 2006 13:26:24 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Inserting a timed delay in a pl/pgsql procedure Thread-Index: AcbC26rhzBhq17PDT4iDizah/rnebwABbdPg From: "Benjamin Krajmalnik" To: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.043 tagged_above=0 required=5 tests=AWL, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/224 X-Sequence-Number: 22767 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 =3D true and accountno=3D423 LOOP returndate :=3D fn_calcteststats(myrecord.kstestssysid); nextexecdate :=3D 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.