Re: Race condition while creating a new partition - Mailing list pgsql-general

From Justin
Subject Re: Race condition while creating a new partition
Date
Msg-id CALL-XeM-CpWpUGqJrpw21Rdun7QJQwFV5sH9Pk7i13XJyzX93w@mail.gmail.com
Whole thread Raw
In response to Re: Race condition while creating a new partition  (Andrei Zhidenkov <andrei.zhidenkov@n26.com>)
Responses Re: Race condition while creating a new partition
List pgsql-general
Hi Andrei

General speaking any DDL (Create, Alter  Drop .etc) commands  issue exclusive locks automatically, so anything this transaction touches starts getting exclusive locks.  Assuming this is a multi-threading app these two threads are sending commands all but at the same time.  The Exclusive lock  has not been committed yet as its waiting for a previous insert to finish, and the Exclusive lock is blocking the insert  as its transaction started prior to the Insert. 

the wait queue is pretty long 84, 80, 82, 83, 87, 88, 85, 86.
The time stamps are only 2 ms apart,  lots of commands being sent in at nearly the same time...

Here are my  suggestions
Tweak  the Python app to make sure all the threads have committed their transactions place a lock on all the other threads, Then issue a DDL command, when the command is committed, then unlock the other threads.  That should kill off the race condition deadlock..

Post all the SQL code that is creating this exclusive lock,  we may be able re-write the SQL code to reduce the time and/or resources this Exclusive Lock is creating.     

Pyscopg2 default mode is to require issuing a Commit it does not automatically commit transaction.  If running in auto-commit OFF try  turning this  ON for DDL commands may fix the issue.  It may also be that DDL command takes far longer than 1 second to complete...


pgsql-general by date:

Previous
From: Andrei Zhidenkov
Date:
Subject: Re: Race condition while creating a new partition
Next
From: Sar
Date:
Subject: Experiencing error during restore - found unexpected block ID (0)