pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Artur ZajÄ…c <azajac@ang.com.pl>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Table locking during backup
Date: Tue, 08 Oct 2019 11:02:31 -0400
Message-ID: <20845.1570546951@sss.pgh.pa.us> (raw)
In-Reply-To: <02b701d57da3$57bea1f0$073be5d0$@ang.com.pl>
References: <021f01d57d52$3397e300$9ac7a900$@ang.com.pl>
	<20191007211930.r53ockkfjkx3gbzt@development>
	<02b701d57da3$57bea1f0$073be5d0$@ang.com.pl>

=?utf-8?Q?Artur_Zaj=C4=85c?= <azajac@ang.com.pl> writes:
> First session:
> BEGIN; 
> set transaction isolation level repeatable read, read only;
> lock TABLE gm.tableabc IN access share mode;

> Second session:
> BEGIN;
> CREATE TEMP TABLE IF NOT EXISTS tableabc (Id BIGINT DEFAULT random()) INHERITS (gm.tableabc);

> "CREATE TEMP TABLE" does not wait for anything. Waiting state is only when I start third session with the same queries as in second.

A bit of looking into pg_locks will show you that CREATE TABLE
... INHERITS takes ShareUpdateExclusiveLock on the table being
inherited from.  Per the manual,

    SHARE UPDATE EXCLUSIVE

        Conflicts with the SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW
        EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. This mode
        protects a table against concurrent schema changes and VACUUM
        runs.

So that doesn't conflict with pg_dump, but would conflict with another
session trying to INHERIT from the same table.  AFAICS, pg_dump's lock
isn't involved in that conflict at all.

If you only notice blocking when pg_dump is running, it's likely not
due to this lock in isolation, but the fact that pg_dump takes
access-share locks on everything in sight.  That can block sessions
that are trying to do DDL, causing other things to queue up behind
them, depending on what other locks those session(s) already hold.

There's really no substitute for looking into pg_locks to see
what's going on in cases like this ...

			regards, tom lane





view thread (4+ messages)

Message-ID: <20845.1570546951@sss.pgh.pa.us>
Permalink:  ../20845.1570546951@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20845.1570546951@sss.pgh.pa.us

 · 

reply

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, azajac@ang.com.pl
  Subject: Re: Table locking during backup
  In-Reply-To: <20845.1570546951@sss.pgh.pa.us>
  References: <021f01d57d52$3397e300$9ac7a900$@ang.com.pl> <20191007211930.r53ockkfjkx3gbzt@development> <02b701d57da3$57bea1f0$073be5d0$@ang.com.pl> <20845.1570546951@sss.pgh.pa.us>

* 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