Fail backup preflight when database index check detects corruption
Maintainers usually reply within 3 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start with src/roles/backup/tasks/preflight.yaml and trace how it invokes the check_database_index role; inspect that role's task and rescue block to see how bt_index_check failures are handled. Confirm the check and backup preflight both fail on the synthetic corruption described in the issue, while a healthy database still passes without interrupting services.
Written by the indexing model from the issue text.
Description
Problem
The check_database_index role runs PostgreSQL amcheck (bt_index_check) against each database. If the integrity query fails, the role's rescue block only printed a debug message:
FAILED - indexes may be corrupted
It never failed the play, so the role returned success. The role is used by the backup preflight (src/roles/backup/tasks/preflight.yaml), so foremanctl backup carried on and produced a backup of a database that is already corrupted. The problem would only show up at restore time.
How reproducible
Always (with the synthetic corruption steps below; does not touch real application data).
Steps to Reproduce
Run as the PostgreSQL superuser in the foreman database (adjust the container name if needed):
podman exec -it postgresql psql -U postgres -d foreman
CREATE EXTENSION IF NOT EXISTS amcheck;
CREATE TABLE public.zz_amcheck_demo (id int);
INSERT INTO public.zz_amcheck_demo SELECT generate_series(1, 1000);
CREATE UNIQUE INDEX zz_amcheck_demo_idx ON public.zz_amcheck_demo (id);
GRANT ALL ON public.zz_amcheck_demo TO foreman;
-- rows added while the index is not maintained
UPDATE pg_index SET indisready = false WHERE indexrelid = 'public.zz_amcheck_demo_idx'::regclass;
INSERT INTO public.zz_amcheck_demo SELECT generate_series(1001, 1100);
UPDATE pg_index SET indisready = true WHERE indexrelid = 'public.zz_amcheck_demo_idx'::regclass;
SELECT bt_index_check(index => 'public.zz_amcheck_demo_idx'::regclass, heapallindexed => true);
-- ERROR: heap tuple (...) from table "zz_amcheck_demo" lacks matching index tuple ...
Then run foremanctl checks and foremanctl backup <dir>.
Cleanup: DROP TABLE public.zz_amcheck_demo; and, if the extension was not installed before, DROP EXTENSION amcheck;.
Note: the role only runs when the amcheck extension is installed in the database, and it only checks btree indexes in the public schema.
Actual results
foremanctl checks / backup preflight rescue only logs debug and returns success; backup continues.
Expected results
Both commands fail with a clear amcheck failure; backup aborts in preflight without creating foreman-backup-* or stopping services.
Test results
Tested manually on Satellite 6.20 with foremanctl-3.3.1-1.el10sat, using the table above in the foreman database.
| Scenario | Before the fix | After the fix |
|---|---|---|
foremanctl checks, corrupted index |
exit 0, failed=0 rescued=1 |
exit 2, failed=1 |
foremanctl backup, corrupted index |
continues past preflight | aborts in preflight, exit 2, no foreman-backup-* directory, foreman.target still active |
foremanctl checks, after REINDEX |
passes | passes, exit 0 |
foremanctl backup --skip-pulp-content, healthy database with the real Satellite indexes |
not tested | preflight reports PASSED, all 8 dumps non-empty, Backup completed successfully, exit 0 |
Additional info
- Red Hat JIRA: https://redhat.atlassian.net/browse/SAT-54336
- Dominant language
- Python
- Stars
- 26
- Forks
- 59
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 16
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from theforeman/foremanctl
-
foreman-proxy container exhausts its pids limit under remote executionPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
theforeman/foremanctl#982 · 2 comments ·
Maintainers usually reply within 3 days
-
Stop checking the removed Katello event daemonPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
theforeman/foremanctl#913 ·
Maintainers usually reply within 3 days
-
Wait for Foreman tasks in backup integration testsPossibly taken @jakduch claimed this 66 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
theforeman/foremanctl#894 ·
Maintainers usually reply within 3 days
-
Serialize image service pullsPossibly taken @jakduch claimed this 66 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
theforeman/foremanctl#881 ·
Maintainers usually reply within 3 days
-
Use a larger fapolicyd subject cache in deployment testsPossibly taken @jakduch claimed this 66 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
theforeman/foremanctl#880 ·
Maintainers usually reply within 3 days
All issues in theforeman/foremanctl
Similar issues
-
DMB documentation good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ubuntu/ubuntu-project-docs#921 ·
Maintainers usually reply within 1 day
-
⏳ Pending feedback 🐛 Bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jumpserver/jumpserver#18282 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 76/100
ClickHouse/loom#2014 ·
Maintainers usually reply within 1 day
-
accepted
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
future-agi/future-agi#5274 ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 2 days