Restarting the database will terminate the long-running transaction. However, restarting the database isn't feasible. If you have access to the database to run an SQL query, follow the below query to stop the transaction.
1. Query:
SELECT pid, now() - pg_stat_activity.query_start AS duration, query FROM pg_stat_activity WHERE state = 'active' ORDER BY duration DESC;
pid→ backend process ID of the query.duration→ how long the query has been running.query→ SQL text.
2. Once the DBA identify the problematic query, kill it:
SELECT pg_terminate_backend(<pid>);
This will stop the transaction and free up the backend process.
3. Restart Apache Tomcat (if the UI remains frozen).