How to kill PostgreSQL process/session/connection

In this article, we will see how to kill PostgreSQL process ID step by step. we can kill process id by using the function pg_terminate_backend(). To execute this, we must must have superuser privileges.

Query to kill Postgres Process: Continue reading How to kill PostgreSQL process/session/connection

Query to check blocking in PostgreSQL Server

In this article, we will see query to check blocking in PostgreSQL Server.

Syntax to check blocking PostgreSQL Server:

SELECT datname , usename , wait_event_type , wait_event , pg_blocking_pids(pid) AS blocked_by_pid , query FROM pg_stat_activity WHERE wait_event IS NOT NULL;

Continue reading Query to check blocking in PostgreSQL Server

Difference between pg_cancel_backend and pg_terminate_backend in PostrgreSQL

In this article, we will see difference between pg_cancel_backend and pg_terminate_backend in PostgreSQL.

pg_cancel_backend(pid) is a milder version og pg_terminate_backend(pid).

The difference between pg_cancel_backend and pg_terminate_backend in PostgreSQL is that Continue reading Difference between pg_cancel_backend and pg_terminate_backend in PostrgreSQL

How to get locks present in PostgreSQL

In this article, we will see How to get locks present in PostgreSQL.

Query to check the locks present in PostgreSQL:

select t.relname,l.locktype,page,virtualtransaction,pid,mode,granted from pg_locks l, pg_stat_all_tables t where l.relation=t.relid order by relation asc;

Continue reading How to get locks present in PostgreSQL