Skip to content

Commit c5e4259

Browse files
committed
PGPRO-692: Do not compress .history and .backup files. Improve messages.
1 parent 3e06d9f commit c5e4259

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

src/archive.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
2929
char current_dir[MAXPGPATH];
3030
int64 system_id;
3131
pgBackupConfig *config;
32+
bool is_compress = false;
3233

3334
if (wal_file_name == NULL && wal_file_path == NULL)
3435
elog(ERROR, "required parameters are not specified: --wal-file-name %%f --wal-file-path %%p");
@@ -64,7 +65,14 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
6465
if (access(backup_wal_file_path, F_OK) != -1)
6566
elog(ERROR, "file '%s', already exists.", backup_wal_file_path);
6667

67-
push_wal_file(absolute_wal_file_path, backup_wal_file_path);
68+
#ifdef HAVE_LIBZ
69+
if (compress_alg == PGLZ_COMPRESS)
70+
elog(ERROR, "pglz compression is not supported");
71+
if (compress_alg == ZLIB_COMPRESS)
72+
is_compress = IsXLogFileName(wal_file_name);
73+
#endif
74+
75+
push_wal_file(absolute_wal_file_path, backup_wal_file_path, is_compress);
6876
elog(INFO, "pg_probackup archive-push completed successfully");
6977

7078
return 0;

src/data.c

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ copy_meta(const char *from_path, const char *to_path)
750750
* Copy WAL segment from pgdata to archive catalog with possible compression.
751751
*/
752752
void
753-
push_wal_file(const char *from_path, const char *to_path)
753+
push_wal_file(const char *from_path, const char *to_path, bool is_compress)
754754
{
755755
FILE *in = NULL;
756756
FILE *out;
@@ -765,20 +765,17 @@ push_wal_file(const char *from_path, const char *to_path)
765765
/* open file for read */
766766
in = fopen(from_path, "r");
767767
if (in == NULL)
768-
elog(ERROR, "Cannot open source WAL segment \"%s\": %s", from_path,
768+
elog(ERROR, "Cannot open source WAL file \"%s\": %s", from_path,
769769
strerror(errno));
770770

771771
/* open backup file for write */
772772
#ifdef HAVE_LIBZ
773-
if (compress_alg == PGLZ_COMPRESS)
774-
elog(ERROR, "pglz compression is not supported");
775-
776-
if (compress_alg == ZLIB_COMPRESS)
773+
if (is_compress)
777774
{
778775
snprintf(gz_to_path, sizeof(gz_to_path), "%s.gz", to_path);
779776
gz_out = gzopen(gz_to_path, "wb");
780777
if (gzsetparams(gz_out, compress_level, Z_DEFAULT_STRATEGY) != Z_OK)
781-
elog(ERROR, "Cannot set compression level %d to segment \"%s\": %s",
778+
elog(ERROR, "Cannot set compression level %d to file \"%s\": %s",
782779
compress_level, gz_to_path, get_gz_error(gz_out));
783780

784781
to_path_p = gz_to_path;
@@ -788,7 +785,7 @@ push_wal_file(const char *from_path, const char *to_path)
788785
{
789786
out = fopen(to_path, "w");
790787
if (out == NULL)
791-
elog(ERROR, "Cannot open destination WAL segment \"%s\": %s",
788+
elog(ERROR, "Cannot open destination WAL file \"%s\": %s",
792789
to_path, strerror(errno));
793790
}
794791

@@ -800,23 +797,23 @@ push_wal_file(const char *from_path, const char *to_path)
800797
read_len = fread(buf, 1, sizeof(buf), in);
801798

802799
if (ferror(in))
803-
elog(ERROR, "Cannot read source WAL segment \"%s\": %s",
800+
elog(ERROR, "Cannot read source WAL file \"%s\": %s",
804801
from_path, strerror(errno));
805802

806803
if (read_len > 0)
807804
{
808805
#ifdef HAVE_LIBZ
809-
if (compress_alg == ZLIB_COMPRESS)
806+
if (is_compress)
810807
{
811808
if (gzwrite(gz_out, buf, read_len) != read_len)
812-
elog(ERROR, "Cannot write to compressed WAL segment \"%s\": %s",
809+
elog(ERROR, "Cannot write to compressed WAL file \"%s\": %s",
813810
gz_to_path, get_gz_error(gz_out));
814811
}
815812
else
816813
#endif
817814
{
818815
if (fwrite(buf, 1, read_len, out) != read_len)
819-
elog(ERROR, "Cannot write to WAL segment \"%s\": %s",
816+
elog(ERROR, "Cannot write to WAL file \"%s\": %s",
820817
to_path, strerror(errno));
821818
}
822819
}
@@ -826,21 +823,25 @@ push_wal_file(const char *from_path, const char *to_path)
826823
}
827824

828825
#ifdef HAVE_LIBZ
829-
if (compress_alg == ZLIB_COMPRESS && gzclose(gz_out) != 0)
830-
elog(ERROR, "Cannot close compressed WAL segment \"%s\": %s",
831-
gz_to_path, get_gz_error(gz_out));
832-
else if (compress_alg != ZLIB_COMPRESS)
826+
if (is_compress)
827+
{
828+
if (gzclose(gz_out) != 0)
829+
elog(ERROR, "Cannot close compressed WAL file \"%s\": %s",
830+
gz_to_path, get_gz_error(gz_out));
831+
elog(INFO, "WAL file compressed to \"%s\"", gz_to_path);
832+
}
833+
else
833834
#endif
834835
{
835836
if (fflush(out) != 0 ||
836837
fsync(fileno(out)) != 0 ||
837838
fclose(out))
838-
elog(ERROR, "Cannot write WAL segment \"%s\": %s",
839+
elog(ERROR, "Cannot write WAL file \"%s\": %s",
839840
to_path, strerror(errno));
840841
}
841842

842843
if (fclose(in))
843-
elog(ERROR, "Cannot close source WAL segment \"%s\": %s",
844+
elog(ERROR, "Cannot close source WAL file \"%s\": %s",
844845
from_path, strerror(errno));
845846

846847
/* update file permission. */
@@ -883,7 +884,7 @@ get_wal_file(const char *from_path, const char *to_path)
883884
}
884885
/* Cannot open compressed file for some reason */
885886
else
886-
elog(ERROR, "Cannot open compressed WAL segment \"%s\": %s",
887+
elog(ERROR, "Cannot open compressed WAL file \"%s\": %s",
887888
gz_from_path, strerror(errno));
888889
}
889890
else
@@ -895,14 +896,14 @@ get_wal_file(const char *from_path, const char *to_path)
895896
#endif
896897
/* Didn't find compressed file */
897898
if (!is_decompress)
898-
elog(ERROR, "Cannot open source WAL segment \"%s\": %s",
899+
elog(ERROR, "Cannot open source WAL file \"%s\": %s",
899900
from_path, strerror(errno));
900901
}
901902

902903
/* open backup file for write */
903904
out = fopen(to_path, "w");
904905
if (out == NULL)
905-
elog(ERROR, "Cannot open destination WAL segment \"%s\": %s",
906+
elog(ERROR, "Cannot open destination WAL file \"%s\": %s",
906907
to_path, strerror(errno));
907908

908909
/* copy content */
@@ -915,22 +916,22 @@ get_wal_file(const char *from_path, const char *to_path)
915916
{
916917
read_len = gzread(gz_in, buf, sizeof(buf));
917918
if (read_len != sizeof(buf) && !gzeof(gz_in))
918-
elog(ERROR, "Cannot read compressed WAL segment \"%s\": %s",
919+
elog(ERROR, "Cannot read compressed WAL file \"%s\": %s",
919920
gz_from_path, get_gz_error(gz_in));
920921
}
921922
else
922923
#endif
923924
{
924925
read_len = fread(buf, 1, sizeof(buf), in);
925926
if (ferror(in))
926-
elog(ERROR, "Cannot read source WAL segment \"%s\": %s",
927+
elog(ERROR, "Cannot read source WAL file \"%s\": %s",
927928
from_path, strerror(errno));
928929
}
929930

930931
if (read_len > 0)
931932
{
932933
if (fwrite(buf, 1, read_len, out) != read_len)
933-
elog(ERROR, "Cannot write to WAL segment \"%s\": %s", to_path,
934+
elog(ERROR, "Cannot write to WAL file \"%s\": %s", to_path,
934935
strerror(errno));
935936
}
936937

@@ -952,18 +953,22 @@ get_wal_file(const char *from_path, const char *to_path)
952953
if (fflush(out) != 0 ||
953954
fsync(fileno(out)) != 0 ||
954955
fclose(out))
955-
elog(ERROR, "Cannot write WAL segment \"%s\": %s",
956+
elog(ERROR, "Cannot write WAL file \"%s\": %s",
956957
to_path, strerror(errno));
957958

958959
#ifdef HAVE_LIBZ
959-
if (is_decompress && gzclose(gz_in) != 0)
960-
elog(ERROR, "Cannot close compressed WAL segment \"%s\": %s",
961-
gz_from_path, get_gz_error(gz_in));
962-
else if (!is_decompress)
960+
if (is_decompress)
961+
{
962+
if (gzclose(gz_in) != 0)
963+
elog(ERROR, "Cannot close compressed WAL file \"%s\": %s",
964+
gz_from_path, get_gz_error(gz_in));
965+
elog(INFO, "WAL file decompressed from \"%s\"", gz_from_path);
966+
}
967+
else
963968
#endif
964969
{
965970
if (fclose(in))
966-
elog(ERROR, "Cannot close source WAL segment \"%s\": %s",
971+
elog(ERROR, "Cannot close source WAL file \"%s\": %s",
967972
from_path, strerror(errno));
968973
}
969974

src/pg_probackup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ extern void restore_data_file(const char *from_root, const char *to_root,
427427
pgFile *file, pgBackup *backup);
428428
extern bool copy_file(const char *from_root, const char *to_root,
429429
pgFile *file);
430-
extern void push_wal_file(const char *from_path, const char *to_path);
430+
extern void push_wal_file(const char *from_path, const char *to_path,
431+
bool is_compress);
431432
extern void get_wal_file(const char *from_path, const char *to_path);
432433

433434
extern bool calc_file_checksum(pgFile *file);

0 commit comments

Comments
 (0)