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