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; +``` +