How to terminate all DB activities of a particular PostgreSQL user?
I know how to select them: SELECT * FROM pg_stat_activity WHERE usename='foo_user'
?
And I found this here: https://stackoverflow.com/a/35319598/633961
What I did is first check what are the running processes by
SELECT * FROM pg_stat_activity WHERE state = 'active';
Find the process you want to kill, then type:
SELECT pg_cancel_backend(<pid of the process>)
If the process cannot be killed, try:
SELECT pg_terminate_backend(<pid of the process>)
But how to apply this to several processes?
Use Case
Sometimes a test in CI takes too long and the system should be destroyed.