PostgresSQL
listing and aborting long running queries
# lists info about currently running queries
SELECT procpid, datname, query_start, current_query FROM pg_stat_activity;
# full command for oma production database (mind the SSH key path!!!)
ssh -t -i ~/.ssh/authorized_keys/steig_3.pem ec2-user@ec2-107-20-223-147.compute-1.amazonaws.com "sudo su - postgres -c 'psql -c \"SELECT procpid, datname, query_start, current_query FROM pg_stat_activity\"'"
# to stop a query, you need its procpid and feed it to pg_cancel_backend command
SELECT pg_cancel_backend(procpid);
# again, full command (mind the SSH key path and replace procpid!!!)
ssh -t -i ~/.ssh/authorized_keys/steig_3.pem ec2-user@ec2-107-20-223-147.compute-1.amazonaws.co
Last updated