App to monitor PostgreSQL queries in real time?

pg_activity is what we use. https://github.com/dalibo/pg_activity

It's a great tool with a top-like interface.

You can install and run it on Ubuntu 21.10 with:

sudo apt install pg-activity
pg_activity

PgAdmin offers a pretty easy-to-use tool called server monitor

(Tools ->ServerStatus)


With PostgreSQL 8.4 or higher you can use the contrib module pg_stat_statements to gather query execution statistics of the database server.

Run the SQL script of this contrib module pg_stat_statements.sql (on ubuntu it can be found in /usr/share/postgresql/<version>/contrib) in your database and add this sample configuration to your postgresql.conf (requires re-start):

custom_variable_classes = 'pg_stat_statements'
pg_stat_statements.max = 1000
pg_stat_statements.track = top # top,all,none
pg_stat_statements.save = off

To see what queries are executed in real time you might want to just configure the server log to show all queries or queries with a minimum execution time. To do so set the logging configuration parameters log_statement and log_min_duration_statement in your postgresql.conf accordingly.


If you are using Docker Compose, you can add this line to your docker-compose.yaml file:

command: ["postgres", "-c", "log_statement=all"]

now you can see postgres query logs in docker-compose logs with

docker-compose logs -f 

or if you want to see only postgres logs

docker-compose logs -f [postgres-service-name]

https://stackoverflow.com/a/58806511/10053470