Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

[WIP] A004 multiple database support #152

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions resources/checks/A004_cluster_info.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Collect pg cluster info
# Collect general cluster info
main_sql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/4.0/sql/0_node.sql | awk '{gsub("; *$", "", $0); print $0}')

pgver=$(${CHECK_HOST_CMD} "${_PSQL} -c \"SHOW server_version\"")

vers=(${pgver//./ })
majorVer=${vers[0]}

prepare_sql=""
dbs=$(${CHECK_HOST_CMD} "${_PSQL} -f - " <<SQL
select datname from pg_database where datname not in ('template0', 'template1', 'postgres')
SQL)

if [[ $majorVer -lt 10 ]]; then
# echo "Version less 10"
Expand All @@ -23,13 +25,21 @@ else

fi

${CHECK_HOST_CMD} "${_PSQL} -f - " <<SQL
$prepare_sql
with data as (
$main_sql
)
select json_object_agg(data.metric, data) as json from data where data.metric not like '------%'
and data.metric not in ('Database Name', 'Database Size')
result="{ }"

for cur_db in ${dbs}; do
object=$(${CHECK_HOST_CMD} "${_PSQL} -f - " <<SQL
$prepare_sql
with data as (
$main_sql
)
select json_object_agg(data.metric, data) as json from data where data.metric not like '------%'
and data.metric not in ('Database Name', 'Database Size')

SQL)
result=$(jq --arg db "${cur_db}" --argjson obj "$object" -r '. += { ($db): $obj }' <<<"${result}")
done

jq -r . <<<"$result"

SQL