|
8 | 8 | # Requirements: local trust for postgres (login by Unix domain socket) in the pg_hba.conf or ".pgpass" |
9 | 9 | # Run as user: postgres |
10 | 10 |
|
11 | | -ver="1.0" |
| 11 | +ver="1.1" |
12 | 12 |
|
13 | 13 | # variables for function "sendmail()" |
14 | 14 | smtp_server="10.128.64.5:25" |
@@ -450,22 +450,26 @@ function pg_data_validation(){ |
450 | 450 | } |
451 | 451 | # amcheck - verify the logical consistency of the structure of PostgreSQL B-Tree indexes |
452 | 452 | 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 |
455 | 458 | ${bin_dir}/psql -p "${port}" -U postgres -d "$db" -tAc "CREATE EXTENSION if not exists amcheck_next" 1> /dev/null |
456 | 459 | if [[ $? -eq 0 ]]; then |
457 | 460 | info "Verify the logical consistency of the structure of indexes and heap relations in the database \e[1m$db\e[0m" |
458 | 461 | 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") |
459 | 462 | for index in $indexes; do |
460 | 463 | # info "\e[90mVerify the logical consistency of the structure of index\e[0m ${index}" |
461 | 464 | ${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 |
465 | 468 | done |
466 | 469 | fi |
467 | 470 | fi |
468 | | - done |
| 471 | + fi |
| 472 | + done |
469 | 473 | } |
470 | 474 |
|
471 | 475 | # Send report to mail address |
|
0 commit comments