Skip to content

Commit

Permalink
Added support for PostgreSQL versions 11, 12.
Browse files Browse the repository at this point in the history
--checkdb (pg_logical_validation):

For PostgreSQL version <= 10 install the "amcheck_next" extension.
if PostgreSQL version >=11 install (included in the postgresql package) extension "amcheck".
  • Loading branch information
vitabaks committed Jan 27, 2020
1 parent 703960f commit 7544001
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ Debian/Ubuntu
###### PostgreSQL versions:
all supported PostgreSQL versions

:white_check_mark: tested, works fine: `PostgreSQL 9.4, 10`
:white_check_mark: tested, works fine: `PostgreSQL 9.4, 10, 11`

## Requirements
pgbackrest >= 2.01

for `--checkdb`:
- [amcheck_next](https://github.com/petergeoghegan/amcheck) extension/SQL version >=2.
for `--checkdb`:
- [amcheck_next](https://github.com/petergeoghegan/amcheck) extension/SQL version >=2 `(if PostgreSQL version <= 10)`.

>You can use the packages for your PostgreSQL version from the [APT](https://apt.postgresql.org/pub/repos/apt/pool/main/a/amcheck/) repository
Expand Down
18 changes: 11 additions & 7 deletions pgbackrest_auto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Requirements: local trust for postgres (login by Unix domain socket) in the pg_hba.conf or ".pgpass"
# Run as user: postgres

ver="1.0"
ver="1.1"

# variables for function "sendmail()"
smtp_server="10.128.64.5:25"
Expand Down Expand Up @@ -450,22 +450,26 @@ function pg_data_validation(){
}
# amcheck - verify the logical consistency of the structure of PostgreSQL B-Tree indexes
function pg_logical_validation(){
for db in "${ok_dbArray[@]}"; do
if pg_isready 1> /dev/null; then
for db in "${ok_dbArray[@]}"; do
if pg_isready 1> /dev/null; then
if [[ "$PGVER" -ge "11" && "$PGVER" -lt "90" ]]; then
${bin_dir}/psql -p "${port}" -U postgres -d "$db" -tAc "CREATE EXTENSION if not exists amcheck" 1> /dev/null
else
${bin_dir}/psql -p "${port}" -U postgres -d "$db" -tAc "CREATE EXTENSION if not exists amcheck_next" 1> /dev/null
if [[ $? -eq 0 ]]; then
info "Verify the logical consistency of the structure of indexes and heap relations in the database \e[1m$db\e[0m"
indexes=$(${bin_dir}/psql -p "${port}" -d "$db" -tAc "SELECT quote_ident(n.nspname)||'.'||quote_ident(c.relname) FROM pg_index i JOIN pg_opclass op ON i.indclass[0] = op.oid JOIN pg_am am ON op.opcmethod = am.oid JOIN pg_class c ON i.indexrelid = c.oid JOIN pg_namespace n ON c.relnamespace = n.oid WHERE am.amname = 'btree' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND c.relpersistence != 't' AND c.relkind = 'i' AND i.indisready AND i.indisvalid")
for index in $indexes; do
# info "\e[90mVerify the logical consistency of the structure of index\e[0m ${index}"
${bin_dir}/psql -p "${port}" -d "$db" -tAc "SELECT bt_index_parent_check('${index}', true)" 1> /dev/null
if [[ $? -ne 0 ]]; then
errmsg "Logical validation for index \e[1m${index}\e[0m ( database \e[1m$db\e[0m ) - \e[91mFailed\e[0m"
fi
if [[ $? -ne 0 ]]; then
errmsg "Logical validation for index \e[1m${index}\e[0m ( database \e[1m$db\e[0m ) - \e[91mFailed\e[0m"
fi
done
fi
fi
done
fi
done
}

# Send report to mail address
Expand Down

0 comments on commit 7544001

Please sign in to comment.