Re: pg_sleep() inside plpgsql block - pro & cons

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: pinker <pinker(at)onet(dot)eu>, pgsql-general(at)postgresql(dot)org
Subject: Re: pg_sleep() inside plpgsql block - pro & cons
Date: 2018-10-03 06:12:30
Message-ID: 53f641b1f03458e226fa08fc08090d9300942fa6.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Durgamahesh Manne 2018-10-03 07:30:15 Re: regarding bdr extension
Previous Message Laurenz Albe 2018-10-03 06:06:35 Re: how to identify the timeline of specified recovery_target_time when do multiple PITR