Clearing locks in Postgresql using psql

Occasionally I get into situations where an app has crashed and locked a row in a table.

To figure out what locks are currently in place I run this command from psql:

select * from pg_stat_activity where datname = '<some db I care about>';

Once I know which machine I want to target, I terminate the process with the following command which is likely barbaric in nature:

SELECT pg_terminate_backend(pid) from pg_stat_activity where client_addr = '<client id>';

I’m using an ip in my where clause but it could obviously be based on any other column you want to filter on.