A query hangs and nothing in the logs explains it. Usually it waits for a lock that another session holds, and PostgreSQL can tell you which one.
SELECT pid, pg_blocking_pids(pid) AS blocked_by,
state, wait_event_type, left(query, 60) AS query
FROM pg_stat_activity
WHERE cardinality(pg_blocking_pids(pid)) > 0;
For every session that is stuck on a lock, you get its own pid and an array of the pids blocking it. I’d look up those pids in pg_stat_activity to see what they are doing. Very often the blocker is in the state idle in transaction: someone ran BEGIN and an update in a console and walked away, or an app forgot to commit.
A blocker can itself be blocked, so you may find a chain. Follow it to the session at the start, which is not waiting on anybody.
Once you know the pid, pg_cancel_backend(pid) or pg_terminate_backend(pid) can end it, but check what it is first. Killing a session rolls back its open transaction. The docs advise against calling this function very often, because it briefly takes the lock manager’s locks itself, so run it when something hangs and not every second from a monitoring tool. A zero in the array means a prepared transaction holds the lock.
Further reading: System information functions (pg_blocking_pids), pg_stat_activity view