Commit dfcf7d2
committed
fix(operator): REINDEX DATABASE after pg_resetwal fallback
pg_resetwal bypasses WAL replay — it tells postgres to pretend the
data dir is consistent without replaying anything. Any index update
that was in flight at snapshot time can leave torn pages, which
postgres later surfaces as 'unexpected zero page at block N' when
a query happens to hit the corrupted page. The corruption is silent
until then, so it surfaces well after the restore completes — long
after debugging context is gone.
Reuse the existing post-restore reindex infrastructure (the
/pgdata/needs-reindex marker, the background hook in the postgres
container's startup script, the readiness probe that waits for the
marker to clear). Add a second marker file /pgdata/needs-reindex-all
that the pg_resetwal fallback paths touch every time they run. The
runtime hook now handles both flags:
- needs-reindex-all (set by pg_resetwal): REINDEX DATABASE on every
user database. Supersedes needs-reindex (its set of indexes is a
strict subset).
- needs-reindex (set by locale change): existing collation-dependent
REINDEX INDEX CONCURRENTLY loop.
The readiness probe gates pod-Ready on BOTH flags being absent, so
clients don't see corrupted indexes during the window between pod
startup and reindex completion.
Trade-off: REINDEX DATABASE isn't CONCURRENT so the reindex blocks
writes to each table in turn. For a read-only analytics replica the
operator's other pre-restore work has already taken the table to
single-user mode anyway, and the alternative is letting corrupt
indexes reach clients. REINDEX runs in the background after startup,
not in the foreground init script, so it doesn't extend the
pod-creation timeout.1 parent 2e7c7bc commit dfcf7d2
2 files changed
Lines changed: 175 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
922 | 922 | | |
923 | 923 | | |
924 | 924 | | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
925 | 933 | | |
926 | 934 | | |
927 | 935 | | |
| |||
946 | 954 | | |
947 | 955 | | |
948 | 956 | | |
| 957 | + | |
949 | 958 | | |
950 | 959 | | |
951 | 960 | | |
| |||
966 | 975 | | |
967 | 976 | | |
968 | 977 | | |
| 978 | + | |
969 | 979 | | |
970 | 980 | | |
971 | 981 | | |
| |||
1061 | 1071 | | |
1062 | 1072 | | |
1063 | 1073 | | |
1064 | | - | |
| 1074 | + | |
1065 | 1075 | | |
1066 | 1076 | | |
1067 | 1077 | | |
| |||
1235 | 1245 | | |
1236 | 1246 | | |
1237 | 1247 | | |
1238 | | - | |
| 1248 | + | |
1239 | 1249 | | |
1240 | 1250 | | |
1241 | 1251 | | |
1242 | 1252 | | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | | - | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
1262 | 1289 | | |
1263 | | - | |
1264 | | - | |
| 1290 | + | |
| 1291 | + | |
1265 | 1292 | | |
1266 | 1293 | | |
1267 | 1294 | | |
| |||
1308 | 1335 | | |
1309 | 1336 | | |
1310 | 1337 | | |
1311 | | - | |
| 1338 | + | |
1312 | 1339 | | |
1313 | 1340 | | |
1314 | 1341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
694 | 818 | | |
695 | 819 | | |
696 | 820 | | |
| |||
0 commit comments