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 1g7aOm-0006Tq-9F for pgsql-general@arkaria.postgresql.org; Wed, 03 Oct 2018 06:12:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g7aOj-00046a-Oq for pgsql-general@arkaria.postgresql.org; Wed, 03 Oct 2018 06:12:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g7aOj-00046S-GJ for pgsql-general@lists.postgresql.org; Wed, 03 Oct 2018 06:12:37 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g7aOg-0005Mi-Fu for pgsql-general@postgresql.org; Wed, 03 Oct 2018 06:12:37 +0000 Received: from smtp1.mailbox.org (unknown [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 126A4490D4; Wed, 3 Oct 2018 08:12:33 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id C5Jns91htjP3; Wed, 3 Oct 2018 08:12:31 +0200 (CEST) Message-ID: <53f641b1f03458e226fa08fc08090d9300942fa6.camel@cybertec.at> Subject: Re: pg_sleep() inside plpgsql block - pro & cons From: Laurenz Albe To: pinker , pgsql-general@postgresql.org Date: Wed, 03 Oct 2018 08:12:30 +0200 In-Reply-To: <1538487870670-0.post@n3.nabble.com> References: <1538475003972-0.post@n3.nabble.com> <1538487870670-0.post@n3.nabble.com> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk pinker wrote: > Francisco Olarte wrote > > I do some similar things, but I sleep outside of the > > database, is there a reason this can not be done? > > > > Francisco Olarte. > > Yes, I do try to convince them to do it outside the db, that's the reason > I'm looking for some support here :) I'm not sure those 2 reasons are enough > to convince them, wanted to be prepared... The main reason why longer sleeping in the database is harmful is that it causes long database transactions. Remember that a function always runs inside a database transaction. Long transactions have two very bad consequences: - They hold locks for a long time, blocking concurrent transactions and increasing the likelihood of deadlocks (the word "deadlock" often works wonders when convincing people). - They keep autovacuum from freeing dead tuples, which can lead to bloated tables and indexes if you have many concurrent data modifications. This wastes storage space and slows down sequential scans. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com