Add postgres - processlist and locks

This commit is contained in:
2021-11-17 11:48:47 +01:00
parent dbeb01a057
commit 385a3b98ca

View File

@@ -31,4 +31,34 @@ $ createdb -O <OWNER> <DBNAME>
\c <DB> connect to a database
\dt list tables
\d <TABLE> describe table
```
\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= '<database name>';
```
With the entry of the `pid` column you can terminate or kill the process:
```sql
SELECT pg_cancel_backend(<pid>); # Stop gracefully
SELECT pg_terminate_backend(<pid>); # Kill
```
## View locks
```sql
SELECT * FROM pg_locks;
```