Deadlock concern caused by TRUNCATE on user_catalog_table in synchronous mode

From: "osumi(dot)takamichi(at)fujitsu(dot)com" <osumi(dot)takamichi(at)fujitsu(dot)com>
To: "'amit(dot)kapila16(at)gmail(dot)com'" <amit(dot)kapila16(at)gmail(dot)com>, "'pgsql-hackers(at)lists(dot)postgresql(dot)org'" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Deadlock concern caused by TRUNCATE on user_catalog_table in synchronous mode
Date: 2021-05-19 10:32:04
Message-ID: OSBPR01MB4888314C70DA6B112E32DD6AED2B9@OSBPR01MB4888.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

I've been discussing about user_catalog_table
and the possibility of deadlock during synchronous mode
of logical replication in [1]. I'll launch a new thread
and summarize the contents so that anyone who is
interested in this title can join the discussion.

We don't have any example of user_catalog_tables
in the core code, so any response and idea related to this area is helpful.

Now, we don't disallow output plugin to take a lock
on user_catalog_table. Then, we can consider a deadlock scenario like below.

1. TRUNCATE command is performed on user_catalog_table.
2. TRUNCATE command locks the table and index with ACCESS EXCLUSIVE LOCK.
3. TRUNCATE waits for the subscriber's synchronization
when synchronous_standby_names is set.
4. Here, the walsender hangs, *if* it tries to acquire a lock on the user_catalog_table
because the table where it wants to see is locked by the TRUNCATE already.

(Here, we don't talk about LOCK command because
the discussion is in progress in another thread independently - [2])

Another important point here is that we can *not*
know how and when plugin does read only access to user_catalog_table in general,
because it depends on the purpose of the plugin.
Then, I'm thinking that changing a behavior of TRUNCATE side
to error out when TRUNCATE is performed on user_catalog_table
will work to make the concern disappear. Kindly have a look at the attached patch.

[1] - https://www.postgresql.org/message-id/MEYP282MB166933B1AB02B4FE56E82453B64D9%40MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM

[2] - https://www.postgresql.org/message-id/CALDaNm1UB==gL9Poad4ETjfcyGdJBphWEzEZocodnBd--kJpVw@mail.gmail.com

Best Regards,
Takamichi Osumi

Attachment Content-Type Size
disallow_TRUNCATE_on_user_catalog_table_v01.patch application/octet-stream 3.6 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2021-05-19 10:32:37 Re: pgbench test failing on 14beta1 on Debian/i386
Previous Message Fujii Masao 2021-05-19 10:24:09 Re: pg_get_wal_replay_pause_state() should not return 'paused' while a promotion is ongoing.