Another one for the Quick Tips category – have you ever needed to see what queries are running against your Postgres database? Perhaps a nightly process hasn’t finished yet and you’re curious if it’s deadlocked? Or maybe the database server is using 100% CPU and you’re not sure why? These, along with many others, are all reasons I have needed to peek under the hood of Postgres.
Doing so is pretty simple, just execute the following query:
And you’ll get a list of running queries (sans the above query) with relevant information, like the current run time, the status of the query, and the SQL itself.