cloudnative-pg / cloudnative-pg/plugin-barman-cloud
Backups are not restorable on low-activity databases due to missing final WAL segment
- Lenguaje dominante
- Go
- Estrellas
- 191
- Forks
- 72
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 21
Descripción
## Problem Summary
When CNPG takes a backup using the barman-cloud plugin, the backup cannot be restored because the final WAL segment referenced in the
backup metadata is never archived to S3. This occurs on a databases with zero write activity after a successful backup.
## Root Cause
1. A backup completes and records its end position (e.g., LSN 3/26000060 in WAL file 000000330000000300000026)
2. The backup metadata states this WAL file is required for recovery
3. However, this WAL file is still active (currently being written to) and hasn't been closed
4. PostgreSQL only archives WAL files when they are closed via:
• Filling up completely (16MB)
• pg_switch_wal() being called
• Clean server shutdown
5. On low-activity databases, the WAL file may remain active for hours/days
6. archive_timeout = 5min (CNPG default) does not trigger if there's zero activity after the backup
7. Result: The backup cannot be restored because the required WAL file is missing from S3
## Reproduction
1. Create a CNPG cluster with barman-cloud backup configured
2. Take a backup on a zero-activity database
3. Attempt to restore the backup immediately after completion
4. Restoration fails with: FATAL: WAL ends before end of online backup
## Evidence
Backup metadata shows:
```
endLSN: 3/26000060
endWal: "000000330000000300000026"
```
PostgreSQL archiver shows:
```
last_archived_wal: 000000330000000300000025 (previous segment)
```
Current database state:
```
pg_current_wal_lsn: 3/26000060 (same position, no activity)
pg_walfile_name: 000000330000000300000026 (still active)
```
S3 bucket:
```
000000330000000300000025.gz ✅ EXISTS
000000330000000300000026.gz ❌ MISSING
```
## Expected Behavior
After a backup completes successfully, it should be immediately restorable without waiting for database activity to trigger WAL archiving.
Guía de contribución
Línea de trabajo
Comienza siguiendo el flujo de finalización de la copia de seguridad de barman-cloud y cómo se archivan los segmentos WAL de PostgreSQL después de que la copia de seguridad alcanza su LSN final. Reproduce el caso de actividad cero del issue y, a continuación, verifica que el segmento WAL final referenciado esté presente en S3 y que la copia de seguridad se restaure inmediatamente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- go, postgresql
- Área
- backend, databases
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 35/100