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