postgresql_info: add in_recovery return value to show if a service in recovery mode or not (#1091) (#1093)

* postgresql_info: add in_recovery return value to show if a service is in recovery mode or not

* add changelog fragment

* fix sanity

(cherry picked from commit da7f9ffc3f)

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
patchback[bot] 2020-10-14 14:59:21 +03:00 committed by GitHub
parent ee8f87412a
commit efa884b64a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -18,7 +18,7 @@ options:
description:
- Limit the collected information by comma separated string or YAML list.
- Allowable values are C(version),
C(databases), C(settings), C(tablespaces), C(roles),
C(databases), C(in_recovery), C(settings), C(tablespaces), C(roles),
C(replications), C(repl_slots).
- By default, collects all subsets.
- You can use shell-style (fnmatch) wildcard to pass groups of values (see Examples).
@ -117,6 +117,11 @@ version:
returned: always
type: int
sample: 1
in_recovery:
description: Indicates if the service is in recovery mode or not.
returned: always
type: bool
sample: false
databases:
description: Information about databases.
returned: always
@ -550,6 +555,7 @@ class PgClusterInfo(object):
self.cursor = db_conn_obj.connect()
self.pg_info = {
"version": {},
"in_recovery": None,
"tablespaces": {},
"databases": {},
"replications": {},
@ -563,6 +569,7 @@ class PgClusterInfo(object):
"""Collect information based on 'filter' option."""
subset_map = {
"version": self.get_pg_version,
"in_recovery": self.get_recovery_state,
"tablespaces": self.get_tablespaces,
"databases": self.get_db_info,
"replications": self.get_repl_info,
@ -922,6 +929,10 @@ class PgClusterInfo(object):
minor=int(raw[1]),
)
def get_recovery_state(self):
"""Get if the service is in recovery mode."""
self.pg_info["in_recovery"] = self.__exec_sql("SELECT pg_is_in_recovery()")[0][0]
def get_db_info(self):
"""Get information about the current database."""
# Following query returns: