Thread: Dead lock after the migration from CentOS 7 to RHEL 9

Dead lock after the migration from CentOS 7 to RHEL 9

From
Wasim Devale
Date:
Hi All

I am facing this issue while reindexing after migration. I analysed the application holding the particular table. I stopped the application and reindexed it. It went well then again I am facing this issue below.

ERROR: deadlock detected

DETAIL: Process 2197043 waits for AccessExclusiveLock on relation 10384355 of database 10163711; blocked by process 1889236.

Process 1889236 waits for RowExclusiveLock on relation 10168609 of database 10163711; blocked by process 2197043.

HINT: See server log for query details.


Thanks,
Wasim

Fwd: Dead lock after the migration from CentOS 7 to RHEL 9

From
Wasim Devale
Date:
Hi please help me with the below email.

---------- Forwarded message ---------
From: Wasim Devale <wasimd60@gmail.com>
Date: Wed, 14 Aug, 2024, 11:09 am
Subject: Dead lock after the migration from CentOS 7 to RHEL 9
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>, pgsql-admin <pgsql-admin@postgresql.org>


Hi All

I am facing this issue while reindexing after migration. I analysed the application holding the particular table. I stopped the application and reindexed it. It went well then again I am facing this issue below.

ERROR: deadlock detected

DETAIL: Process 2197043 waits for AccessExclusiveLock on relation 10384355 of database 10163711; blocked by process 1889236.

Process 1889236 waits for RowExclusiveLock on relation 10168609 of database 10163711; blocked by process 2197043.

HINT: See server log for query details.


Thanks,
Wasim

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
"David G. Johnston"
Date:
On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:
Hi please help me with the below email.

---------- Forwarded message ---------
From: Wasim Devale <wasimd60@gmail.com>
Date: Wed, 14 Aug, 2024, 11:09 am
Subject: Dead lock after the migration from CentOS 7 to RHEL 9
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>, pgsql-admin <pgsql-admin@postgresql.org>


Hi All

I am facing this issue while reindexing after migration. I analysed the application holding the particular table. I stopped the application and reindexed it. It went well then again I am facing this issue below.

ERROR: deadlock detected

DETAIL: Process 2197043 waits for AccessExclusiveLock on relation 10384355 of database 10163711; blocked by process 1889236.

Process 1889236 waits for RowExclusiveLock on relation 10168609 of database 10163711; blocked by process 2197043.

HINT: See server log for query details.


How are we supposed to help; you have the indicated log files, and application code, not us. It’s a bug in your code.  And you haven’t asked any question that could be answered.

David J.

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Wasim Devale
Date:

So it's not a postgresql issue. It's from the application side correct?

On Thu, 15 Aug, 2024, 8:56 am David G. Johnston, <david.g.johnston@gmail.com> wrote:
On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:
Hi please help me with the below email.

---------- Forwarded message ---------
From: Wasim Devale <wasimd60@gmail.com>
Date: Wed, 14 Aug, 2024, 11:09 am
Subject: Dead lock after the migration from CentOS 7 to RHEL 9
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>, pgsql-admin <pgsql-admin@postgresql.org>


Hi All

I am facing this issue while reindexing after migration. I analysed the application holding the particular table. I stopped the application and reindexed it. It went well then again I am facing this issue below.

ERROR: deadlock detected

DETAIL: Process 2197043 waits for AccessExclusiveLock on relation 10384355 of database 10163711; blocked by process 1889236.

Process 1889236 waits for RowExclusiveLock on relation 10168609 of database 10163711; blocked by process 2197043.

HINT: See server log for query details.


How are we supposed to help; you have the indicated log files, and application code, not us. It’s a bug in your code.  And you haven’t asked any question that could be answered.

David J.

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
"David G. Johnston"
Date:
On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:

So it's not a postgresql issue. It's from the application side correct?


That’s the assumption.  The vast majority of locks happen because the “application” executed SQL commands.

David J.

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Wasim Devale
Date:

Ok thanks for the insights.

Do we need to do any config changes in the config file?

We have also configured Datadog agent at operating system level that checks postgresql activity it's has the pgpouncer.d config file that is unchanged after the migration. This might be the possible reason that it is throughing dead lock error.

Please through some insights on the above.

Thanks for the immediate help.

Regards,
Wasim

On Thu, 15 Aug, 2024, 9:01 am David G. Johnston, <david.g.johnston@gmail.com> wrote:
On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:

So it's not a postgresql issue. It's from the application side correct?


That’s the assumption.  The vast majority of locks happen because the “application” executed SQL commands.

David J.

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Scott Ribe
Date:
Given errors like the pair you posted, my next step would be to examine the queries being executed by those processes
duringthe deadlock. Now, I think by the time the deadlock error is logged, the queries involved have been cancelled, so
it'spossible the processes have gone on to another query and so pg_stat_activity might not have useful information, or
itmight--depending on what your app would do after a deadlock error. 

If it does not, then the next thing would be to set log_min_duration_statement to less than deadlock/statement timeout,
sothat you could look through logs to figure out what are the two queries which are deadlocking against each other. 

--
Scott Ribe
scott_ribe@elevated-dev.com
https://www.linkedin.com/in/scottribe/



> On Aug 14, 2024, at 9:38 PM, Wasim Devale <wasimd60@gmail.com> wrote:
>
> Ok thanks for the insights.
> Do we need to do any config changes in the config file?
> We have also configured Datadog agent at operating system level that checks postgresql activity it's has the
pgpouncer.dconfig file that is unchanged after the migration. This might be the possible reason that it is throughing
deadlock error.  
> Please through some insights on the above.
> Thanks for the immediate help.
> Regards,
> Wasim
>
> On Thu, 15 Aug, 2024, 9:01 am David G. Johnston, <david.g.johnston@gmail.com> wrote:
> On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:
> So it's not a postgresql issue. It's from the application side correct?
>
> That’s the assumption.  The vast majority of locks happen because the “application” executed SQL commands.
>
> David J.




Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
"David G. Johnston"
Date:
On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:

Ok thanks for the insights.

Do we need to do any config changes in the config file?

We have also configured Datadog agent at operating system level that checks postgresql activity it's has the pgpouncer.d config file that is unchanged after the migration. This might be the possible reason that it is throughing dead lock error.

Please through some insights on the above.


Sounds like you need to read up on what a deadlock is, and then go figure out what combination of SQL commands in your environment is causing it. Only then does it make sense to reason through possible solutions.  Until you can show some SQL commands I’m not of much help.  I’m not inclined to teach what a deadlock is - such knowledge is available on the internet.

David J.

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Wasim Devale
Date:
Thanks Scott

I do reindexing on database when  production is completely down. it's only the application UI queries that holds the tables.

I will dig down more if require your help I will post it.

Thanks David, 
Thanks Scott.




On Thu, 15 Aug, 2024, 9:15 am Scott Ribe, <scott_ribe@elevated-dev.com> wrote:
Given errors like the pair you posted, my next step would be to examine the queries being executed by those processes during the deadlock. Now, I think by the time the deadlock error is logged, the queries involved have been cancelled, so it's possible the processes have gone on to another query and so pg_stat_activity might not have useful information, or it might--depending on what your app would do after a deadlock error.

If it does not, then the next thing would be to set log_min_duration_statement to less than deadlock/statement timeout, so that you could look through logs to figure out what are the two queries which are deadlocking against each other.

--
Scott Ribe
scott_ribe@elevated-dev.com
https://www.linkedin.com/in/scottribe/



> On Aug 14, 2024, at 9:38 PM, Wasim Devale <wasimd60@gmail.com> wrote:
>
> Ok thanks for the insights.
> Do we need to do any config changes in the config file?
> We have also configured Datadog agent at operating system level that checks postgresql activity it's has the pgpouncer.d config file that is unchanged after the migration. This might be the possible reason that it is throughing dead lock error.
> Please through some insights on the above.
> Thanks for the immediate help.
> Regards,
> Wasim
>
> On Thu, 15 Aug, 2024, 9:01 am David G. Johnston, <david.g.johnston@gmail.com> wrote:
> On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:
> So it's not a postgresql issue. It's from the application side correct?
>
> That’s the assumption.  The vast majority of locks happen because the “application” executed SQL commands.
>
> David J.

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Tom Lane
Date:
Scott Ribe <scott_ribe@elevated-dev.com> writes:
> Given errors like the pair you posted, my next step would be to examine the queries being executed by those processes
duringthe deadlock. Now, I think by the time the deadlock error is logged, the queries involved have been cancelled, so
it'spossible the processes have gone on to another query and so pg_stat_activity might not have useful information, or
itmight--depending on what your app would do after a deadlock error. 
> If it does not, then the next thing would be to set log_min_duration_statement to less than deadlock/statement
timeout,so that you could look through logs to figure out what are the two queries which are deadlocking against each
other.

The postmaster log should already contain the statements that
deadlocked against each other --- that's what the "HINT: See server
log for query details" is telling you.

            regards, tom lane



Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Asad Ali
Date:
The error message indicates a deadlock situation between two processes in your PostgreSQL database. A deadlock occurs when two or more processes are blocked indefinitely, each waiting for the other to release a lock.

Here's a breakdown of the error message:

- Process 2197043 is waiting for an AccessExclusiveLock on relation 10384355 (a table or index).
- Process 1889236 is holding the lock that process 2197043 is waiting for and is waiting for a RowExclusiveLock on relation 10168609 (another table or index).
- Process 2197043 is holding the lock that process 1889236 is waiting for, creating a deadlock.

To resolve this issue:

1. Check the server log for query details, as hinted in the error message. This will help you identify the queries causing the deadlock.
2. Analyze the queries and identify any potential causes, such as:
    - Long-running transactions
    - Lock contention between multiple processes
    - Poorly indexed tables
3. Consider the following solutions:
    - Optimize queries to reduce lock contention
    - Use more granular locking (e.g., RowShareLock instead of RowExclusiveLock)
    - Split long-running transactions into smaller ones
    - Reindex tables during a maintenance window to minimize lock contention
4. If the issue persists, consider increasing the deadlock_timeout parameter to allow PostgreSQL to detect and resolve deadlocks more efficiently.

Remember to exercise caution when making changes to your database configuration or queries, as they may impact performance or data integrity.

On Wed, Aug 14, 2024 at 10:39 AM Wasim Devale <wasimd60@gmail.com> wrote:
Hi All

I am facing this issue while reindexing after migration. I analysed the application holding the particular table. I stopped the application and reindexed it. It went well then again I am facing this issue below.

ERROR: deadlock detected

DETAIL: Process 2197043 waits for AccessExclusiveLock on relation 10384355 of database 10163711; blocked by process 1889236.

Process 1889236 waits for RowExclusiveLock on relation 10168609 of database 10163711; blocked by process 2197043.

HINT: See server log for query details.


Thanks,
Wasim

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Ron Johnson
Date:
On Wed, Aug 14, 2024 at 11:50 PM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:

Ok thanks for the insights.

Do we need to do any config changes in the config file?

We have also configured Datadog agent at operating system level that checks postgresql activity it's has the pgpouncer.d config file that is unchanged after the migration. This might be the possible reason that it is throughing dead lock error.

Please through some insights on the above.


Sounds like you need to read up on what a deadlock is, and then go figure out what combination of SQL commands in your environment is causing it. Only then does it make sense to reason through possible solutions.  Until you can show some SQL commands I’m not of much help.  I’m not inclined to teach what a deadlock is - such knowledge is available on the internet.

TBF, this is apparently the same application that was running "fine" before upgrading.

OP has still done a non-existant job at telling us what version he upgraded from and to, how he upgraded and what he did afterwards.

--
Death to America, and butter sauce.
Iraq lobster!

Re: Dead lock after the migration from CentOS 7 to RHEL 9

From
Wasim Devale
Date:

I am not much aware that the application code is embedded in Java and the groovy language.

The issue is resolved I did indexing concurrently on each primary key index individually via a Linux command written in a file and executed it and other indexes that has the btree indexing. This resolved it.

Thanks everyone.

On Thu, 15 Aug, 2024, 7:41 pm Ron Johnson, <ronljohnsonjr@gmail.com> wrote:
On Wed, Aug 14, 2024 at 11:50 PM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Wednesday, August 14, 2024, Wasim Devale <wasimd60@gmail.com> wrote:

Ok thanks for the insights.

Do we need to do any config changes in the config file?

We have also configured Datadog agent at operating system level that checks postgresql activity it's has the pgpouncer.d config file that is unchanged after the migration. This might be the possible reason that it is throughing dead lock error.

Please through some insights on the above.


Sounds like you need to read up on what a deadlock is, and then go figure out what combination of SQL commands in your environment is causing it. Only then does it make sense to reason through possible solutions.  Until you can show some SQL commands I’m not of much help.  I’m not inclined to teach what a deadlock is - such knowledge is available on the internet.

TBF, this is apparently the same application that was running "fine" before upgrading.

OP has still done a non-existant job at telling us what version he upgraded from and to, how he upgraded and what he did afterwards.

--
Death to America, and butter sauce.
Iraq lobster!