You go to run your migrations against your DB, and everything just hangs. One of the causes for this is that the migration is waiting for access to a relation (typically a table, but potentially a view) to which your migration script needs to write, but another process has it locked. If that’s the reason, here’s how we find and kill that process.
1 |
select relation from pg_locks where not granted; |
That’ll give you the ID of the relation you need.
1 |
select pid from pg_locks where relation = <relation id> and granted; |
That’ll give you the pid of the locking process.
In postgres itself, you can do a
1 |
pg_cancel_backend(pid), |
but that doesn’t work if you aren’t a superuser. Just pop back to your command line and kill the process itself.