Class: K8sflow::Pg::Ps

Inherits:
PgBase
  • Object
show all
Defined in:
lib/k8sflow/command/pg/ps.rb

Class Method Summary collapse

Methods inherited from PgBase

database, databases, exec_sql, hash_opt, kv_parse, nine_two?, parse_pg_uri, pid_column, psql_cmd, query_column, ssl?, version

Class Method Details

.callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/k8sflow/command/pg/ps.rb', line 14

def self.call
  sql = %Q(
    SELECT
#{pid_column},
#{"state," if nine_two?}
application_name AS source,
age(now(),xact_start) AS running_for,
waiting,
#{query_column} AS query
     FROM pg_stat_activity
     WHERE
 #{query_column} <> '<insufficient privilege>'
 #{
# Apply idle-backend filter appropriate to versions and options.
case
when options[:verbose]
  ''
when nine_two?
  "AND state <> 'idle'"
else
  "AND current_query <> '<IDLE>'"
end
 }
 AND #{pid_column} <> pg_backend_pid()
 ORDER BY query_start DESC
     )

  puts exec_sql(sql)
end