Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7HdB-0007Rg-Bt for pgsql-general@arkaria.postgresql.org; Tue, 02 Oct 2018 10:10:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g7Hd8-0001k8-Nj for pgsql-general@arkaria.postgresql.org; Tue, 02 Oct 2018 10:10:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7Hd8-0001jk-Bz for pgsql-general@lists.postgresql.org; Tue, 02 Oct 2018 10:10:14 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g7Hd0-0006V0-5C for pgsql-general@postgresql.org; Tue, 02 Oct 2018 10:10:12 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id EDE30F7D5CC0 for ; Tue, 2 Oct 2018 03:10:03 -0700 (MST) Date: Tue, 2 Oct 2018 03:10:03 -0700 (MST) From: pinker To: pgsql-general@postgresql.org Message-ID: <1538475003972-0.post@n3.nabble.com> Subject: pg_sleep() inside plpgsql block - pro & cons MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi! There is second time I see that somebody uses pg_sleep function inside plpgsql block. This case is quite similar to the last one - it's some kind of wait for data to be loaded. After pg_sleep there is a check if some condition is true, if not procedure goes to sleep again. As a result an average duration of this function is 1,5h... I'm trying to gather pros and cons regarding using pg_sleep this way. What's coming to my mind are only 2 cons: * clog contention * long running open transactions (which is quite good described in here: https://www.simononsoftware.com/are-long-running-transactions-bad/) So maybe you'll add some more to the list? -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html