Solution on PostgreSQL database lock table

  1. Query whether the table is locked
select oid from pg_class where relname=’The table may be locked table’; select pid from pg_locks where relation=’The oid found above’;

select pg_cancel_backend (Pid found above)
select
T.PID, T.STATE, T.QUERY, T.WAIT_EVENT_TYPE, T.WAIT_EVENT,
T.QUERY_START
from PG_STAT_ACTIVITY T
where T.DATNAME =’database user name’;

select T.PID, T.STATE, T.QUERY, T.WAIT_EVENT_TYPE, T.WAIT_EVENT,
T.QUERY_START
from PG_STAT_ACTIVITY T
where T.DATNAME =’Database Username’
and T.WAIT_EVENT_TYPE =’Lock’;
select PG_CANCEL_BACKEND(‘6984’);

--

--

--

Database/System Administrator | DevOPS | Cloud Specialist | DevOPS

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

.. Into Iterative and Incremental Development in Agile.

Explaining DevOps in simple terms..

Where To Start To Learn How To Code

My notes from Droidcon London 2019

MoonSwap Weekly Report (May 24th to May 30th)

Calling SageMaker Runtime Endpoint using SpringBoot and Java

Creating an Automatic Image Classifier

Is my Microservice actually a Distributed Monolith in disguise?

Is my Microservice actually a Distributed Monolith in disguise?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pankaj kushwaha

Pankaj kushwaha

Database/System Administrator | DevOPS | Cloud Specialist | DevOPS

More from Medium

Creating a VM Template in Proxmox to use with Terraform

Capturing browser console logs with cypress-terminal-report

How to create and deploy a T-Pot Honeypot using Amazon Web Services

Mobile App for tickets of different transportation system