Module: PgHero::Methods::Connections

Included in:
Database
Defined in:
lib/pghero/methods/connections.rb

Instance Method Summary collapse

Instance Method Details

#connection_sourcesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pghero/methods/connections.rb', line 8

def connection_sources
  select_all <<-SQL
    SELECT
      datname AS database,
      usename AS user,
      application_name AS source,
      client_addr AS ip,
      COUNT(*) AS total_connections
    FROM
      pg_stat_activity
    GROUP BY
      1, 2, 3, 4
    ORDER BY
      5 DESC, 1, 2, 3, 4
  SQL
end

#total_connectionsObject



4
5
6
# File 'lib/pghero/methods/connections.rb', line 4

def total_connections
  select_one("SELECT COUNT(*) FROM pg_stat_activity")
end