mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
fix(postgres): move tenant PostgreSQL to patched standard-trixie images (#5405)
## What this PR does Moves the tenant `postgres` application to PostgreSQL minors that fix CVE-2026-116331, and makes the upgrade repair the indexes that the move can break. ### Why the images change CVE-2026-116331 is a type confusion in the min/max aggregate optimisation: a role that can create objects runs code as the operating system user of the server. Tenants hold such roles, so this application is the exposed one. The fixed minors are 18.7, 17.12, 16.16, 15.20 and 14.25. The default flavor pins bare image tags (`postgresql:17.7`). A bare tag is the `system` variant on Debian bullseye, and upstream stopped building it: the fixed minors are published for bookworm and trixie only. This PR takes `standard-trixie`: the standard variant, because backups go through the barman-cloud plugin and need none of the barman binaries the `system` variant adds, and trixie, because the postgis flavor is on it already, so both image families share one Debian release. `hack/update-versions.sh` selects bare tags, so it would have settled on 17.11 and 18.6, which are still affected. This PR: - pins `<minor>-standard-trixie` for the default flavor and bumps every major to its fixed minor; - bumps the postgis flavor to the same minors (it was already on `standard-trixie`), which moves PostGIS from 3.6.1 to 3.7.0; - teaches `hack/update-versions.sh` to pick minors from `standard-trixie` tags. PostgreSQL 13 has no fixed release. It keeps the minor 13.22 and stays exposed to the CVE, and it moves to the trixie variant with every other major, so it takes the base image change and the index rebuild without getting the fix. 14.25 is the last release of the 14 line. ### Why the upgrade needs a repair step For a running default-flavor cluster the image moves from bullseye to trixie, so glibc goes from 2.31 to 2.41 and ICU's collator version from 153.14 to 153.128 under an existing data directory. An index ordered by a collation of either library is then ordered by rules the server no longer applies. PostgreSQL only logs a warning. Reproduced on a live cluster with 60 000 rows of mixed Unicode text: | Index collation | After the image change | |---|---| | `C` (what the chart creates by default) | intact | | libc `en_US.utf8` | intact on this data, version mismatch warning | | ICU `en-x-icu` | `amcheck`: item order invariant violated; 2 604 rows not found through the index | A database the chart created with its defaults uses `C` and is not affected. A tenant who declared `COLLATE` on a column, used an ICU collation, or created a database with a locale is. ### What the init Job does now The post-install/post-upgrade Job gets one more pass. It runs after the passes that manage roles and databases, so a rebuild that fails or runs out of time costs none of them. In every connectable database it: 1. finds the indexes that depend on a collation whose recorded library version differs from the one the server reports. PostgreSQL records a collation for an index only where it orders a key, so the collations of the columns an index reads in its expressions and its predicate count as well; 2. rebuilds them with `REINDEX INDEX CONCURRENTLY` (plain `REINDEX` for an exclusion constraint's index, which cannot be rebuilt concurrently, so its table is neither read nor written meanwhile); 3. refreshes the recorded versions with `ALTER COLLATION ... REFRESH VERSION` and `ALTER DATABASE ... REFRESH COLLATION VERSION`, once every rebuild in that database succeeded. **Timing.** Helm runs the hook as soon as the `Cluster` is patched, while CloudNativePG is still rolling the instances, so the primary can answer from the old image for minutes. The Job runs the new image, so it waits until the server reports the same PostgreSQL version and Debian release as its own `psql`. The rebuild counter of the package is left out, because a tag is rebuilt in place and the Job can pull a newer rebuild than the instances run. It waits only when an index depends on a versioned collation; a cluster with nothing to rebuild is not delayed. **Retries.** `REINDEX CONCURRENTLY` gives an index a new OID, so the highest OID seen when a repair begins separates the indexes still to rebuild from the ones already done. That mark is kept as a setting of the database (`cozystack.collation_repair`) with a fingerprint of the stale collations and the list of indexes rebuilt in place, and removed when the repair is complete. A retry therefore continues instead of starting over. **Failures.** A rebuild that fails does not stop the others. The pass reports the failures and exits non-zero at the end. A failed or interrupted `REINDEX CONCURRENTLY` leaves an invalid `_ccnew` index on the table; two of those mean two runs failed there, and the pass then leaves that table's stale indexes to an operator instead of scanning the table again on every retry. A rebuild that succeeds drops the leftovers; dropping them by hand lets the next run try again. An in-place rebuild leaves no such trace, so the setting records each attempt with the index's storage file: a changed file means the index was rebuilt, by a run or by hand, and two attempts on the same file leave it to an operator. A rebuild that waits for a lock behind an open transaction gives up when the Job runs out of time, and an in-place rebuild is cut off at the same point, so no backend is left waiting or holding the table after the Job is gone. A concurrent rebuild that is already running is not cut short. **Privileges.** The Job connects as the superuser, so every session of the pass sets `search_path` to `pg_catalog, pg_temp`. A function or operator that a tenant defined in `public` cannot be picked in place of a built-in. **Before PostgreSQL 15** the server records no version for a database's default collation. The version recorded for the libc collation of the same locale stands in for it; the two are matched as glibc matches them, so `en_US.UTF-8` finds `en_US.utf8`. A locale with no such collation cannot be checked, and a run that saw the image change says so in a warning that names the database. **Range partition keys.** Rebuilding an index does not move a row to the partition the new ordering assigns it. A collation that such a key depends on keeps its recorded version, so PostgreSQL keeps logging the mismatch, and the Job prints a warning that names the table on every run. Its indexes are still rebuilt, once. The pass is driven by the version mismatch, not by this particular image change, so it also applies to later glibc or ICU bumps. ### Verified `helm unittest` passes for the chart (236 tests). The e2e suite gains a step that creates a collation with a stale version, upgrades the release and checks that the index was rebuilt and the version refreshed. On a live cluster, applications were installed from the v1.7.0 chart and upgraded with this change applied on top of v1.7.0. Each had a client holding a connection, which is what makes the primary restart take minutes. | Case | Outcome | |---|---| | v17, two instances, default `C` collation only | Job finished in 15 s without waiting; data identical; `amcheck` clean | | v17, two instances, ICU, libc, expression, unique, exclusion and partition indexes | Job waited about 3.5 min for the primary, rebuilt seven indexes; `amcheck` clean; every row found through the ICU index again (run with the first revision of the pass) | | v17, two instances, backups to the system bucket | a backup taken before and one taken after the upgrade both succeed; WAL archiving continues with no failed segment, so the barman-cloud plugin covers the binaries the `standard` variant lacks | | v18, an application that had been running for months (18.1 to 18.7) | row counts identical; `amcheck` clean | | v14 (14.20 to 14.25) and v13 (13.22, base image only) with the same index set | Job waited, rebuilt six indexes; `amcheck` clean | The pass itself was also run against a live server for the cases an upgrade does not produce on demand: - a second run does nothing; - a failed rebuild leaves the other indexes rebuilt, and a later run rebuilds only the failed one; - after two failed runs the index is left alone until it is rebuilt by hand, and the pass then completes; - an exclusion constraint's index is rebuilt in place once, not again by a retry; when a writer blocks it twice it is left alone, and after a manual `REINDEX INDEX` the pass completes; - a collation under a range partition key stays stale and its indexes are not rebuilt twice; - a rebuild blocked by an open transaction fails on its lock wait and leaves no waiting backend; it succeeds once the transaction ends; - a tenant function named like a built-in is not called by the pass, while a session with the default `search_path` does call it; - on PostgreSQL 14 an index on the database default collation is rebuilt, also when the locale is spelled `en_US.UTF-8`, and a database with a locale that has no stand-in gets the warning only in a run that saw the image change; - an index whose expression or partial-index predicate reads a column of a stale collation is rebuilt, although PostgreSQL records no collation for it. ### Known limits - **A window of wrong results.** Between the primary restart and the end of the rebuild, queries through an affected index can miss rows and a unique index can accept a duplicate. The index cannot be built ahead of time, because it has to be built by the new library. A duplicate that slipped in makes that index's rebuild fail until the duplicate is removed. - **The hook budget.** The wait ends 120 seconds before the Job's deadline. A roll that takes longer fails the Job, and the next run finds the server ready. One index must be rebuilt within one run of the Job. A very large index on a non-`C` collation does not fit that: after two attempts the pass stops trying and asks for a manual `REINDEX`, and the release stays failed until then. - **Range partition keys** are reported, not repaired. - **Other dependents** of a collation, such as `CHECK` constraints and materialized views, are not examined. - **PostgreSQL 13 and 14, default collation.** A database whose locale has no libc collation in the catalog has no stand-in. Its default-collation indexes are not rebuilt; the Job warns about it and names `REINDEX DATABASE` as the remedy. - **Collations inside expressions.** An index is found through the collations that order its keys and through the columns its expressions and predicate read. A collation that an expression applies to a column of another collation, with `COLLATE` inside the expression, leaves no trace in the catalog and is missed. - **The wait is not in the e2e suite.** The e2e step does not swap the image, so it runs the rebuild but not the wait for the roll. That part is covered by the live runs above. - **PostGIS 3.6.1 to 3.7.0** on the postgis flavor is not exercised here. - **Upstream `REINDEX` advice for these minors** is not automated. The 17.12 [release notes](https://www.postgresql.org/docs/17/release-17-12.html) ask for a `REINDEX` of btree indexes on unconstrained `bpchar` columns and of `gist_trgm_ops` indexes, among others. The flavor guard is unchanged in behaviour; its comment and messages no longer claim that the two image families always differ in Debian release. ### Screenshots N/A — no UI changes. ### Downstream repositories Walked the trigger map against the diff: two version maps, the image template, the init script, a comment in `db.yaml`, the version update script and one unit test of `packages/apps/postgres`, plus one e2e suite. The `version` enum, `values.yaml`, `values.schema.json`, the README, the `ApplicationDefinition` and the release prefix are untouched. - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(postgres): tenant PostgreSQL moves to the minors that fix CVE-2026-116331 (18.7, 17.12, 16.16, 15.20, 14.25) on the standard-trixie image variant. Upgrading rolls every Postgres instance. - PostgreSQL 13 has no fixed release: it keeps 13.22 and stays exposed to CVE-2026-116331, and it still takes the image move and the index rebuild described below. 14.25 is the last release of the 14 line. Plan a move to a newer major for clusters on 13 and 14. - For the default flavor the image moves from Debian bullseye to trixie, which changes glibc and ICU. The upgrade rebuilds the indexes that depend on a non-C collation. Until that rebuild finishes such an index can return incomplete results and a unique one can accept duplicates, so plan a maintenance window if you use ICU or locale-specific collations. Databases created with the chart defaults use the C collation and are not affected. - An exclusion constraint's index is rebuilt in place, and its table is neither read nor written meanwhile. - When a rebuild cannot finish inside the upgrade Job, the release stays failed and the Job is retried. After two failed attempts the Job stops rebuilding that index, names it in its log and keeps failing until an operator steps in. Expect this for a large index on a non-C collation: rebuild it by hand with `REINDEX INDEX CONCURRENTLY`, drop the invalid `_ccnew` indexes the failed attempts left on its table, and the next run completes. A unique index fails the same way while it holds duplicates, which have to be removed first. - Tables range-partitioned on a text key with a non-C collation need a manual check, after which the collation version is refreshed by hand. - On the postgis flavor PostGIS moves from 3.6.1 to 3.7.0, and the upgrade does not update the extension in existing databases: once the new image has rolled out to the primary, run `ALTER EXTENSION postgis UPDATE` in each database that uses it. ```
This commit is contained in:
9 files changed
+410
-34
No files matched your search
@@ -249,6 +249,123 @@ spec:
|
|||||||
fi
|
fi
|
||||||
check:
|
check:
|
||||||
($error == null): true
|
($error == null): true
|
||||||
|
|
||||||
|
# The init Job rebuilds an index whose collation changed library version.
|
||||||
|
# The pass is SQL run by a Helm hook, so only a real server can say whether
|
||||||
|
# it works. A collation created with an explicit version reads as stale
|
||||||
|
# without swapping the operand image, which makes one more upgrade of the
|
||||||
|
# release enough to run the pass over it.
|
||||||
|
- name: rebuild-index-after-collation-version-change
|
||||||
|
try:
|
||||||
|
- script:
|
||||||
|
timeout: 2m
|
||||||
|
content: |
|
||||||
|
set -eu
|
||||||
|
pod=$(kubectl -n "$NAMESPACE" get pod \
|
||||||
|
-l cnpg.io/cluster=postgres-test,cnpg.io/instanceRole=primary \
|
||||||
|
-o name | head -n1)
|
||||||
|
kubectl -n "$NAMESPACE" exec -i "$pod" -c postgres -- \
|
||||||
|
psql -U postgres -d testdb -v ON_ERROR_STOP=1 <<'EOF'
|
||||||
|
CREATE COLLATION stale_icu (provider = icu, locale = 'en', version = '0');
|
||||||
|
CREATE TABLE collation_probe (s text COLLATE stale_icu);
|
||||||
|
INSERT INTO collation_probe SELECT 'v' || g FROM generate_series(1, 1000) g;
|
||||||
|
CREATE UNIQUE INDEX collation_probe_s ON collation_probe (s);
|
||||||
|
CREATE EXTENSION IF NOT EXISTS btree_gist;
|
||||||
|
CREATE TABLE collation_probe_excl (s text COLLATE stale_icu, EXCLUDE USING gist (s WITH =));
|
||||||
|
INSERT INTO collation_probe_excl SELECT 'k' || g FROM generate_series(1, 200) g;
|
||||||
|
CREATE TABLE collation_probe_before AS
|
||||||
|
SELECT 'collation_probe_s'::regclass::oid AS index,
|
||||||
|
(SELECT relfilenode FROM pg_class WHERE oid = 'collation_probe_excl_s_excl'::regclass) AS in_place_file;
|
||||||
|
EOF
|
||||||
|
check:
|
||||||
|
($error == null): true
|
||||||
|
# A declared user is the smallest change that makes Helm upgrade the
|
||||||
|
# release, and so run the hook, without restarting PostgreSQL.
|
||||||
|
- patch:
|
||||||
|
resource:
|
||||||
|
apiVersion: apps.cozystack.io/v1alpha1
|
||||||
|
kind: Postgres
|
||||||
|
metadata:
|
||||||
|
name: test
|
||||||
|
spec:
|
||||||
|
users:
|
||||||
|
collationprobe: {}
|
||||||
|
# 11m: above the 600s upgrade timeout cozystack-api gives this release.
|
||||||
|
# The step above that waited for this Job deleted it, so the Job found
|
||||||
|
# here is the one the upgrade created.
|
||||||
|
- assert:
|
||||||
|
timeout: 11m
|
||||||
|
resource:
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
metadata:
|
||||||
|
name: postgres-test-init-job
|
||||||
|
status:
|
||||||
|
(conditions[?type == 'Complete']):
|
||||||
|
- status: "True"
|
||||||
|
- script:
|
||||||
|
timeout: 2m
|
||||||
|
content: |
|
||||||
|
set -eu
|
||||||
|
pod=$(kubectl -n "$NAMESPACE" get pod \
|
||||||
|
-l cnpg.io/cluster=postgres-test,cnpg.io/instanceRole=primary \
|
||||||
|
-o name | head -n1)
|
||||||
|
q() {
|
||||||
|
kubectl -n "$NAMESPACE" exec "$pod" -c postgres -- \
|
||||||
|
psql -U postgres -d testdb -v ON_ERROR_STOP=1 -tAc "$1"
|
||||||
|
}
|
||||||
|
refreshed=$(q "SELECT collversion = pg_collation_actual_version(oid) FROM pg_collation WHERE collname = 'stale_icu'")
|
||||||
|
if [ "$refreshed" != t ]; then
|
||||||
|
echo "the init Job left the collation version stale" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# REINDEX CONCURRENTLY gives the index a new OID, so an unchanged
|
||||||
|
# one means the version was refreshed over an index nobody rebuilt.
|
||||||
|
rebuilt=$(q "SELECT 'collation_probe_s'::regclass::oid <> index FROM collation_probe_before")
|
||||||
|
if [ "$rebuilt" != t ]; then
|
||||||
|
echo "the init Job refreshed the collation version without rebuilding the index" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
q "CREATE EXTENSION IF NOT EXISTS amcheck"
|
||||||
|
q "SELECT bt_index_check('collation_probe_s', true)"
|
||||||
|
# An exclusion constraint's index is rebuilt in place: it keeps its
|
||||||
|
# OID and gets a new storage file.
|
||||||
|
rebuilt_in_place=$(q "SELECT c.relfilenode <> b.in_place_file FROM pg_class c, collation_probe_before b WHERE c.oid = 'collation_probe_excl_s_excl'::regclass")
|
||||||
|
if [ "$rebuilt_in_place" != t ]; then
|
||||||
|
echo "the init Job did not rebuild the exclusion constraint's index" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# The pass keeps its progress in a setting of the database and
|
||||||
|
# removes it once nothing is left to repair.
|
||||||
|
progress=$(q "SELECT count(*) FROM pg_db_role_setting s JOIN pg_database d ON d.oid = s.setdatabase, unnest(s.setconfig) AS c WHERE d.datname = current_database() AND c LIKE 'cozystack.collation_repair=%'")
|
||||||
|
if [ "$progress" != 0 ]; then
|
||||||
|
echo "the init Job left its repair setting on a database it finished repairing" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
leftovers=$(q "SELECT count(*) FROM pg_index WHERE NOT indisvalid")
|
||||||
|
if [ "$leftovers" != 0 ]; then
|
||||||
|
echo "the rebuild left $leftovers invalid index(es) behind" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# The Job above also completes on a retry, so a hook that failed
|
||||||
|
# first would pass unseen without this.
|
||||||
|
cd ../../..
|
||||||
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
||||||
|
statuses=$(kubectl -n "$NAMESPACE" get helmrelease postgres-test \
|
||||||
|
-o jsonpath="$HELMRELEASE_HISTORY_JSONPATH")
|
||||||
|
printf 'HelmRelease postgres-test history statuses:\n%s\n' "${statuses:-<empty>}"
|
||||||
|
if helmrelease_has_remediation_cycle "$statuses"; then
|
||||||
|
echo "HelmRelease postgres-test failed an action while the index was rebuilt" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
check:
|
||||||
|
($error == null): true
|
||||||
|
finally:
|
||||||
|
- delete:
|
||||||
|
ref:
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
name: postgres-test-init-job
|
||||||
# The Postgres CR itself was applied by chainsaw and is deleted (and waited
|
# The Postgres CR itself was applied by chainsaw and is deleted (and waited
|
||||||
# on) automatically during cleanup — no explicit teardown step needed.
|
# on) automatically during cleanup — no explicit teardown step needed.
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"v18": "18.1-3.6.1-standard-trixie"
|
"v18": "18.7-3.7.0-standard-trixie"
|
||||||
"v17": "17.7-3.6.1-standard-trixie"
|
"v17": "17.12-3.7.0-standard-trixie"
|
||||||
"v16": "16.11-3.6.1-standard-trixie"
|
"v16": "16.16-3.7.0-standard-trixie"
|
||||||
"v15": "15.15-3.6.1-standard-trixie"
|
"v15": "15.20-3.7.0-standard-trixie"
|
||||||
"v14": "14.20-3.6.1-standard-trixie"
|
"v14": "14.25-3.7.0-standard-trixie"
|
||||||
"v13": "13.22-3.6.0-standard-trixie"
|
"v13": "13.22-3.6.0-standard-trixie"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"v18": "v18.1"
|
"v18": "v18.7"
|
||||||
"v17": "v17.7"
|
"v17": "v17.12"
|
||||||
"v16": "v16.11"
|
"v16": "v16.16"
|
||||||
"v15": "v15.15"
|
"v15": "v15.20"
|
||||||
"v14": "v14.20"
|
"v14": "v14.25"
|
||||||
"v13": "v13.22"
|
"v13": "v13.22"
|
||||||
@@ -33,9 +33,10 @@ if ! command -v jq &> /dev/null; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get available image tags
|
# Get available image tags. Only standard-trixie builds count: the chart
|
||||||
|
# appends that suffix to the minor it reads from versions.yaml.
|
||||||
echo "Fetching available image tags from registry..."
|
echo "Fetching available image tags from registry..."
|
||||||
AVAILABLE_TAGS=$(skopeo list-tags docker://ghcr.io/cloudnative-pg/postgresql | jq -r '.Tags[] | select(test("^[0-9]+\\.[0-9]+$"))' | sort -V)
|
AVAILABLE_TAGS=$(skopeo list-tags docker://ghcr.io/cloudnative-pg/postgresql | jq -r '.Tags[] | select(test("^[0-9]+\\.[0-9]+-standard-trixie$")) | sub("-standard-trixie$"; "")' | sort -V)
|
||||||
|
|
||||||
if [ -z "$AVAILABLE_TAGS" ]; then
|
if [ -z "$AVAILABLE_TAGS" ]; then
|
||||||
echo "Error: Could not fetch available image tags" >&2
|
echo "Error: Could not fetch available image tags" >&2
|
||||||
|
|||||||
@@ -16,25 +16,33 @@
|
|||||||
|
|
||||||
{{/*
|
{{/*
|
||||||
Single source for the operand image: the init Job runs psql against the
|
Single source for the operand image: the init Job runs psql against the
|
||||||
Cluster, so both must resolve the same image.
|
Cluster, so both must resolve the same image, and the Job compares its own
|
||||||
|
PostgreSQL build with the server's to tell when a new image has rolled out.
|
||||||
|
|
||||||
|
standard-trixie, not the bare tag: a bare tag is the system variant on
|
||||||
|
Debian bullseye, which upstream stopped building. The standard variant,
|
||||||
|
because backups go through the barman-cloud plugin and need none of the
|
||||||
|
barman binaries the system variant adds. trixie, because the postgis
|
||||||
|
flavor is on it already, so both image families share one Debian release.
|
||||||
*/}}
|
*/}}
|
||||||
{{- define "postgres.imageName" -}}
|
{{- define "postgres.imageName" -}}
|
||||||
{{- if eq (default "postgresql" .Values.flavor) "postgis" -}}
|
{{- if eq (default "postgresql" .Values.flavor) "postgis" -}}
|
||||||
ghcr.io/cloudnative-pg/postgis:{{ include "postgres.postgisVersionMap" . | trim }}
|
ghcr.io/cloudnative-pg/postgis:{{ include "postgres.postgisVersionMap" . | trim }}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
ghcr.io/cloudnative-pg/postgresql:{{ include "postgres.versionMap" . | trim | trimPrefix "v" }}
|
ghcr.io/cloudnative-pg/postgresql:{{ include "postgres.versionMap" . | trim | trimPrefix "v" }}-standard-trixie
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{/*
|
{{/*
|
||||||
The flavor is fixed at bootstrap. The two image families are built on
|
The flavor is fixed at bootstrap. Only the postgis image carries the shared
|
||||||
different Debian releases, so moving a live cluster from one to the other
|
libraries behind PostGIS objects, so the postgis-to-postgresql direction
|
||||||
swaps glibc under an initialised data directory and silently invalidates
|
leaves every one of them without its code. The two families are also built
|
||||||
every index on collatable text; the postgis-to-postgresql direction also
|
and released separately, and nothing keeps their Debian release in step, so
|
||||||
drops the shared libraries behind every PostGIS object. CNPG would roll
|
either direction can swap glibc and ICU under an initialised data directory
|
||||||
either change out as an ordinary image update, so refuse it here, before
|
together with the flavor. CNPG would roll either change out as an ordinary
|
||||||
the Cluster is patched. Only the image name is compared: a minor bump or
|
image update, so refuse it here, before the Cluster is patched. Only the
|
||||||
a registry mirror rewriting the host must keep passing.
|
image name is compared: a minor bump, a move to another variant of the same
|
||||||
|
family, or a registry mirror rewriting the host must keep passing.
|
||||||
|
|
||||||
A physical recovery carries the same data directory across, so it is held
|
A physical recovery carries the same data directory across, so it is held
|
||||||
to the same rule. With no live Cluster of its own yet, the release is
|
to the same rule. With no live Cluster of its own yet, the release is
|
||||||
@@ -49,14 +57,14 @@ ghcr.io/cloudnative-pg/postgresql:{{ include "postgres.versionMap" . | trim | tr
|
|||||||
{{- if and $live $live.spec $live.spec.imageName -}}
|
{{- if and $live $live.spec $live.spec.imageName -}}
|
||||||
{{- $liveName := regexReplaceAll "[:@].*$" (last (splitList "/" $live.spec.imageName)) "" -}}
|
{{- $liveName := regexReplaceAll "[:@].*$" (last (splitList "/" $live.spec.imageName)) "" -}}
|
||||||
{{- if ne $liveName $wantName -}}
|
{{- if ne $liveName $wantName -}}
|
||||||
{{- fail (printf "postgres: flavor cannot change on an existing cluster (running %s, requested %s). The image families use different glibc versions, which would corrupt text indexes. Create a new Postgres with the wanted flavor and move the data with a logical dump (pg_dump / pg_restore); restoring a backup keeps the flavor it was taken from." $liveName $wantName) -}}
|
{{- fail (printf "postgres: flavor cannot change on an existing cluster (running %s, requested %s). Only the postgis image carries the PostGIS libraries, and the two image families can differ in glibc and ICU, which corrupts text indexes. Create a new Postgres with the wanted flavor and move the data with a logical dump (pg_dump / pg_restore); restoring a backup keeps the flavor it was taken from." $liveName $wantName) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- else if and .Values.bootstrap.enabled .Values.bootstrap.oldName -}}
|
{{- else if and .Values.bootstrap.enabled .Values.bootstrap.oldName -}}
|
||||||
{{- $source := lookup "postgresql.cnpg.io/v1" "Cluster" .Release.Namespace .Values.bootstrap.oldName -}}
|
{{- $source := lookup "postgresql.cnpg.io/v1" "Cluster" .Release.Namespace .Values.bootstrap.oldName -}}
|
||||||
{{- if and $source $source.spec $source.spec.imageName -}}
|
{{- if and $source $source.spec $source.spec.imageName -}}
|
||||||
{{- $sourceName := regexReplaceAll "[:@].*$" (last (splitList "/" $source.spec.imageName)) "" -}}
|
{{- $sourceName := regexReplaceAll "[:@].*$" (last (splitList "/" $source.spec.imageName)) "" -}}
|
||||||
{{- if ne $sourceName $wantName -}}
|
{{- if ne $sourceName $wantName -}}
|
||||||
{{- fail (printf "postgres: cannot recover a %s backup of %s into the %s flavor. A physical restore keeps the source's glibc and libraries, which would corrupt text indexes. Set flavor to match the source, or create the new Postgres empty and move the data with a logical dump (pg_dump / pg_restore)." $sourceName .Values.bootstrap.oldName $wantName) -}}
|
{{- fail (printf "postgres: cannot recover a %s backup of %s into the %s flavor. A physical restore carries over a data directory built with the source's libraries: PostGIS objects need the postgis image, and a glibc or ICU difference corrupts text indexes. Set flavor to match the source, or create the new Postgres empty and move the data with a logical dump (pg_dump / pg_restore)." $sourceName .Values.bootstrap.oldName $wantName) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
@@ -176,11 +176,9 @@ spec:
|
|||||||
The S3/barman settings live in the barmancloud.cnpg.io/ObjectStore CR
|
The S3/barman settings live in the barmancloud.cnpg.io/ObjectStore CR
|
||||||
rendered at the bottom of this file (named after the release); the
|
rendered at the bottom of this file (named after the release); the
|
||||||
Cluster only references it by name. Native spec.backup.barmanObjectStore
|
Cluster only references it by name. Native spec.backup.barmanObjectStore
|
||||||
is deprecated in CNPG 1.27 and removed in 1.29. The bare (system-flavor)
|
is deprecated in CNPG 1.27 and removed in 1.29, and the standard image
|
||||||
image tags this chart pins still ship the barman-cloud-* binaries the
|
variant this chart pins does not ship the barman-cloud-* binaries the
|
||||||
native path needs (unlike the `standard` variant keycloak-db pins), but
|
native path needs; the plugin runs them in a sidecar.
|
||||||
the system flavor is deprecated upstream, so this chart moves to the
|
|
||||||
plugin as well.
|
|
||||||
*/}}
|
*/}}
|
||||||
{{- $hasInlineCreds := and (ne (default "" .Values.backup.s3AccessKey) "") (ne (default "" .Values.backup.s3SecretKey) "") }}
|
{{- $hasInlineCreds := and (ne (default "" .Values.backup.s3AccessKey) "") (ne (default "" .Values.backup.s3SecretKey) "") }}
|
||||||
{{- $hasLegacyCreds := or $hasInlineCreds (ne (default "" $credCfg.name) "") }}
|
{{- $hasLegacyCreds := or $hasInlineCreds (ne (default "" $credCfg.name) "") }}
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ spec:
|
|||||||
is idempotent and the purged pod stays Pending on the missing mount, so a retry
|
is idempotent and the purged pod stays Pending on the missing mount, so a retry
|
||||||
buys nothing.
|
buys nothing.
|
||||||
*/}}
|
*/}}
|
||||||
activeDeadlineSeconds: {{ if .Release.IsInstall }}570{{ else }}540{{ end }}
|
{{- $deadline := ternary 570 540 .Release.IsInstall }}
|
||||||
|
activeDeadlineSeconds: {{ $deadline }}
|
||||||
backoffLimit: 0
|
backoffLimit: 0
|
||||||
ttlSecondsAfterFinished: 3600
|
ttlSecondsAfterFinished: 3600
|
||||||
template:
|
template:
|
||||||
@@ -77,6 +78,8 @@ spec:
|
|||||||
value: "5432"
|
value: "5432"
|
||||||
- name: PGDATABASE
|
- name: PGDATABASE
|
||||||
value: postgres
|
value: postgres
|
||||||
|
- name: JOB_DEADLINE
|
||||||
|
value: {{ $deadline | quote }}
|
||||||
securityContext:
|
securityContext:
|
||||||
allowPrivilegeEscalation: false
|
allowPrivilegeEscalation: false
|
||||||
capabilities:
|
capabilities:
|
||||||
|
|||||||
@@ -591,6 +591,255 @@ stringData:
|
|||||||
EOT
|
EOT
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- /*
|
||||||
|
An operand image built on another Debian release ships another glibc and
|
||||||
|
ICU, and an index ordered by a collation of either library is then
|
||||||
|
ordered by rules the server no longer applies: lookups miss rows and a
|
||||||
|
unique index stops seeing duplicates. PostgreSQL records the library
|
||||||
|
version each collation was created with, so a collation whose recorded
|
||||||
|
version differs from the one the server reports marks the indexes to
|
||||||
|
rebuild. The C and POSIX collations carry no version and never qualify,
|
||||||
|
which is every index of a database this chart created with its defaults.
|
||||||
|
|
||||||
|
PostgreSQL records a collation for an index only where it orders a key.
|
||||||
|
A collation can also decide what an index holds without ordering it, in
|
||||||
|
a predicate or inside an expression, and for those the catalog names
|
||||||
|
the columns the index reads and nothing else. The collations of those
|
||||||
|
columns therefore count as well. That rebuilds an index or two that did
|
||||||
|
not need it, and still misses a collation that an expression applies to
|
||||||
|
a column of another one.
|
||||||
|
|
||||||
|
This pass comes after the ones that manage roles and databases, so
|
||||||
|
that a rebuild that fails, or does not finish before the Job deadline,
|
||||||
|
costs none of them. Only the record of an adopted restore follows it:
|
||||||
|
that record must not be written by a run that failed.
|
||||||
|
|
||||||
|
Helm runs this hook as soon as the Cluster is patched, while CNPG is
|
||||||
|
still rolling the instances, so the primary may answer from the previous
|
||||||
|
image for minutes. The Job runs the image the Cluster is moving to, so
|
||||||
|
the server is on it once both report the same PostgreSQL version and
|
||||||
|
the same Debian release. The rebuild counter that follows them is left
|
||||||
|
out: a tag is rebuilt in place, so the Job and an instance can run
|
||||||
|
different rebuilds of one release for good. Waiting is only worth its
|
||||||
|
time when an index depends on a versioned collation. The wait ends 120
|
||||||
|
seconds before the Job's deadline, which is what a first run keeps for
|
||||||
|
rebuilding.
|
||||||
|
|
||||||
|
Rebuilds survive a retry: REINDEX CONCURRENTLY gives the index a new
|
||||||
|
OID, so the highest OID seen when the repair began separates the
|
||||||
|
indexes still to rebuild from the ones already done. That mark is kept
|
||||||
|
as a setting of the database, next to a fingerprint of the stale
|
||||||
|
collations and their new versions, so another library change starts a
|
||||||
|
new repair. An exclusion constraint's index cannot be rebuilt
|
||||||
|
concurrently: its table is neither read nor written while it is rebuilt
|
||||||
|
in place, and it keeps its OID. The same setting therefore records each
|
||||||
|
attempt at one together with the index's storage file: a file that has
|
||||||
|
changed since means the index was rebuilt, by a run or by hand, and two
|
||||||
|
attempts on the same file mean two runs did not finish, after which the
|
||||||
|
index is left to an operator. The rebuild is given what is left of the
|
||||||
|
Job and no more, so that the table is not kept locked by a backend the
|
||||||
|
Job no longer waits for.
|
||||||
|
|
||||||
|
A transaction that stays open on the table makes a rebuild wait for a
|
||||||
|
lock. That wait is bounded by what is left of the Job as well, so that
|
||||||
|
no backend is left waiting for a lock after the Job is gone. A
|
||||||
|
concurrent rebuild that is already running is not cut short: it blocks
|
||||||
|
nobody, and the index it finishes counts as done. Both bounds keep a
|
||||||
|
minute in reserve: the deadline counts from the start of the Job,
|
||||||
|
$SECONDS from the start of this script.
|
||||||
|
|
||||||
|
One index must be rebuilt within one run of the Job, and a retry would
|
||||||
|
otherwise start a rebuild that cannot finish over and over. An
|
||||||
|
interrupted or failed REINDEX CONCURRENTLY leaves an invalid index with
|
||||||
|
a _ccnew suffix on the table, so two of those mean two runs already
|
||||||
|
failed there: the pass then leaves the table's stale indexes alone
|
||||||
|
until an operator has dropped the leftovers. A rebuild that succeeds
|
||||||
|
drops them itself. A failed or
|
||||||
|
skipped rebuild does not stop the others: the pass reports them and
|
||||||
|
exits non-zero at the end, with the recorded versions of that database
|
||||||
|
left as they are.
|
||||||
|
|
||||||
|
A collation that a range partition key depends on is never refreshed:
|
||||||
|
rebuilding an index does not move a row to the partition the new
|
||||||
|
ordering assigns it, and the version mismatch PostgreSQL keeps logging
|
||||||
|
is the only lasting sign of that. Its indexes are still rebuilt, and
|
||||||
|
again only when another collation of the database goes stale.
|
||||||
|
Before PostgreSQL 15 the server records no version for a database's
|
||||||
|
default collation. The version recorded for the libc collation of the
|
||||||
|
same locale stands in for it there, and is refreshed in its place; the
|
||||||
|
two are matched as glibc matches them, without regard to the case of
|
||||||
|
the codeset or a hyphen in it. A locale with no such collation cannot
|
||||||
|
be checked, which a run that saw the image change says in a warning.
|
||||||
|
|
||||||
|
Every session of the pass pins search_path to pg_catalog: the Job
|
||||||
|
connects as the superuser, and a function or operator a tenant defined
|
||||||
|
in public would otherwise be picked wherever its argument types match
|
||||||
|
a call more exactly than the built-in does.
|
||||||
|
*/}}
|
||||||
|
|
||||||
|
echo "== refresh collation versions"
|
||||||
|
collation_sql() {
|
||||||
|
cat <<\EOT
|
||||||
|
SET client_min_messages = error;
|
||||||
|
SET search_path = pg_catalog, pg_temp;
|
||||||
|
SELECT current_setting('server_version_num')::int >= 150000 AS tracks_database \gset
|
||||||
|
\if :tracks_database
|
||||||
|
SELECT datcollversion IS NOT NULL AS db_versioned, coalesce(pg_database_collation_actual_version(oid), '') AS db_actual, datcollversion IS NOT NULL AND datcollversion IS DISTINCT FROM pg_database_collation_actual_version(oid) AS db_stale, false AS db_unmatched FROM pg_database WHERE datname = current_database() \gset
|
||||||
|
\else
|
||||||
|
SELECT d.datcollate NOT IN ('C', 'POSIX') AS db_versioned,
|
||||||
|
coalesce(max(pg_collation_actual_version(c.oid)), '') AS db_actual,
|
||||||
|
coalesce(bool_or(c.collversion IS DISTINCT FROM pg_collation_actual_version(c.oid)), false) AS db_stale,
|
||||||
|
d.datcollate NOT IN ('C', 'POSIX') AND count(c.oid) = 0 AS db_unmatched
|
||||||
|
FROM pg_database d
|
||||||
|
LEFT JOIN pg_collation c ON c.collprovider = 'c' AND lower(replace(c.collcollate, '-', '')) = lower(replace(d.datcollate, '-', '')) AND c.collversion IS NOT NULL AND c.collencoding IN (-1, d.encoding)
|
||||||
|
WHERE d.datname = current_database()
|
||||||
|
GROUP BY d.datcollate \gset
|
||||||
|
\endif
|
||||||
|
CREATE TEMP TABLE cozystack_collation AS
|
||||||
|
SELECT v.oid, v.actual, v.stale,
|
||||||
|
EXISTS (SELECT FROM pg_partitioned_table p WHERE p.partstrat = 'r' AND v.oid = ANY (p.partcollation::oid[])) AS held
|
||||||
|
FROM (
|
||||||
|
SELECT c.oid, coalesce(pg_collation_actual_version(c.oid), '') AS actual, c.collversion IS DISTINCT FROM pg_collation_actual_version(c.oid) AS stale
|
||||||
|
FROM pg_collation c
|
||||||
|
WHERE c.collversion IS NOT NULL
|
||||||
|
AND c.collencoding IN (-1, (SELECT encoding FROM pg_database WHERE datname = current_database()))
|
||||||
|
UNION ALL
|
||||||
|
SELECT 100, :'db_actual', :'db_stale'::boolean WHERE :'db_versioned'::boolean
|
||||||
|
) v;
|
||||||
|
CREATE TEMP TABLE cozystack_collation_index AS
|
||||||
|
SELECT i.indexrelid AS index, bool_or(c.stale) AS stale
|
||||||
|
FROM (
|
||||||
|
SELECT x.indexrelid, k.used FROM pg_index x, unnest(x.indcollation::oid[]) AS k(used)
|
||||||
|
UNION
|
||||||
|
SELECT d.objid, d.refobjid FROM pg_depend d WHERE d.classid = 'pg_class'::regclass AND d.refclassid = 'pg_collation'::regclass
|
||||||
|
UNION
|
||||||
|
SELECT d.objid, a.attcollation FROM pg_depend d JOIN pg_attribute a ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid
|
||||||
|
WHERE d.classid = 'pg_class'::regclass AND d.refclassid = 'pg_class'::regclass AND d.refobjsubid > 0 AND a.attcollation <> 0
|
||||||
|
) u
|
||||||
|
JOIN cozystack_collation c ON c.oid = u.used
|
||||||
|
JOIN pg_index i ON i.indexrelid = u.indexrelid
|
||||||
|
JOIN pg_class r ON r.oid = i.indexrelid
|
||||||
|
WHERE r.relkind = 'i' AND r.relpersistence <> 't' AND i.indisvalid
|
||||||
|
GROUP BY 1;
|
||||||
|
EOT
|
||||||
|
}
|
||||||
|
collation_run() {
|
||||||
|
{ collation_sql; cat; } | psql -v ON_ERROR_STOP=1 -q -t -A --dbname "$1" -v moved="$IMAGE_MOVED"
|
||||||
|
}
|
||||||
|
IMAGE_MOVED=false
|
||||||
|
pg_release() {
|
||||||
|
sed -E 's/^([0-9.]+) \(Debian [^)]*(pgdg[0-9]+)\+[0-9]+\)$/\1 \2/'
|
||||||
|
}
|
||||||
|
server_release() {
|
||||||
|
psql -t -A -c 'SHOW server_version' 2>/dev/null | pg_release
|
||||||
|
}
|
||||||
|
JOB_RELEASE=$(psql -V | sed 's/^psql (PostgreSQL) //' | pg_release)
|
||||||
|
COLLATION_DBS=$(psql -v ON_ERROR_STOP=1 -t -A -c "SELECT datname FROM pg_database WHERE datallowconn AND NOT datistemplate")
|
||||||
|
if [ "$(server_release)" != "$JOB_RELEASE" ]; then
|
||||||
|
IMAGE_MOVED=true
|
||||||
|
DEPENDENT=""
|
||||||
|
for db in $COLLATION_DBS; do
|
||||||
|
DEPENDENT="$DEPENDENT$(collation_run "$db" <<\EOT
|
||||||
|
SELECT index FROM cozystack_collation_index;
|
||||||
|
EOT
|
||||||
|
)"
|
||||||
|
done
|
||||||
|
if [ -n "$DEPENDENT" ]; then
|
||||||
|
echo "indexes depend on a versioned collation; waiting for the server to run PostgreSQL $JOB_RELEASE"
|
||||||
|
until [ "$(server_release)" = "$JOB_RELEASE" ]; do
|
||||||
|
if [ "$SECONDS" -ge $((JOB_DEADLINE - 120)) ]; then
|
||||||
|
echo "the server did not move to PostgreSQL $JOB_RELEASE in time (check the rollout of the cnpg.io/Cluster); indexes that depend on a versioned collation are not rebuilt yet - failing the init-job, the next run of it rebuilds them" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
COLLATION_FAILED=""
|
||||||
|
for db in $COLLATION_DBS; do
|
||||||
|
PLAN=$(collation_run "$db" <<\EOT
|
||||||
|
SELECT coalesce(md5(string_agg(oid || '=' || actual, ',' ORDER BY oid)), '') AS fingerprint FROM cozystack_collation WHERE stale \gset
|
||||||
|
SELECT coalesce(current_setting('cozystack.collation_repair', true), '') AS recorded \gset
|
||||||
|
SELECT :'fingerprint' <> '' AND split_part(:'recorded', ':', 1) = :'fingerprint' AS resumed \gset
|
||||||
|
\if :resumed
|
||||||
|
SELECT split_part(:'recorded', ':', 2) AS mark, split_part(:'recorded', ':', 3) AS inplace \gset
|
||||||
|
\else
|
||||||
|
SELECT max(oid)::bigint AS mark, '' AS inplace FROM pg_class \gset
|
||||||
|
SELECT format('ALTER DATABASE %I SET cozystack.collation_repair = %L', current_database(), :'fingerprint' || ':' || :'mark') WHERE :'fingerprint' <> '' \gexec
|
||||||
|
\endif
|
||||||
|
SELECT index::bigint FROM cozystack_collation_index WHERE stale AND index::bigint <= :'mark'::bigint AND NOT EXISTS (SELECT FROM unnest(string_to_array(:'inplace', ',')) AS e JOIN pg_class r ON r.oid = index WHERE split_part(e, '/', 1) = index::text AND split_part(e, '/', 2) <> r.relfilenode::text) ORDER BY pg_relation_size(index);
|
||||||
|
EOT
|
||||||
|
)
|
||||||
|
DB_FAILED=""
|
||||||
|
for index in $PLAN; do
|
||||||
|
LEFT=$((JOB_DEADLINE - SECONDS - 60))
|
||||||
|
if [ "$LEFT" -lt 10 ]; then
|
||||||
|
echo "index $index in database $db was not rebuilt: the init-job is out of time, the next run of it carries on" >&2
|
||||||
|
DB_FAILED=yes
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if ! psql -v ON_ERROR_STOP=1 -q -t -A --dbname "$db" -v index="$index" -v lock_wait="${LEFT}s" <<\EOT
|
||||||
|
SET client_min_messages = error;
|
||||||
|
SET search_path = pg_catalog, pg_temp;
|
||||||
|
SET lock_timeout = :'lock_wait';
|
||||||
|
SELECT count(*) = 1 AS present FROM pg_index WHERE indexrelid = :'index'::oid \gset
|
||||||
|
\if :present
|
||||||
|
SELECT coalesce(current_setting('cozystack.collation_repair', true), '') AS recorded \gset
|
||||||
|
SELECT i.indrelid AS relation, i.indisexclusion AS exclusion, i.indexrelid::regclass AS name, :'index' || '/' || r.relfilenode AS attempt,
|
||||||
|
(SELECT count(*) FROM pg_index l JOIN pg_class n ON n.oid = l.indexrelid WHERE l.indrelid = i.indrelid AND NOT l.indisvalid AND n.relname ~ '_ccnew[0-9]*$') >= 2 AS abandoned,
|
||||||
|
(SELECT count(*) FROM unnest(string_to_array(split_part(:'recorded', ':', 3), ',')) AS e WHERE e = :'index' || '/' || r.relfilenode) >= 2 AS abandoned_in_place
|
||||||
|
FROM pg_index i JOIN pg_class r ON r.oid = i.indexrelid WHERE i.indexrelid = :'index'::oid \gset
|
||||||
|
\if :abandoned
|
||||||
|
SELECT format('DO %L', format('BEGIN RAISE EXCEPTION %L, %L; END', '%', format('index %s in database %s was left alone: two earlier runs failed to rebuild an index of its table, and each left an invalid _ccnew index there. Fix what made them fail, then drop those _ccnew indexes; the next run of the init-job rebuilds this one', :'name', current_database()))) \gexec
|
||||||
|
\endif
|
||||||
|
\if :exclusion
|
||||||
|
\if :abandoned_in_place
|
||||||
|
SELECT format('DO %L', format('BEGIN RAISE EXCEPTION %L, %L; END', '%', format('index %s in database %s was left alone: two earlier runs began rebuilding it in place and did not finish. Rebuild it by hand with REINDEX INDEX, which blocks its table meanwhile; the next run of the init-job sees that it was rebuilt', :'name', current_database()))) \gexec
|
||||||
|
\endif
|
||||||
|
SELECT format('rebuilding index %s in database %s in place: its collation changed version', :'name', current_database());
|
||||||
|
SELECT format('ALTER DATABASE %I SET cozystack.collation_repair = %L', current_database(), split_part(:'recorded', ':', 1) || ':' || split_part(:'recorded', ':', 2) || ':' || concat_ws(',', nullif(split_part(:'recorded', ':', 3), ''), :'attempt')) WHERE :'recorded' <> '' \gexec
|
||||||
|
SET statement_timeout = :'lock_wait';
|
||||||
|
SELECT format('REINDEX INDEX %s', :'name') \gexec
|
||||||
|
RESET statement_timeout;
|
||||||
|
\else
|
||||||
|
SELECT format('rebuilding index %s in database %s: its collation changed version', :'name', current_database());
|
||||||
|
SELECT format('REINDEX INDEX CONCURRENTLY %s', :'name') \gexec
|
||||||
|
\endif
|
||||||
|
SELECT format('DROP INDEX CONCURRENTLY IF EXISTS %s', l.indexrelid::regclass) FROM pg_index l JOIN pg_class n ON n.oid = l.indexrelid WHERE l.indrelid = :'relation'::oid AND NOT l.indisvalid AND n.relname ~ '_ccnew[0-9]*$' \gexec
|
||||||
|
\endif
|
||||||
|
EOT
|
||||||
|
then
|
||||||
|
DB_FAILED=yes
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -n "$DB_FAILED" ]; then
|
||||||
|
COLLATION_FAILED="$COLLATION_FAILED $db"
|
||||||
|
else
|
||||||
|
collation_run "$db" <<\EOT
|
||||||
|
SELECT format('WARNING: database %s uses the locale %s, for which this PostgreSQL major records no collation version and the catalog has no collation to stand in; the indexes on its default collation were not checked. If this upgrade moved the image to another Debian release, rebuild them with REINDEX DATABASE', datname, datcollate) FROM pg_database WHERE datname = current_database() AND :'db_unmatched'::boolean AND :'moved'::boolean;
|
||||||
|
SELECT format('WARNING: %s in database %s is range-partitioned on a key whose collation changed version; rows stored before the change may now belong to another partition, and the collation version is left as recorded until that is checked', p.partrelid::regclass, current_database()) FROM pg_partitioned_table p WHERE p.partstrat = 'r' AND EXISTS (SELECT FROM cozystack_collation c WHERE c.stale AND c.oid = ANY (p.partcollation::oid[]));
|
||||||
|
DO $$
|
||||||
|
DECLARE
|
||||||
|
entry record;
|
||||||
|
BEGIN
|
||||||
|
FOR entry IN SELECT c.oid::regcollation AS name FROM cozystack_collation c WHERE c.stale AND NOT c.held AND c.oid <> 100
|
||||||
|
AND NOT (current_setting('server_version_num')::int < 150000
|
||||||
|
AND EXISTS (SELECT FROM cozystack_collation d WHERE d.oid = 100 AND d.held)
|
||||||
|
AND c.oid IN (SELECT n.oid FROM pg_collation n JOIN pg_database d ON d.datname = current_database() WHERE n.collprovider = 'c' AND lower(replace(n.collcollate, '-', '')) = lower(replace(d.datcollate, '-', '')))) LOOP
|
||||||
|
EXECUTE format('ALTER COLLATION %s REFRESH VERSION', entry.name);
|
||||||
|
END LOOP;
|
||||||
|
END$$;
|
||||||
|
SELECT format('ALTER DATABASE %I REFRESH COLLATION VERSION', current_database()) FROM cozystack_collation WHERE oid = 100 AND stale AND NOT held AND current_setting('server_version_num')::int >= 150000 \gexec
|
||||||
|
SELECT coalesce(md5(string_agg(oid || '=' || actual, ',' ORDER BY oid)), '') AS remaining FROM cozystack_collation WHERE stale AND held \gset
|
||||||
|
SELECT CASE WHEN :'remaining' = '' THEN '' ELSE :'remaining' || ':0' END AS settled \gset
|
||||||
|
SELECT CASE WHEN :'settled' = '' THEN format('ALTER DATABASE %I RESET cozystack.collation_repair', current_database()) ELSE format('ALTER DATABASE %I SET cozystack.collation_repair = %L', current_database(), :'settled') END WHERE coalesce(current_setting('cozystack.collation_repair', true), '') <> :'settled' \gexec
|
||||||
|
EOT
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -n "$COLLATION_FAILED" ]; then
|
||||||
|
echo "index rebuilds failed in:$COLLATION_FAILED (the errors are above); the other indexes were rebuilt. A unique index cannot be rebuilt over rows that the previous ordering kept apart and the new one treats as equal, so remove such duplicates. The next run of the init-job tries again, except for an index an error above reports as left alone" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
{{- if .Values.bootstrap.newServerName }}
|
{{- if .Values.bootstrap.newServerName }}
|
||||||
|
|
||||||
echo "== record the adopted restore"
|
echo "== record the adopted restore"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
suite: postgres image flavor
|
suite: postgres image flavor
|
||||||
# The Cluster and the init Job must resolve the same image, and a live
|
# The Cluster and the init Job must resolve the same image, and a live
|
||||||
# cluster must never be moved to the other flavor: the two image families
|
# cluster must never be moved to the other flavor: only one image family
|
||||||
# ship different glibc versions, so CNPG would roll an image swap that
|
# carries the PostGIS libraries, and CNPG would roll the swap out as an
|
||||||
# corrupts collatable indexes. Tags are matched by pattern so that
|
# ordinary image update. Tags are matched by pattern so that
|
||||||
# hack/update-versions.sh can bump minors without touching this suite.
|
# hack/update-versions.sh can bump minors without touching this suite.
|
||||||
release:
|
release:
|
||||||
name: pg-test
|
name: pg-test
|
||||||
@@ -20,7 +20,7 @@ tests:
|
|||||||
asserts:
|
asserts:
|
||||||
- matchRegex:
|
- matchRegex:
|
||||||
path: spec.imageName
|
path: spec.imageName
|
||||||
pattern: ^ghcr\.io/cloudnative-pg/postgresql:18\.[0-9]+$
|
pattern: ^ghcr\.io/cloudnative-pg/postgresql:18\.[0-9]+-standard-trixie$
|
||||||
|
|
||||||
- it: postgis flavor switches the Cluster to the standard-trixie PostGIS image
|
- it: postgis flavor switches the Cluster to the standard-trixie PostGIS image
|
||||||
set:
|
set:
|
||||||
|
|||||||
Reference in new issue
Block a user