Add postgres - processlist and locks
This commit is contained in:
@@ -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;
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user