Skip to content

Commit

Permalink
Add support for pre active connections for pre pg 9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
blogh committed Jul 18, 2020
1 parent 1bbc7f1 commit 3d1c7ea
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pgactivity/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,22 @@ def pg_get_active_connections(self,):
"""
Get total of active connections.
"""
query = """
SELECT
COUNT(*) as active_connections
FROM pg_stat_activity
WHERE state = 'active'
"""

if self.pg_num_version <= 90100:
# prior to PostgreSQL 9.1, there was no state column
query = """
SELECT
COUNT(*) as active_connections
FROM pg_stat_activity
WHERE query NOT LIKE '<IDLE>%'
"""
else:
query = """
SELECT
COUNT(*) as active_connections
FROM pg_stat_activity
WHERE state = 'active'
"""

cur = self.pg_conn.cursor()
cur.execute(query,)
Expand Down

0 comments on commit 3d1c7ea

Please sign in to comment.