Skip to content

Commit 7544001

Browse files
committed
Added support for PostgreSQL versions 11, 12.
--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".
1 parent 703960f commit 7544001

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ Debian/Ubuntu
206206
###### PostgreSQL versions:
207207
all supported PostgreSQL versions
208208

209-
:white_check_mark: tested, works fine: `PostgreSQL 9.4, 10`
209+
:white_check_mark: tested, works fine: `PostgreSQL 9.4, 10, 11`
210210

211211
## Requirements
212212
pgbackrest >= 2.01
213213

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

217217
>You can use the packages for your PostgreSQL version from the [APT](https://apt.postgresql.org/pub/repos/apt/pool/main/a/amcheck/) repository
218218

pgbackrest_auto

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Requirements: local trust for postgres (login by Unix domain socket) in the pg_hba.conf or ".pgpass"
99
# Run as user: postgres
1010

11-
ver="1.0"
11+
ver="1.1"
1212

1313
# variables for function "sendmail()"
1414
smtp_server="10.128.64.5:25"
@@ -450,22 +450,26 @@ function pg_data_validation(){
450450
}
451451
# amcheck - verify the logical consistency of the structure of PostgreSQL B-Tree indexes
452452
function pg_logical_validation(){
453-
for db in "${ok_dbArray[@]}"; do
454-
if pg_isready 1> /dev/null; then
453+
for db in "${ok_dbArray[@]}"; do
454+
if pg_isready 1> /dev/null; then
455+
if [[ "$PGVER" -ge "11" && "$PGVER" -lt "90" ]]; then
456+
${bin_dir}/psql -p "${port}" -U postgres -d "$db" -tAc "CREATE EXTENSION if not exists amcheck" 1> /dev/null
457+
else
455458
${bin_dir}/psql -p "${port}" -U postgres -d "$db" -tAc "CREATE EXTENSION if not exists amcheck_next" 1> /dev/null
456459
if [[ $? -eq 0 ]]; then
457460
info "Verify the logical consistency of the structure of indexes and heap relations in the database \e[1m$db\e[0m"
458461
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")
459462
for index in $indexes; do
460463
# info "\e[90mVerify the logical consistency of the structure of index\e[0m ${index}"
461464
${bin_dir}/psql -p "${port}" -d "$db" -tAc "SELECT bt_index_parent_check('${index}', true)" 1> /dev/null
462-
if [[ $? -ne 0 ]]; then
463-
errmsg "Logical validation for index \e[1m${index}\e[0m ( database \e[1m$db\e[0m ) - \e[91mFailed\e[0m"
464-
fi
465+
if [[ $? -ne 0 ]]; then
466+
errmsg "Logical validation for index \e[1m${index}\e[0m ( database \e[1m$db\e[0m ) - \e[91mFailed\e[0m"
467+
fi
465468
done
466469
fi
467470
fi
468-
done
471+
fi
472+
done
469473
}
470474

471475
# Send report to mail address

0 commit comments

Comments
 (0)