Sometimes want a list of all connections to your postgres database. Postgres maintains this list in an internal datastructure that you simply query like this:
SELECT * FROM pg_stat_activity;
This will give you something like this (I have removed many columns to make it more readable here):
| state | application_name | client_addr | wait_event |
|---|---|---|---|
| NULL | NULL | AutoVacuumMain | |
| NULL | NULL | LogicalLauncherMain | |
| idle | test.trader.PersistentQueue(data) | 172.20.0.5 | ClientRead |
| active | PyCharm 2021.2.3 | 172.20.0.1 | NULL |
| NULL | NULL | BgWriterHibernate | |
| NULL | NULL | CheckpointerMain | |
| NULL | NULL | WalWriterMain |
In this example, there are two client connections: one from PyCharm, one from my test-application showing up as “test.trader.PersistentQueue(data)”. The other rows are postgres internals that I don’t know about.
[Read More]