From 385a3b98ca8064af936a5089170c929fa3abeae2 Mon Sep 17 00:00:00 2001 From: Michael Schlapa Date: Wed, 17 Nov 2021 11:48:47 +0100 Subject: [PATCH] Add postgres - processlist and locks --- postgresql.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/postgresql.md b/postgresql.md index 60538b8..1b4926d 100644 --- a/postgresql.md +++ b/postgresql.md @@ -31,4 +31,34 @@ $ createdb -O \c connect to a database \dt list tables \d describe table -``` \ No newline at end of file +\df list functions +\dy list trigger +``` + +## Find and kill query process + +To get a list of all currently running query process (like `SHOW FULL PROCESSLIST` from MySQL) enter: + +```sql +SELECT * FROM pg_stat_activity; +``` + +If you know the name of the database you can filter with it like so: + +```sql +SELECT * FROM pg_stat_activity WHERE datname= ''; +``` + +With the entry of the `pid` column you can terminate or kill the process: + +```sql +SELECT pg_cancel_backend(); # Stop gracefully +SELECT pg_terminate_backend(); # Kill +``` + +## View locks + +```sql +SELECT * FROM pg_locks; +``` +