Skip to content

Commit ae280cb

Browse files
FEATURE (backups): Add zstd 5 compression level for PostgreSQL >= 16
1 parent af49939 commit ae280cb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

backend/internal/features/backups/backups/usecases/postgresql/create_backup_uc.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ func (uc *CreatePostgresqlBackupUsecase) Execute(
6060
}
6161

6262
args := []string{
63-
"-Fc", // custom format with built-in compression
64-
"-Z", "6", // balanced compression level (0-9, 6 is balanced)
63+
"-Fc", // custom format with built-in compression
6564
"--no-password", // Use environment variable for password, prevent prompts
6665
"-h", pg.Host,
6766
"-p", strconv.Itoa(pg.Port),
@@ -70,6 +69,16 @@ func (uc *CreatePostgresqlBackupUsecase) Execute(
7069
"--verbose", // Add verbose output to help with debugging
7170
}
7271

72+
// Use zstd compression level 5 for PostgreSQL 15+ (better compression and speed)
73+
// Fall back to gzip compression level 5 for older versions
74+
if pg.Version == tools.PostgresqlVersion13 || pg.Version == tools.PostgresqlVersion14 || pg.Version == tools.PostgresqlVersion15 {
75+
args = append(args, "-Z", "5")
76+
uc.logger.Info("Using gzip compression level 5 (zstd not available)", "version", pg.Version)
77+
} else {
78+
args = append(args, "--compress=zstd:5")
79+
uc.logger.Info("Using zstd compression level 5", "version", pg.Version)
80+
}
81+
7382
return uc.streamToStorage(
7483
backupID,
7584
backupConfig,

0 commit comments

Comments
 (0)