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