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-2018, 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 "common/file_perm.h"
23 #include "libpq-fe.h"
24 #include "access/xlog_internal.h"
25 #include "getopt_long.h"
26 
27 #include "receivelog.h"
28 #include "streamutil.h"
29 
30 
31 /* Time to sleep between reconnection attempts */
32 #define RECONNECT_SLEEP_TIME 5
33 
34 /* Global options */
35 static char *basedir = NULL;
36 static int verbose = 0;
37 static int compresslevel = 0;
38 static int noloop = 0;
39 static int standby_message_timeout = 10 * 1000; /* 10 sec = default */
40 static volatile bool time_to_stop = false;
41 static bool do_create_slot = false;
42 static bool slot_exists_ok = false;
43 static bool do_drop_slot = false;
44 static bool do_sync = true;
45 static bool synchronous = false;
46 static char *replication_slot = NULL;
48 
49 
50 static void usage(void);
51 static DIR *get_destination_dir(char *dest_folder);
52 static void close_destination_dir(DIR *dest_dir, char *dest_folder);
54 static void StreamLog(void);
55 static bool stop_streaming(XLogRecPtr segendpos, uint32 timeline,
56  bool segment_finished);
57 
58 #define disconnect_and_exit(code) \
59  { \
60  if (conn != NULL) PQfinish(conn); \
61  exit(code); \
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 <pgsql-bugs@postgresql.org>.\n"));
106 }
107 
108 static bool
109 stop_streaming(XLogRecPtr xlogpos, uint32 timeline, bool segment_finished)
110 {
111  static uint32 prevtimeline = 0;
112  static XLogRecPtr prevpos = InvalidXLogRecPtr;
113 
114  /* we assume that we get called once at the end of each segment */
115  if (verbose && segment_finished)
116  fprintf(stderr, _("%s: finished segment at %X/%X (timeline %u)\n"),
117  progname, (uint32) (xlogpos >> 32), (uint32) xlogpos,
118  timeline);
119 
120  if (!XLogRecPtrIsInvalid(endpos) && endpos < xlogpos)
121  {
122  if (verbose)
123  fprintf(stderr, _("%s: stopped log streaming at %X/%X (timeline %u)\n"),
124  progname, (uint32) (xlogpos >> 32), (uint32) xlogpos,
125  timeline);
126  time_to_stop = true;
127  return true;
128  }
129 
130  /*
131  * Note that we report the previous, not current, position here. After a
132  * timeline switch, xlogpos points to the beginning of the segment because
133  * that's where we always begin streaming. Reporting the end of previous
134  * timeline isn't totally accurate, because the next timeline can begin
135  * slightly before the end of the WAL that we received on the previous
136  * timeline, but it's close enough for reporting purposes.
137  */
138  if (verbose && prevtimeline != 0 && prevtimeline != timeline)
139  fprintf(stderr, _("%s: switched to timeline %u at %X/%X\n"),
140  progname, timeline,
141  (uint32) (prevpos >> 32), (uint32) prevpos);
142 
143  prevtimeline = timeline;
144  prevpos = xlogpos;
145 
146  if (time_to_stop)
147  {
148  if (verbose)
149  fprintf(stderr, _("%s: received interrupt signal, exiting\n"),
150  progname);
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  fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
170  progname, basedir, strerror(errno));
172  }
173 
174  return dir;
175 }
176 
177 
178 /*
179  * Close existing directory.
180  */
181 static void
182 close_destination_dir(DIR *dest_dir, char *dest_folder)
183 {
184  Assert(dest_dir != NULL && dest_folder != NULL);
185  if (closedir(dest_dir))
186  {
187  fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"),
188  progname, dest_folder, strerror(errno));
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  fprintf(stderr, _("%s: could not stat file \"%s\": %s\n"),
269  progname, fullpath, strerror(errno));
271  }
272 
273  if (statbuf.st_size != WalSegSz)
274  {
275  fprintf(stderr,
276  _("%s: segment file \"%s\" has incorrect size %d, skipping\n"),
277  progname, dirent->d_name, (int) statbuf.st_size);
278  continue;
279  }
280  }
281  else if (!ispartial && iscompress)
282  {
283  int fd;
284  char buf[4];
285  int bytes_out;
286  char fullpath[MAXPGPATH * 2];
287 
288  snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
289 
290  fd = open(fullpath, O_RDONLY | PG_BINARY);
291  if (fd < 0)
292  {
293  fprintf(stderr, _("%s: could not open compressed file \"%s\": %s\n"),
294  progname, fullpath, strerror(errno));
296  }
297  if (lseek(fd, (off_t) (-4), SEEK_END) < 0)
298  {
299  fprintf(stderr, _("%s: could not seek in compressed file \"%s\": %s\n"),
300  progname, fullpath, strerror(errno));
302  }
303  if (read(fd, (char *) buf, sizeof(buf)) != sizeof(buf))
304  {
305  fprintf(stderr, _("%s: could not read compressed file \"%s\": %s\n"),
306  progname, fullpath, strerror(errno));
308  }
309 
310  close(fd);
311  bytes_out = (buf[3] << 24) | (buf[2] << 16) |
312  (buf[1] << 8) | buf[0];
313 
314  if (bytes_out != WalSegSz)
315  {
316  fprintf(stderr,
317  _("%s: compressed segment file \"%s\" has incorrect uncompressed size %d, skipping\n"),
318  progname, dirent->d_name, bytes_out);
319  continue;
320  }
321  }
322 
323  /* Looks like a valid segment. Remember that we saw it. */
324  if ((segno > high_segno) ||
325  (segno == high_segno && tli > high_tli) ||
326  (segno == high_segno && tli == high_tli && high_ispartial && !ispartial))
327  {
328  high_segno = segno;
329  high_tli = tli;
330  high_ispartial = ispartial;
331  }
332  }
333 
334  if (errno)
335  {
336  fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"),
337  progname, basedir, strerror(errno));
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, high_ptr, WalSegSz);
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  */
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))
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  fprintf(stderr,
423  _("%s: starting log streaming at %X/%X (timeline %u)\n"),
424  progname, (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
425  stream.timeline);
426 
427  stream.stream_stop = stop_streaming;
428  stream.stop_socket = PGINVALID_SOCKET;
430  stream.synchronous = synchronous;
431  stream.do_sync = do_sync;
432  stream.mark_done = false;
434  stream.do_sync);
435  stream.partial_suffix = ".partial";
437 
438  ReceiveXlogStream(conn, &stream);
439 
440  if (!stream.walmethod->finish())
441  {
442  fprintf(stderr,
443  _("%s: could not finish writing WAL files: %s\n"),
444  progname, strerror(errno));
445  return;
446  }
447 
448  PQfinish(conn);
449 
451  pg_free(stream.walmethod);
452 
453  conn = NULL;
454 }
455 
456 /*
457  * When sigint is called, just tell the system to exit at the next possible
458  * moment.
459  */
460 #ifndef WIN32
461 
462 static void
463 sigint_handler(int signum)
464 {
465  time_to_stop = true;
466 }
467 #endif
468 
469 int
470 main(int argc, char **argv)
471 {
472  static struct option long_options[] = {
473  {"help", no_argument, NULL, '?'},
474  {"version", no_argument, NULL, 'V'},
475  {"directory", required_argument, NULL, 'D'},
476  {"dbname", required_argument, NULL, 'd'},
477  {"endpos", required_argument, NULL, 'E'},
478  {"host", required_argument, NULL, 'h'},
479  {"port", required_argument, NULL, 'p'},
480  {"username", required_argument, NULL, 'U'},
481  {"no-loop", no_argument, NULL, 'n'},
482  {"no-password", no_argument, NULL, 'w'},
483  {"password", no_argument, NULL, 'W'},
484  {"status-interval", required_argument, NULL, 's'},
485  {"slot", required_argument, NULL, 'S'},
486  {"verbose", no_argument, NULL, 'v'},
487  {"compress", required_argument, NULL, 'Z'},
488 /* action */
489  {"create-slot", no_argument, NULL, 1},
490  {"drop-slot", no_argument, NULL, 2},
491  {"if-not-exists", no_argument, NULL, 3},
492  {"synchronous", no_argument, NULL, 4},
493  {"no-sync", no_argument, NULL, 5},
494  {NULL, 0, NULL, 0}
495  };
496 
497  int c;
498  int option_index;
499  char *db_name;
500  uint32 hi,
501  lo;
502 
503  progname = get_progname(argv[0]);
504  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
505 
506  if (argc > 1)
507  {
508  if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
509  {
510  usage();
511  exit(0);
512  }
513  else if (strcmp(argv[1], "-V") == 0 ||
514  strcmp(argv[1], "--version") == 0)
515  {
516  puts("pg_receivewal (PostgreSQL) " PG_VERSION);
517  exit(0);
518  }
519  }
520 
521  while ((c = getopt_long(argc, argv, "D:d:E:h:p:U:s:S:nwWvZ:",
522  long_options, &option_index)) != -1)
523  {
524  switch (c)
525  {
526  case 'D':
528  break;
529  case 'd':
531  break;
532  case 'h':
534  break;
535  case 'p':
536  if (atoi(optarg) <= 0)
537  {
538  fprintf(stderr, _("%s: invalid port number \"%s\"\n"),
539  progname, optarg);
540  exit(1);
541  }
543  break;
544  case 'U':
546  break;
547  case 'w':
548  dbgetpassword = -1;
549  break;
550  case 'W':
551  dbgetpassword = 1;
552  break;
553  case 's':
554  standby_message_timeout = atoi(optarg) * 1000;
555  if (standby_message_timeout < 0)
556  {
557  fprintf(stderr, _("%s: invalid status interval \"%s\"\n"),
558  progname, optarg);
559  exit(1);
560  }
561  break;
562  case 'S':
564  break;
565  case 'E':
566  if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
567  {
568  fprintf(stderr,
569  _("%s: could not parse end position \"%s\"\n"),
570  progname, optarg);
571  exit(1);
572  }
573  endpos = ((uint64) hi) << 32 | lo;
574  break;
575  case 'n':
576  noloop = 1;
577  break;
578  case 'v':
579  verbose++;
580  break;
581  case 'Z':
582  compresslevel = atoi(optarg);
583  if (compresslevel < 0 || compresslevel > 9)
584  {
585  fprintf(stderr, _("%s: invalid compression level \"%s\"\n"),
586  progname, optarg);
587  exit(1);
588  }
589  break;
590 /* action */
591  case 1:
592  do_create_slot = true;
593  break;
594  case 2:
595  do_drop_slot = true;
596  break;
597  case 3:
598  slot_exists_ok = true;
599  break;
600  case 4:
601  synchronous = true;
602  break;
603  case 5:
604  do_sync = false;
605  break;
606  default:
607 
608  /*
609  * getopt_long already emitted a complaint
610  */
611  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
612  progname);
613  exit(1);
614  }
615  }
616 
617  /*
618  * Any non-option arguments?
619  */
620  if (optind < argc)
621  {
622  fprintf(stderr,
623  _("%s: too many command-line arguments (first is \"%s\")\n"),
624  progname, argv[optind]);
625  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
626  progname);
627  exit(1);
628  }
629 
631  {
632  fprintf(stderr, _("%s: cannot use --create-slot together with --drop-slot\n"), progname);
633  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
634  progname);
635  exit(1);
636  }
637 
638  if (replication_slot == NULL && (do_drop_slot || do_create_slot))
639  {
640  /* translator: second %s is an option name */
641  fprintf(stderr, _("%s: %s needs a slot to be specified using --slot\n"), progname,
642  do_drop_slot ? "--drop-slot" : "--create-slot");
643  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
644  progname);
645  exit(1);
646  }
647 
648  if (synchronous && !do_sync)
649  {
650  fprintf(stderr, _("%s: cannot use --synchronous together with --no-sync\n"), progname);
651  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
652  progname);
653  exit(1);
654  }
655 
656  /*
657  * Required arguments
658  */
659  if (basedir == NULL && !do_drop_slot && !do_create_slot)
660  {
661  fprintf(stderr, _("%s: no target directory specified\n"), progname);
662  fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
663  progname);
664  exit(1);
665  }
666 
667 #ifndef HAVE_LIBZ
668  if (compresslevel != 0)
669  {
670  fprintf(stderr,
671  _("%s: this build does not support compression\n"),
672  progname);
673  exit(1);
674  }
675 #endif
676 
677  /*
678  * Check existence of destination folder.
679  */
680  if (!do_drop_slot && !do_create_slot)
681  {
683 
685  }
686 
687 #ifndef WIN32
688  pqsignal(SIGINT, sigint_handler);
689 #endif
690 
691  /*
692  * Obtain a connection before doing anything.
693  */
694  conn = GetConnection();
695  if (!conn)
696  /* error message already written in GetConnection() */
697  exit(1);
698 
699  /*
700  * Run IDENTIFY_SYSTEM to make sure we've successfully have established a
701  * replication connection and haven't connected using a database specific
702  * connection.
703  */
704  if (!RunIdentifySystem(conn, NULL, NULL, NULL, &db_name))
706 
707  /*
708  * Set umask so that directories/files are created with the same
709  * permissions as directories/files in the source data directory.
710  *
711  * pg_mode_mask is set to owner-only by default and then updated in
712  * GetConnection() where we get the mode from the server-side with
713  * RetrieveDataDirCreatePerm() and then call SetDataDirectoryCreatePerm().
714  */
715  umask(pg_mode_mask);
716 
717  /* determine remote server's xlog segment size */
718  if (!RetrieveWalSegSize(conn))
720 
721  /*
722  * Check that there is a database associated with connection, none should
723  * be defined in this context.
724  */
725  if (db_name)
726  {
727  fprintf(stderr,
728  _("%s: replication connection using slot \"%s\" is unexpectedly database specific\n"),
731  }
732 
733  /*
734  * Drop a replication slot.
735  */
736  if (do_drop_slot)
737  {
738  if (verbose)
739  fprintf(stderr,
740  _("%s: dropping replication slot \"%s\"\n"),
742 
746  }
747 
748  /* Create a replication slot */
749  if (do_create_slot)
750  {
751  if (verbose)
752  fprintf(stderr,
753  _("%s: creating replication slot \"%s\"\n"),
755 
756  if (!CreateReplicationSlot(conn, replication_slot, NULL, false, true, false,
760  }
761 
762  /*
763  * Don't close the connection here so that subsequent StreamLog() can
764  * reuse it.
765  */
766 
767  while (true)
768  {
769  StreamLog();
770  if (time_to_stop)
771  {
772  /*
773  * We've been Ctrl-C'ed or end of streaming position has been
774  * willingly reached, so exit without an error code.
775  */
776  exit(0);
777  }
778  else if (noloop)
779  {
780  fprintf(stderr, _("%s: disconnected\n"), progname);
781  exit(1);
782  }
783  else
784  {
785  fprintf(stderr,
786  /* translator: check source for value for %d */
787  _("%s: disconnected; waiting %d seconds to try again\n"),
789  pg_usleep(RECONNECT_SLEEP_TIME * 1000000);
790  }
791  }
792 }
static char * replication_slot
Definition: pg_receivewal.c:46
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
int main(int argc, char **argv)
static int standby_message_timeout
Definition: pg_receivewal.c:39
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:1030
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
#define IsPartialCompressXLogFileName(fname)
Definition: pg_receivewal.c:69
bool RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, XLogRecPtr *startpos, char **db_name)
Definition: streamutil.c:417
int closedir(DIR *)
Definition: dirent.c:111
void PQfinish(PGconn *conn)
Definition: fe-connect.c:3638
#define MemSet(start, val, len)
Definition: c.h:908
static bool synchronous
Definition: pg_receivewal.c:45
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:1080
TimeLineID timeline
Definition: receivelog.h:33
WalWriteMethod * CreateWalDirectoryMethod(const char *basedir, int compression, bool sync)
Definition: walmethods.c:347
static void sigint_handler(int signum)
static bool slot_exists_ok
Definition: pg_receivewal.c:42
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:47
bool RetrieveWalSegSize(PGconn *conn)
Definition: streamutil.c:283
PGconn * conn
Definition: streamutil.c:55
#define MAXPGPATH
#define disconnect_and_exit(code)
Definition: pg_receivewal.c:58
static XLogRecPtr endpos
Definition: pg_receivewal.c:47
DIR * opendir(const char *)
Definition: dirent.c:33
static int noloop
Definition: pg_receivewal.c:38
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:35
#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:325
static volatile bool time_to_stop
Definition: pg_receivewal.c:40
stream_stop_callback stream_stop
Definition: receivelog.h:42
static bool do_drop_slot
Definition: pg_receivewal.c:43
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:52
#define no_argument
Definition: getopt_long.h:24
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1054
#define PGINVALID_SOCKET
Definition: port.h:33
#define XLogSegmentOffset(xlogptr, wal_segsz_bytes)
char * dbport
Definition: streamutil.c:50
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:699
char * dbhost
Definition: streamutil.c:48
bool ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
Definition: receivelog.c:447
#define RECONNECT_SLEEP_TIME
Definition: pg_receivewal.c:32
struct dirent * readdir(DIR *)
Definition: dirent.c:77
static int compresslevel
Definition: pg_receivewal.c:37
static bool do_create_slot
Definition: pg_receivewal.c:41
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:836
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:49
char * optarg
Definition: getopt.c:53
static bool do_sync
Definition: pg_receivewal.c:44
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:36
#define _(x)
Definition: elog.c:84
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
void FreeWalDirectoryMethod(void)
Definition: walmethods.c:371
bool CheckServerVersionForStreaming(PGconn *conn)
Definition: receivelog.c:367