Thread: Truncate DUMMY_mid is blocked DELETE DUMMY_init TABLE

Truncate DUMMY_mid is blocked DELETE DUMMY_init TABLE

From
M Sarwar
Date:
Hello,
Today I have an interesting observation.
I am truncating the table DUMMY_mid .
Truncate is getting struck due to DELETE operation on the table DUMMY_init.

When I take a look at the PG_STAT_ACTIVITY table, it is confirmed that the TRUNCATE is blocked by  DELETE on DUMMY_INIT table.
This seems to be strange to me.
Thanks,
Sarwar


Re: Truncate DUMMY_mid is blocked DELETE DUMMY_init TABLE

From
Tom Lane
Date:
M Sarwar <sarwarmd02@outlook.com> writes:
> I am truncating the table DUMMY_mid .
> Truncate is getting struck due to DELETE operation on the table DUMMY_init.

Maybe you have foreign keys connecting those tables?

            regards, tom lane



Re: Truncate DUMMY_mid is blocked DELETE DUMMY_init TABLE

From
M Sarwar
Date:
Hi Tom,
I checked both the tables, DUMMY_MID as well as DUMMY_INIT and they do not have relationship at all.
These 2 tables number of columns and the column names are the same. The data is copied from one another. That should not matter as long as there is no foreign key relationship to each others.
Thanks,
Sarwar


From: Tom Lane <tgl@sss.pgh.pa.us>
Sent: Wednesday, June 5, 2024 5:39 PM
To: M Sarwar <sarwarmd02@outlook.com>
Cc: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
Subject: Re: Truncate DUMMY_mid is blocked DELETE DUMMY_init TABLE
 
M Sarwar <sarwarmd02@outlook.com> writes:
> I am truncating the table DUMMY_mid .
> Truncate is getting struck due to DELETE operation on the table DUMMY_init.

Maybe you have foreign keys connecting those tables?

                        regards, tom lane

Re: Truncate DUMMY_mid is blocked DELETE DUMMY_init TABLE

From
Laurenz Albe
Date:
On Wed, 2024-06-05 at 21:23 +0000, M Sarwar wrote:
> Today I have an interesting observation.
> I am truncating the table DUMMY_mid .
> Truncate is getting struck due to DELETE operation on the table DUMMY_init.
>
>
> When I take a look at the PG_STAT_ACTIVITY table, it is confirmed that
> the TRUNCATE is blocked by  DELETE on DUMMY_INIT table.
> This seems to be strange to me.

In "pg_stat_activity", you only see the last SQL statement that was executed
on that connection.  There might have been other SQL statements earlier in the
same transaction that read or in some other way used "DUMMY_mid".

Yours,
Laurenz Albe