Module: PgBouncerHero::Methods::Basics

Included in:
Database
Defined in:
lib/pgbouncerhero/methods/basics.rb

Constant Summary collapse

SHUTDOWN_MODES =
{
  nil => "",
  immediate: "",
  wait_for_clients: " WAIT_FOR_CLIENTS",
  wait_for_servers: " WAIT_FOR_SERVERS"
}.freeze

Instance Method Summary collapse

Instance Method Details

#clientsObject



36
37
38
# File 'lib/pgbouncerhero/methods/basics.rb', line 36

def clients
  execute("SHOW clients")
end

#confObject



45
46
47
# File 'lib/pgbouncerhero/methods/basics.rb', line 45

def conf
  execute("SHOW config")
end

#databasesObject



24
25
26
# File 'lib/pgbouncerhero/methods/basics.rb', line 24

def databases
  execute("SHOW databases")
end

#listsObject



30
31
32
# File 'lib/pgbouncerhero/methods/basics.rb', line 30

def lists
  execute("SHOW lists")
end

#pause(database_name) ⇒ Object



57
58
59
# File 'lib/pgbouncerhero/methods/basics.rb', line 57

def pause(database_name)
  execute_database_command(:pause, "PAUSE", database_name)
end

#poolsObject



33
34
35
# File 'lib/pgbouncerhero/methods/basics.rb', line 33

def pools
  execute("SHOW pools")
end

#reconnect(database_name) ⇒ Object



60
61
62
# File 'lib/pgbouncerhero/methods/basics.rb', line 60

def reconnect(database_name)
  execute_database_command(:reconnect, "RECONNECT", database_name)
end

#reloadObject



51
52
53
# File 'lib/pgbouncerhero/methods/basics.rb', line 51

def reload
  instrument_admin_command(:reload) { execute("RELOAD") }
end

#resume(database_name = nil) ⇒ Object



66
67
68
69
70
# File 'lib/pgbouncerhero/methods/basics.rb', line 66

def resume(database_name = nil)
  return instrument_admin_command(:resume) { execute("RESUME") } if database_name.nil?

  execute_database_command(:resume, "RESUME", database_name)
end

#serversObject



39
40
41
# File 'lib/pgbouncerhero/methods/basics.rb', line 39

def servers
  execute("SHOW servers")
end

#shutdown(mode = nil) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/pgbouncerhero/methods/basics.rb', line 71

def shutdown(mode = nil)
  instrument_admin_command(:shutdown, mode: mode || :immediate) do
    suffix = SHUTDOWN_MODES.fetch(mode)
    execute("SHUTDOWN#{suffix}")
  rescue KeyError
    raise ArgumentError, "unsupported shutdown mode: #{mode.inspect}"
  end
end

#stateObject



48
49
50
# File 'lib/pgbouncerhero/methods/basics.rb', line 48

def state
  execute("SHOW state")
end

#statsObject



27
28
29
# File 'lib/pgbouncerhero/methods/basics.rb', line 27

def stats
  execute("SHOW stats")
end

#summaryObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pgbouncerhero/methods/basics.rb', line 11

def summary
  if connection
    l = lists
    d = databases
    p = pools
    l = l.as_json
    d = d.as_json.reject { |a| a["name"] == "pgbouncer" }
    p = p.as_json
    l.push({ databases_details: d })
    l.push({ pools_details: p })
    l
  end
end

#suspendObject



54
55
56
# File 'lib/pgbouncerhero/methods/basics.rb', line 54

def suspend
  instrument_admin_command(:suspend) { execute("SUSPEND") }
end

#usersObject



42
43
44
# File 'lib/pgbouncerhero/methods/basics.rb', line 42

def users
  execute("SHOW users")
end

#wait_close(database_name) ⇒ Object



63
64
65
# File 'lib/pgbouncerhero/methods/basics.rb', line 63

def wait_close(database_name)
  execute_database_command(:wait_close, "WAIT_CLOSE", database_name)
end