Conversation
Random corruption occurs over time on indexes. To avoid this, we rework the upgrade process and use a version of postgres where the libc doesn't change
There was a problem hiding this comment.
Pull request overview
Reworks parts of the Postgres upgrade/post-run process to reduce index corruption risk over time, and pins the Postgres Docker image tag to an OS-specific variant to avoid libc changes.
Changes:
- Update default
docker_postgres_tagto an OS-specific tag ({{ db_pg_version }}-trixie). - Add a new post-run upgrade step (20260128) intended to reindex/vacuum and refresh collation versions.
- Enhance post-major-upgrade DB maintenance tasks (extensions update, reindex, collation refresh, vacuum in stages).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| roles/prepare_vars/defaults/main/docker_images.yml | Changes Postgres image tag default to include OS suffix. |
| roles/post_run/tasks/main.yml | Adds inclusion of the new 20260128 post-run DB maintenance tasks. |
| roles/post_run/tasks/db_upgraded.yml | Adds extension upgrade + reindex/collation refresh; changes vacuum behavior. |
| roles/post_run/tasks/20260128.yml | Introduces a new maintenance task file for the 20260128 upgrade step. |
| README.md | Updates documented default for docker_postgres_tag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
roles/post_run/tasks/db_upgraded.yml
Outdated
| psql -U {{ lookup('vars', 'db_'+_db.name+'_user') }} -d "{{ _db.name }}" -c " | ||
| SELECT 'ALTER EXTENSION ' || quote_ident(extname) || ' UPDATE;' | ||
| FROM pg_extension; | ||
| " |
There was a problem hiding this comment.
This task currently only SELECTs ALTER EXTENSION ... UPDATE; statements and prints them; it does not actually execute the ALTER EXTENSION commands, so extensions will not be upgraded as intended. Use a DO block/loop (or generate commands and execute them) so the updates are applied.
| psql -U {{ lookup('vars', 'db_'+_db.name+'_user') }} -d "{{ _db.name }}" -c " | |
| SELECT 'ALTER EXTENSION ' || quote_ident(extname) || ' UPDATE;' | |
| FROM pg_extension; | |
| " | |
| psql -U {{ lookup('vars', 'db_'+_db.name+'_user') }} -d "{{ _db.name }}" -v ON_ERROR_STOP=1 -c "DO \$\$DECLARE r record; BEGIN FOR r IN SELECT extname FROM pg_extension LOOP EXECUTE format('ALTER EXTENSION %I UPDATE', r.extname); END LOOP; END\$\$;" |
| # We should use docker_compose_v2_exec when ansible will be updated to 11 or another version that support it | ||
| # With this module we could avoid relaying on container name |
There was a problem hiding this comment.
This file is missing the YAML document start marker (---). The repo's .yamllint enforces document-start: present: true, so this will fail linting.
roles/post_run/tasks/20260128.yml
Outdated
| - name: "Re-index the database to avoid corruption of some indexes on the database {{ _db.name }}" | ||
| community.docker.docker_container_exec: | ||
| container: "{{ db_info.name }}-db" |
There was a problem hiding this comment.
This task name interpolates {{ _db.name }}, but _db is not defined in this include (the loop var is db_info). Undefined variables in task names will raise errors in Ansible; update the task name to use db_info.name (and keep naming consistent across the file).
roles/post_run/tasks/20260128.yml
Outdated
| - name: "Run Postgres vaccum analyze on the database {{ db_info.name }} on the database {{ _db.name }}" | ||
| community.docker.docker_container_exec: |
There was a problem hiding this comment.
This task name references {{ _db.name }} (undefined here) and also contains duplicated text ("on the database ... on the database ..."). Update the name to use db_info.name and remove the duplication to avoid Ansible undefined-variable failures and improve readability.
README.md
Outdated
| | docker_postgres_image | "postgres" | Postgres docker image (use Dockerhub by default). | | ||
| | docker_postgres_tag | "{{ db_pg_version }}-alpine" | Postgres docker tag. | | ||
| | docker_postgres_tag | "{{ db_pg_version }}-trixie" | Postgres docker tag. | | ||
| | docker_bimdata_tag | "{{ bimdata_version }} | Docker tag use by all bimdata images. | |
There was a problem hiding this comment.
The README table row for docker_bimdata_tag has a malformed default value (missing closing }}"), which breaks the markdown table formatting and shows an incorrect value to users. Please fix it to "{{ bimdata_version }}".
| | docker_bimdata_tag | "{{ bimdata_version }} | Docker tag use by all bimdata images. | | |
| | docker_bimdata_tag | "{{ bimdata_version }}" | Docker tag use by all bimdata images. | |
|
|
||
| docker_postgres_image: postgres # Only use when use_external_db: false | ||
| docker_postgres_tag: "{{ db_pg_version }}" | ||
| docker_postgres_tag: "{{ db_pg_version }}-trixie" # use a tag with OS in it to avoid unplanified libc upgrade |
There was a problem hiding this comment.
The comment contains a spelling mistake: "unplanified" should be "unplanned" (and consider rephrasing to "avoid an unplanned libc upgrade").
| docker_postgres_tag: "{{ db_pg_version }}-trixie" # use a tag with OS in it to avoid unplanified libc upgrade | |
| docker_postgres_tag: "{{ db_pg_version }}-trixie" # use a tag with OS in it to avoid an unplanned libc upgrade |
roles/post_run/tasks/main.yml
Outdated
| - inventory_hostname in groups["db"] | ||
| - not use_external_db | bool | ||
| - db_info.current_version != "" | ||
| - db_info.current_version is version(db_pg_version, "==") |
There was a problem hiding this comment.
This include condition compares db_info.current_version (read from PG_VERSION and typically just the major version) to db_pg_version without normalizing db_pg_version the way other upgrade logic does (e.g., splitting on '.' to get the major). If db_pg_version is ever configured as a full semver (e.g. "17.2"), this condition will evaluate false and the 20260128 tasks will never run.
| - db_info.current_version is version(db_pg_version, "==") | |
| - db_info.current_version is version(db_pg_version.split('.') | first, "==") |
Random corruption occurs over time on indexes.
To avoid this, we rework the upgrade process and
use a version of postgres where the libc doesn't change