PostgreSQL Source Code  git master
pg_receivewal.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_receivewal.c - receive streaming WAL data and write it
4  * to a local file.
5  *
6  * Author: Magnus Hagander <magnus@hagander.net>
7  *
8  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
9  *
10  * IDENTIFICATION
11  * src/bin/pg_basebackup/pg_receivewal.c
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres_fe.h"
16 
17 #include <dirent.h>
18 #include <signal.h>
19 #include <sys/stat.h>
20 #include <unistd.h>
21 
22 #include "access/xlog_internal.h"
23 #include "common/file_perm.h"
24 #include "common/logging.h"
25 #include "getopt_long.h"
26 #include "libpq-fe.h"
27 #include "receivelog.h"
28 #include "streamutil.h"
29 
30 /* Time to sleep between reconnection attempts */
31 #define RECONNECT_SLEEP_TIME 5
32 
33 /* Global options */
34 static char *basedir = NULL;
35 static int verbose = 0;
36 static int compresslevel = 0;
37 static int noloop = 0;
38 static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
39 static volatile bool time_to_stop = false;
40 static bool do_create_slot = false;
41 static bool slot_exists_ok = false;
42 static bool do_drop_slot = false;
43 static bool do_sync = true;
44 static bool synchronous = false;
45 static char *replication_slot = NULL;
47 
48 
49 static void usage(void);
50 static DIR *get_destination_dir(char *dest_folder);
51 static void close_destination_dir(DIR *dest_dir, char *dest_folder);
53 static void StreamLog(void);
54 static bool stop_streaming(XLogRecPtr segendpos, uint32 timeline,
55  bool segment_finished);
56 
57 static void
59 {
60  if (conn != NULL)
61  PQfinish(conn);
62 }
63 
64 /* Routines to evaluate segment file format */
65 #define IsCompressXLogFileName(fname) \
66  (strlen(fname) == XLOG_FNAME_LEN + strlen(".gz") && \
67  strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
68  strcmp((fname) + XLOG_FNAME_LEN, ".gz") == 0)
69 #define IsPartialCompressXLogFileName(fname) \
70  (strlen(fname) == XLOG_FNAME_LEN + strlen(".gz.partial") && \
71  strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN && \
72  strcmp((fname) + XLOG_FNAME_LEN, ".gz.partial") == 0)
73 
74 static void
75 usage(void)
76 {
77  printf(_("%s receives PostgreSQL streaming write-ahead logs.\n\n"),
78  progname);
79  printf(_("Usage:\n"));
80  printf(_(" %s [OPTION]...\n"), progname);
81  printf(_("\nOptions:\n"));
82  printf(_(" -D, --directory=DIR receive write-ahead log files into this directory\n"));
83  printf(_(" -E, --endpos=LSN exit after receiving the specified LSN\n"));
84  printf(_(" --if-not-exists do not error if slot already exists when creating a slot\n"));
85  printf(_(" -n, --no-loop do not loop on connection lost\n"));
86  printf(_(" --no-sync do not wait for changes to be written safely to disk\n"));
87  printf(_(" -s, --status-interval=SECS\n"
88  " time between status packets sent to server (default: %d)\n"), (standby_message_timeout / 1000));
89  printf(_(" -S, --slot=SLOTNAME replication slot to use\n"));
90  printf(_(" --synchronous flush write-ahead log immediately after writing\n"));
91  printf(_(" -v, --verbose output verbose messages\n"));
92  printf(_(" -V, --version output version information, then exit\n"));
93  printf(_(" -Z, --compress=0-9 compress logs with given compression level\n"));
94  printf(_(" -?, --help show this help, then exit\n"));
95  printf(_("\nConnection options:\n"));
96  printf(_(" -d, --dbname=CONNSTR connection string\n"));
97  printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
98  printf(_(" -p, --port=PORT database server port number\n"));
99  printf(_(" -U, --username=NAME connect as specified database user\n"));
100  printf(_(" -w, --no-password never prompt for password\n"));
101  printf(_(" -W, --password force password prompt (should happen automatically)\n"));
102  printf(_("\nOptional actions:\n"));
103  printf(_(" --create-slot create a new replication slot (for the slot's name see --slot)\n"));
104  printf(_(" --drop-slot drop the replication slot (for the slot's name see --slot)\n"));
105  printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
106  printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
107 }
108 
109 static bool
110 stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
111 {
112  static uint32 prevtimeline = 0;
113  static XLogRecPtr prevpos = InvalidXLogRecPtr;
114 
115  /* we assume that we get called once at the end of each segment */
116  if (verbose && segment_finished)
117  pg_log_info("finished segment at %X/%X (timeline %u)",
118  (uint32) (xlogpos >> 32), (uint32) xlogpos,
119  timeline);
120 
121  if (!XLogRecPtrIsInvalid(endpos) && endpos < xlogpos)
122  {
123  if (verbose)
124  pg_log_info("stopped log streaming at %X/%X (timeline %u)",
125  (uint32) (xlogpos >> 32), (uint32) xlogpos,
126  timeline);
127  time_to_stop = true;
128  return true;
129  }
130 
131  /*
132  * Note that we report the previous, not current, position here. After a
133  * timeline switch, xlogpos points to the beginning of the segment because
134  * that's where we always begin streaming. Reporting the end of previous
135  * timeline isn't totally accurate, because the next timeline can begin
136  * slightly before the end of the WAL that we received on the previous
137  * timeline, but it's close enough for reporting purposes.
138  */
139  if (verbose && prevtimeline != 0 && prevtimeline != timeline)
140  pg_log_info("switched to timeline %u at %X/%X",
141  timeline,
142  (uint32) (prevpos >> 32), (uint32) prevpos);
143 
144  prevtimeline = timeline;
145  prevpos = xlogpos;
146 
147  if (time_to_stop)
148  {
149  if (verbose)
150  pg_log_info("received interrupt signal, exiting");
151  return true;
152  }
153  return false;
154 }
155 
156 
157 /*
158  * Get destination directory.
159  */
160 static DIR *
161 get_destination_dir(char *dest_folder)
162 {
163  DIR *dir;
164 
165  Assert(dest_folder != NULL);
166  dir = opendir(dest_folder);
167  if (dir == NULL)
168  {
169  pg_log_error("could not open directory \"%s\": %m", basedir);
170  exit(1);
171  }
172 
173  return dir;
174 }
175 
176 
177 /*
178  * Close existing directory.
179  */
180 static void
181 close_destination_dir(DIR *dest_dir, char *dest_folder)
182 {
183  Assert(dest_dir != NULL && dest_folder != NULL);
184  if (closedir(dest_dir))
185  {
186  pg_log_error("could not close directory \"%s\": %m", dest_folder);
187  exit(1);
188  }
189 }
190 
191 
192 /*
193  * Determine starting location for streaming, based on any existing xlog
194  * segments in the directory. We start at the end of the last one that is
195  * complete (size matches wal segment size), on the timeline with highest ID.
196  *
197  * If there are no WAL files in the directory, returns InvalidXLogRecPtr.
198  */
199 static XLogRecPtr
201 {
202  DIR *dir;
203  struct dirent *dirent;
204  XLogSegNo high_segno = 0;
205  uint32 high_tli = 0;
206  bool high_ispartial = false;
207 
209 
210  while (errno = 0, (dirent = readdir(dir)) != NULL)
211  {
212  uint32 tli;
213  XLogSegNo segno;
214  bool ispartial;
215  bool iscompress;
216 
217  /*
218  * Check if the filename looks like an xlog file, or a .partial file.
219  */
220  if (IsXLogFileName(dirent->d_name))
221  {
222  ispartial = false;
223  iscompress = false;
224  }
225  else if (IsPartialXLogFileName(dirent->d_name))
226  {
227  ispartial = true;
228  iscompress = false;
229  }
230  else if (IsCompressXLogFileName(dirent->d_name))
231  {
232  ispartial = false;
233  iscompress = true;
234  }
235  else if (IsPartialCompressXLogFileName(dirent->d_name))
236  {
237  ispartial = true;
238  iscompress = true;
239  }
240  else
241  continue;
242 
243  /*
244  * Looks like an xlog file. Parse its position.
245  */
246  XLogFromFileName(dirent->d_name, &tli, &segno, WalSegSz);
247 
248  /*
249  * Check that the segment has the right size, if it's supposed to be
250  * completed. For non-compressed segments just check the on-disk size
251  * and see if it matches a completed segment. For compressed segments,
252  * look at the last 4 bytes of the compressed file, which is where the
253  * uncompressed size is located for gz files with a size lower than
254  * 4GB, and then compare it to the size of a completed segment. The 4
255  * last bytes correspond to the ISIZE member according to
256  * http://www.zlib.org/rfc-gzip.html.
257  */
258  if (!ispartial && !iscompress)
259  {
260  struct stat statbuf;
261  char fullpath[MAXPGPATH * 2];
262 
263  snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
264  if (stat(fullpath, &statbuf) != 0)
265  {
266  pg_log_error("could not stat file \"%s\": %m", fullpath);
267  exit(1);
268  }
269 
270  if (statbuf.st_size != WalSegSz)
271  {
272  pg_log_warning("segment file \"%s\" has incorrect size %d, skipping",
273  dirent->d_name, (int) statbuf.st_size);
274  continue;
275  }
276  }
277  else if (!ispartial && iscompress)
278  {
279  int fd;
280  char buf[4];
281  int bytes_out;
282  char fullpath[MAXPGPATH * 2];
283  int r;
284 
285  snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
286 
287  fd = open(fullpath, O_RDONLY | PG_BINARY, 0);
288  if (fd < 0)
289  {
290  pg_log_error("could not open compressed file \"%s\": %m",
291  fullpath);
292  exit(1);
293  }
294  if (lseek(fd, (off_t) (-4), SEEK_END) < 0)
295  {
296  pg_log_error("could not seek in compressed file \"%s\": %m",
297  fullpath);
298  exit(1);
299  }
300  r = read(fd, (char *) buf, sizeof(buf));
301  if (r != sizeof(buf))
302  {
303  if (r < 0)
304  pg_log_error("could not read compressed file \"%s\": %m",
305  fullpath);
306  else
307  pg_log_error("could not read compressed file \"%s\": read %d of %zu",
308  fullpath, r, sizeof(buf));
309  exit(1);
310  }
311 
312  close(fd);
313  bytes_out = (buf[3] << 24) | (buf[2] << 16) |
314  (buf[1] << 8) | buf[0];
315 
316  if (bytes_out != WalSegSz)
317  {
318  pg_log_warning("compressed segment file \"%s\" has incorrect uncompressed size %d, skipping",
319  dirent->d_name, bytes_out);
320  continue;
321  }
322  }
323 
324  /* Looks like a valid segment. Remember that we saw it. */
325  if ((segno > high_segno) ||
326  (segno == high_segno && tli > high_tli) ||
327  (segno == high_segno && tli == high_tli && high_ispartial && !ispartial))
328  {
329  high_segno = segno;
330  high_tli = tli;
331  high_ispartial = ispartial;
332  }
333  }
334 
335  if (errno)
336  {
337  pg_log_error("could not read directory \"%s\": %m", basedir);
338  exit(1);
339  }
340 
342 
343  if (high_segno > 0)
344  {
345  XLogRecPtr high_ptr;
346 
347  /*
348  * Move the starting pointer to the start of the next segment, if the
349  * highest one we saw was completed. Otherwise start streaming from
350  * the beginning of the .partial segment.
351  */
352  if (!high_ispartial)
353  high_segno++;
354 
355  XLogSegNoOffsetToRecPtr(high_segno, 0, WalSegSz, high_ptr);
356 
357  *tli = high_tli;
358  return high_ptr;
359  }
360  else
361  return InvalidXLogRecPtr;
362 }
363 
364 /*
365  * Start the log streaming
366  */
367 static void
369 {
370  XLogRecPtr serverpos;
371  TimeLineID servertli;
372  StreamCtl stream;
373 
374  MemSet(&stream, 0, sizeof(stream));
375 
376  /*
377  * Connect in replication mode to the server
378  */
379  if (conn == NULL)
380  conn = GetConnection();
381  if (!conn)
382  /* Error message already written in GetConnection() */
383  return;
384 
386  {
387  /*
388  * Error message already written in CheckServerVersionForStreaming().
389  * There's no hope of recovering from a version mismatch, so don't
390  * retry.
391  */
392  exit(1);
393  }
394 
395  /*
396  * Identify server, obtaining start LSN position and current timeline ID
397  * at the same time, necessary if not valid data can be found in the
398  * existing output directory.
399  */
400  if (!RunIdentifySystem(conn, NULL, &servertli, &serverpos, NULL))
401  exit(1);
402 
403  /*
404  * Figure out where to start streaming.
405  */
406  stream.startpos = FindStreamingStart(&stream.timeline);
407  if (stream.startpos == InvalidXLogRecPtr)
408  {
409  stream.startpos = serverpos;
410  stream.timeline = servertli;
411  }
412 
413  /*
414  * Always start streaming at the beginning of a segment
415  */
416  stream.startpos -= XLogSegmentOffset(stream.startpos, WalSegSz);
417 
418  /*
419  * Start the replication
420  */
421  if (verbose)
422  pg_log_info("starting log streaming at %X/%X (timeline %u)",
423  (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
424  stream.timeline);
425 
426  stream.stream_stop = stop_streaming;
427  stream.stop_socket = PGINVALID_SOCKET;
429  stream.synchronous = synchronous;
430  stream.do_sync = do_sync;
431  stream.mark_done = false;
433  stream.do_sync);
434  stream.partial_suffix = ".partial";
436 
437  ReceiveXlogStream(conn, &stream);
438 
439  if (!stream.walmethod->finish())
440  {
441  pg_log_info("could not finish writing WAL files: %m");
442  return;
443  }
444 
445  PQfinish(conn);
446  conn = NULL;
447 
449  pg_free(stream.walmethod);
450 
451  conn = NULL;
452 }
453 
454 /*
455  * When sigint is called, just tell the system to exit at the next possible
456  * moment.
457  */
458 #ifndef WIN32
459 
460 static void
461 sigint_handler(int signum)
462 {
463  time_to_stop = true;
464 }
465 #endif
466 
467 int
468 main(int argc, char **argv)
469 {
470  static struct option long_options[] = {
471  {"help", no_argument, NULL, '?'},
472  {"version", no_argument, NULL, 'V'},
473  {"directory", required_argument, NULL, 'D'},
474  {"dbname", required_argument, NULL, 'd'},
475  {"endpos", required_argument, NULL, 'E'},
476  {"host", required_argument, NULL, 'h'},
477  {"port", required_argument, NULL, 'p'},
478  {"username", required_argument, NULL, 'U'},
479  {"no-loop", no_argument, NULL, 'n'},
480  {"no-password", no_argument, NULL, 'w'},
481  {"password", no_argument, NULL, 'W'},
482  {"status-interval", required_argument, NULL, 's'},
483  {"slot", required_argument, NULL, 'S'},
484  {"verbose", no_argument, NULL, 'v'},
485  {"compress", required_argument, NULL, 'Z'},
486 /* action */
487  {"create-slot", no_argument, NULL, 1},
488  {"drop-slot", no_argument, NULL, 2},
489  {"if-not-exists", no_argument, NULL, 3},
490  {"synchronous", no_argument, NULL, 4},
491  {"no-sync", no_argument, NULL, 5},
492  {NULL, 0, NULL, 0}
493  };
494 
495  int c;
496  int option_index;
497  char *db_name;
498  uint32 hi,
499  lo;
500 
501  pg_logging_init(argv[0]);
502  progname = get_progname(argv[0]);
503  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
504 
505  if (argc > 1)
506  {
507  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
508  {
509  usage();
510  exit(0);
511  }
512  else if (strcmp(argv[1], "-V") == 0 ||
513  strcmp(argv[1], "--version") == 0)
514  {
515  puts("pg_receivewal (PostgreSQL) " PG_VERSION);
516  exit(0);
517  }
518  }
519 
520  while ((c = getopt_long(argc, argv, "D:d:E:h:p:U:s:S:nwWvZ:",
521  long_options, &option_index)) != -1)
522  {
523  switch (c)
524  {
525  case 'D':
527  break;
528  case 'd':
530  break;
531  case 'h':
533  break;
534  case 'p':
535  if (atoi(optarg) <= 0)
536  {
537  pg_log_error("invalid port number \"%s\"", optarg);
538  exit(1);
539  }
541  break;
542  case 'U':
544  break;
545  case 'w':
546  dbgetpassword = -1;
547  break;
548  case 'W':
549  dbgetpassword = 1;
550  break;
551  case 's':
552  standby_message_timeout = atoi(optarg) * 1000;
553  if (standby_message_timeout < 0)
554  {
555  pg_log_error("invalid status interval \"%s\"", optarg);
556  exit(1);
557  }
558  break;
559  case 'S':
561  break;
562  case 'E':
563  if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
564  {
565  pg_log_error("could not parse end position \"%s\"", optarg);
566  exit(1);
567  }
568  endpos = ((uint64) hi) << 32 | lo;
569  break;
570  case 'n':
571  noloop = 1;
572  break;
573  case 'v':
574  verbose++;
575  break;
576  case 'Z':
577  compresslevel = atoi(optarg);
578  if (compresslevel < 0 || compresslevel > 9)
579  {
580  pg_log_error("invalid compression level \"%s\"", optarg);
581  exit(1);
582  }
583  break;
584 /* action */
585  case 1:
586  do_create_slot = true;
587  break;
588  case 2:
589  do_drop_slot = true;
590  break;
591  case 3:
592  slot_exists_ok = true;
593  break;
594  case 4:
595  synchronous = true;
596  break;
597  case 5:
598  do_sync = false;
599  break;
600  default:
601 
602  /*
603  * getopt_long already emitted a complaint
604  */
605  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
606  progname);
607  exit(1);
608  }
609  }
610 
611  /*
612  * Any non-option arguments?
613  */
614  if (optind < argc)
615  {
616  pg_log_error("too many command-line arguments (first is \"%s\")",
617  argv[optind]);
618  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
619  progname);
620  exit(1);
621  }
622 
624  {
625  pg_log_error("cannot use --create-slot together with --drop-slot");
626  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
627  progname);
628  exit(1);
629  }
630 
631  if (replication_slot == NULL && (do_drop_slot || do_create_slot))
632  {
633  /* translator: second %s is an option name */
634  pg_log_error("%s needs a slot to be specified using --slot",
635  do_drop_slot ? "--drop-slot" : "--create-slot");
636  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
637  progname);
638  exit(1);
639  }
640 
641  if (synchronous && !do_sync)
642  {
643  pg_log_error("cannot use --synchronous together with --no-sync");
644  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
645  progname);
646  exit(1);
647  }
648 
649  /*
650  * Required arguments
651  */
652  if (basedir == NULL && !do_drop_slot && !do_create_slot)
653  {
654  pg_log_error("no target directory specified");
655  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
656  progname);
657  exit(1);
658  }
659 
660 #ifndef HAVE_LIBZ
661  if (compresslevel != 0)
662  {
663  pg_log_error("this build does not support compression");
664  exit(1);
665  }
666 #endif
667 
668  /*
669  * Check existence of destination folder.
670  */
671  if (!do_drop_slot && !do_create_slot)
672  {
674 
676  }
677 
678 #ifndef WIN32
679  pqsignal(SIGINT, sigint_handler);
680 #endif
681 
682  /*
683  * Obtain a connection before doing anything.
684  */
685  conn = GetConnection();
686  if (!conn)
687  /* error message already written in GetConnection() */
688  exit(1);
689  atexit(disconnect_atexit);
690 
691  /*
692  * Run IDENTIFY_SYSTEM to make sure we've successfully have established a
693  * replication connection and haven't connected using a database specific
694  * connection.
695  */
696  if (!RunIdentifySystem(conn, NULL, NULL, NULL, &db_name))
697  exit(1);
698 
699  /*
700  * Set umask so that directories/files are created with the same
701  * permissions as directories/files in the source data directory.
702  *
703  * pg_mode_mask is set to owner-only by default and then updated in
704  * GetConnection() where we get the mode from the server-side with
705  * RetrieveDataDirCreatePerm() and then call SetDataDirectoryCreatePerm().
706  */
707  umask(pg_mode_mask);
708 
709  /* determine remote server's xlog segment size */
710  if (!RetrieveWalSegSize(conn))
711  exit(1);
712 
713  /*
714  * Check that there is a database associated with connection, none should
715  * be defined in this context.
716  */
717  if (db_name)
718  {
719  pg_log_error("replication connection using slot \"%s\" is unexpectedly database specific",
721  exit(1);
722  }
723 
724  /*
725  * Drop a replication slot.
726  */
727  if (do_drop_slot)
728  {
729  if (verbose)
730  pg_log_info("dropping replication slot \"%s\"", replication_slot);
731 
733  exit(1);
734  exit(0);
735  }
736 
737  /* Create a replication slot */
738  if (do_create_slot)
739  {
740  if (verbose)
741  pg_log_info("creating replication slot \"%s\"", replication_slot);
742 
743  if (!CreateReplicationSlot(conn, replication_slot, NULL, false, true, false,
745  exit(1);
746  exit(0);
747  }
748 
749  /*
750  * Don't close the connection here so that subsequent StreamLog() can
751  * reuse it.
752  */
753 
754  while (true)
755  {
756  StreamLog();
757  if (time_to_stop)
758  {
759  /*
760  * We've been Ctrl-C'ed or end of streaming position has been
761  * willingly reached, so exit without an error code.
762  */
763  exit(0);
764  }
765  else if (noloop)
766  {
767  pg_log_error("disconnected");
768  exit(1);
769  }
770  else
771  {
772  /* translator: check source for value for %d */
773  pg_log_info("disconnected; waiting %d seconds to try again",
775  pg_usleep(RECONNECT_SLEEP_TIME * 1000000);
776  }
777  }
778 }
static char * replication_slot
Definition: pg_receivewal.c:45
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
int main(int argc, char **argv)
static int standby_message_timeout
Definition: pg_receivewal.c:38
uint32 TimeLineID
Definition: xlogdefs.h:52
bool do_sync
Definition: receivelog.h:38
const char * get_progname(const char *argv0)
Definition: path.c:453
static void DropReplicationSlot(DropReplicationSlotCmd *cmd)
Definition: walsender.c:1128
#define pg_log_error(...)
Definition: logging.h:79
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
static void usage(void)
Definition: pg_receivewal.c:75
void pg_logging_init(const char *argv0)
Definition: logging.c:76
#define IsPartialCompressXLogFileName(fname)
Definition: pg_receivewal.c:69
bool RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, XLogRecPtr *startpos, char **db_name)
Definition: streamutil.c:409
int closedir(DIR *)
Definition: dirent.c:113
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4185
#define MemSet(start, val, len)
Definition: c.h:971
static bool synchronous
Definition: pg_receivewal.c:44
#define printf(...)
Definition: port.h:199
XLogRecPtr startpos
Definition: receivelog.h:31
char * partial_suffix
Definition: receivelog.h:47
static bool stop_streaming(XLogRecPtr segendpos, uint32 timeline, bool segment_finished)
const char * progname
Definition: pg_standby.c:36
#define fprintf
Definition: port.h:197
static void close_destination_dir(DIR *dest_dir, char *dest_folder)
Definition: dirent.h:9
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define PG_BINARY
Definition: c.h:1234
TimeLineID timeline
Definition: receivelog.h:32
WalWriteMethod * CreateWalDirectoryMethod(const char *basedir, int compression, bool sync)
Definition: walmethods.c:349
static void sigint_handler(int signum)
static bool slot_exists_ok
Definition: pg_receivewal.c:41
static void StreamLog(void)
void pg_usleep(long microsec)
Definition: signal.c:53
#define required_argument
Definition: getopt_long.h:25
int optind
Definition: getopt.c:50
Definition: dirent.c:25
#define IsXLogFileName(fname)
char * connection_string
Definition: streamutil.c:46
bool RetrieveWalSegSize(PGconn *conn)
Definition: streamutil.c:277
PGconn * conn
Definition: streamutil.c:54
#define MAXPGPATH
static XLogRecPtr endpos
Definition: pg_receivewal.c:46
DIR * opendir(const char *)
Definition: dirent.c:33
static int noloop
Definition: pg_receivewal.c:37
char * replication_slot
Definition: receivelog.h:48
bool mark_done
Definition: receivelog.h:37
#define XLogFromFileName(fname, tli, logSegNo, wal_segsz_bytes)
char * c
static char * buf
Definition: pg_test_fsync.c:67
uint64 XLogSegNo
Definition: xlogdefs.h:41
static XLogRecPtr FindStreamingStart(uint32 *tli)
static char * basedir
Definition: pg_receivewal.c:34
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
unsigned int uint32
Definition: c.h:367
static volatile bool time_to_stop
Definition: pg_receivewal.c:39
stream_stop_callback stream_stop
Definition: receivelog.h:41
static bool do_drop_slot
Definition: pg_receivewal.c:42
WalWriteMethod * walmethod
Definition: receivelog.h:46
#define XLogRecPtrIsInvalid(r)
Definition: xlogdefs.h:29
#define stat(a, b)
Definition: win32_port.h:255
int dbgetpassword
Definition: streamutil.c:51
#define no_argument
Definition: getopt_long.h:24
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1178
#define PGINVALID_SOCKET
Definition: port.h:33
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
char * dbport
Definition: streamutil.c:49
static void disconnect_atexit(void)
Definition: pg_receivewal.c:58
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
static DIR * get_destination_dir(char *dest_folder)
PGconn * GetConnection(UserMapping *user, bool will_prep_stmt)
Definition: connection.c:107
#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest)
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:738
char * dbhost
Definition: streamutil.c:47
bool ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
Definition: receivelog.c:436
#define RECONNECT_SLEEP_TIME
Definition: pg_receivewal.c:31
struct dirent * readdir(DIR *)
Definition: dirent.c:77
static int compresslevel
Definition: pg_receivewal.c:36
static bool do_create_slot
Definition: pg_receivewal.c:40
bool synchronous
Definition: receivelog.h:36
void pg_free(void *ptr)
Definition: fe_memutils.c:105
bool(* finish)(void)
Definition: walmethods.h:75
pgsocket stop_socket
Definition: receivelog.h:43
static void CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
Definition: walsender.c:926
int WalSegSz
Definition: pg_standby.c:38
#define IsPartialXLogFileName(fname)
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:434
char * dbuser
Definition: streamutil.c:48
char * optarg
Definition: getopt.c:52
static bool do_sync
Definition: pg_receivewal.c:43
int standby_message_timeout
Definition: receivelog.h:35
char d_name[MAX_PATH]
Definition: dirent.h:14
#define close(a)
Definition: win32.h:12
#define pg_log_warning(...)
Definition: pgfnames.c:24
static int verbose
Definition: pg_receivewal.c:35
#define snprintf
Definition: port.h:193
#define _(x)
Definition: elog.c:88
int pg_mode_mask
Definition: file_perm.c:25
#define read(a, b, c)
Definition: win32.h:13
#define IsCompressXLogFileName(fname)
Definition: pg_receivewal.c:65
#define pg_log_info(...)
Definition: logging.h:87
void FreeWalDirectoryMethod(void)
Definition: walmethods.c:373
bool CheckServerVersionForStreaming(PGconn *conn)
Definition: receivelog.c:358