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

H002 reworked, cosmetical fixes, 'single transaction' as psql option #148

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion check
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ validate_args() {

# for usage inside the check scripts
export PSQL_CONN_OPTIONS="--port=${PGPORT} --dbname=${DBNAME} --username=${USERNAME} ${psql_unix_socket_option}"
export _PSQL="${pgpas_subst}${psql_bin} -X -At -q -v ON_ERROR_STOP=1 -P pager=off ${PSQL_CONN_OPTIONS}"
export _PSQL="${pgpas_subst}${psql_bin} -1 -X -At -q -v ON_ERROR_STOP=1 -P pager=off ${PSQL_CONN_OPTIONS}"

dbg ""
dbg "PSQL_CONN_OPTIONS: $PSQL_CONN_OPTIONS"
Expand Down
38 changes: 38 additions & 0 deletions pghrep/templates/H002.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# {{ .checkId }} Non indexed foreign keys (or with bad indexes)

## Observations ##

### Master (`{{.hosts.master}}`) ###
```
{{(index (index .results .hosts.master) "data").raw}}
```
{{/* newline */}}
{{/* newline */}}

{{- if gt (len .hosts.replicas) 0 -}}
### Replica servers: ###
{{/* newline */}}
{{/* newline */}}
{{- range $skey, $host := .hosts.replicas -}}
#### Replica (`{{ $host }}`) ####
{{- if (index $.results $host) -}}
{{/* newline */}}
{{/* newline */}}
```
{{ (index (index $.results $host) "data").raw }}
```
{{- else -}}
```
No non-indexed foreign keys
```
{{- end -}}
{{- end -}}
{{- end -}}

{{/* newline */}}
{{/* newline */}}
## Conclusions ##


## Recommendations ##

2 changes: 1 addition & 1 deletion resources/checks/A005_extensions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Collect pg_settings artifact
sql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/4.0/sql/e1_extensions.sql | awk '{gsub("; *$", "", $0); print $0}')

${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
with data as (
$sql
), withsettins as (
Expand Down
2 changes: 1 addition & 1 deletion resources/checks/D004_ext_settings.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Collect pg_settings artifact
${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
with stat_statements as (
select json_object_agg(pg_settings.name, pg_settings) as json from pg_settings where name ~ 'pg_stat_statements'
), kcache as (
Expand Down
2 changes: 1 addition & 1 deletion resources/checks/F001_heap_bloat.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/4.0/sql/b1_table_estimation.sql | awk '{gsub("; *$", "", $0); print $0}')

${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
with data as (
$sql
)
Expand Down
2 changes: 1 addition & 1 deletion resources/checks/F002_index_bloat.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/4.0/sql/b2_btree_estimation.sql | awk '{gsub("; *$", "", $0); print $0}')

${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
with data as (
$sql
)
Expand Down
4 changes: 2 additions & 2 deletions resources/checks/G001_memory_related_settings.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Collect pg_settings artifact
${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
select json_object_agg(s.name, s) from pg_settings s where name in ('max_connections', 'work_mem', 'maintenance_work_mem', 'autovacuum_work_mem', 'shared_buffers', 'effective_cache_size', 'temp_buffers');
SQL
SQL
2 changes: 1 addition & 1 deletion resources/checks/G002_current_connections.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

sql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/4.0/sql/a1_activity.sql | awk '{gsub("; *$", "", $0); print $0}')

data=$(${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
data=$(${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
-- disble psql CLI options '-A -t' for this report
\pset tuples_only
\pset format aligned
Expand Down
2 changes: 1 addition & 1 deletion resources/checks/G003_timeouts_locks.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Collect pg_settings artifact
${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
with timeouts as (
select json_object_agg(s.name,s ) from pg_settings s where name in ('statement_timeout', 'idle_in_transaction_session_timeout', 'authentication_timeout')
), locks as (
Expand Down
2 changes: 1 addition & 1 deletion resources/checks/H001_unused_indexes.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unusedSql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/4.0/sql/i1_rare_indexes.sql | awk '{gsub("; *$", "", $0); print $0}')
redundantSql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/4.0/sql/i2_redundant_indexes.sql | awk '{gsub("; *$", "", $0); print $0}')

${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
with indexes as (
$unusedSql
), migrations as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

sql=$(curl -s -L https://raw.githubusercontent.com/NikolayS/postgres_dba/master/sql/i3_non_indexed_fks.sql | awk '{gsub("; *$", "", $0); print $0}')

${CHECK_HOST_CMD} "${_PSQL} ${PSQL_CONN_OPTIONS} -f -" <<SQL
data=$(${CHECK_HOST_CMD} "${_PSQL} -f -" <<SQL
-- disble psql CLI options '-A -t' for this report
\pset tuples_only
\pset format aligned
\pset expanded

with data as (
$sql
),
num_data as (
select row_number() over () num, data.* from data
)
select json_object_agg(num, num_data) as json from num_data
SQL
select * from num_data as index
SQL)

data="{ \"raw\": \"${data}\" }"
jq -n "${data}"