PostgreSQL Source Code  git master
streamutil.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * streamutil.c - utility functions for pg_basebackup, pg_receivewal and
4  * pg_recvlogical
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/streamutil.c
12  *-------------------------------------------------------------------------
13  */
14 
15 #include "postgres_fe.h"
16 
17 #include <sys/time.h>
18 #include <unistd.h>
19 
20 /* local includes */
21 #include "receivelog.h"
22 #include "streamutil.h"
23 
24 #include "access/xlog_internal.h"
25 #include "common/fe_memutils.h"
26 #include "common/file_perm.h"
27 #include "datatype/timestamp.h"
28 #include "fe_utils/connect.h"
29 #include "port/pg_bswap.h"
30 #include "pqexpbuffer.h"
31 
32 #define ERRCODE_DUPLICATE_OBJECT "42710"
33 
35 
37 
38 /* SHOW command for replication connection was introduced in version 10 */
39 #define MINIMUM_VERSION_FOR_SHOW_CMD 100000
40 
41 /*
42  * Group access is supported from version 11.
43  */
44 #define MINIMUM_VERSION_FOR_GROUP_ACCESS 110000
45 
46 const char *progname;
47 char *connection_string = NULL;
48 char *dbhost = NULL;
49 char *dbuser = NULL;
50 char *dbport = NULL;
51 char *dbname = NULL;
52 int dbgetpassword = 0; /* 0=auto, -1=never, 1=always */
53 static bool have_password = false;
54 static char password[100];
55 PGconn *conn = NULL;
56 
57 /*
58  * Connect to the server. Returns a valid PGconn pointer if connected,
59  * or NULL on non-permanent error. On permanent error, the function will
60  * call exit(1) directly.
61  */
62 PGconn *
64 {
65  PGconn *tmpconn;
66  int argcount = 7; /* dbname, replication, fallback_app_name,
67  * host, user, port, password */
68  int i;
69  const char **keywords;
70  const char **values;
71  const char *tmpparam;
72  bool need_password;
73  PQconninfoOption *conn_opts = NULL;
74  PQconninfoOption *conn_opt;
75  char *err_msg = NULL;
76 
77  /* pg_recvlogical uses dbname only; others use connection_string only. */
78  Assert(dbname == NULL || connection_string == NULL);
79 
80  /*
81  * Merge the connection info inputs given in form of connection string,
82  * options and default values (dbname=replication, replication=true, etc.)
83  * Explicitly discard any dbname value in the connection string;
84  * otherwise, PQconnectdbParams() would interpret that value as being
85  * itself a connection string.
86  */
87  i = 0;
89  {
90  conn_opts = PQconninfoParse(connection_string, &err_msg);
91  if (conn_opts == NULL)
92  {
93  fprintf(stderr, "%s: %s", progname, err_msg);
94  exit(1);
95  }
96 
97  for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
98  {
99  if (conn_opt->val != NULL && conn_opt->val[0] != '\0' &&
100  strcmp(conn_opt->keyword, "dbname") != 0)
101  argcount++;
102  }
103 
104  keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
105  values = pg_malloc0((argcount + 1) * sizeof(*values));
106 
107  for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
108  {
109  if (conn_opt->val != NULL && conn_opt->val[0] != '\0' &&
110  strcmp(conn_opt->keyword, "dbname") != 0)
111  {
112  keywords[i] = conn_opt->keyword;
113  values[i] = conn_opt->val;
114  i++;
115  }
116  }
117  }
118  else
119  {
120  keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
121  values = pg_malloc0((argcount + 1) * sizeof(*values));
122  }
123 
124  keywords[i] = "dbname";
125  values[i] = dbname == NULL ? "replication" : dbname;
126  i++;
127  keywords[i] = "replication";
128  values[i] = dbname == NULL ? "true" : "database";
129  i++;
130  keywords[i] = "fallback_application_name";
131  values[i] = progname;
132  i++;
133 
134  if (dbhost)
135  {
136  keywords[i] = "host";
137  values[i] = dbhost;
138  i++;
139  }
140  if (dbuser)
141  {
142  keywords[i] = "user";
143  values[i] = dbuser;
144  i++;
145  }
146  if (dbport)
147  {
148  keywords[i] = "port";
149  values[i] = dbport;
150  i++;
151  }
152 
153  /* If -W was given, force prompt for password, but only the first time */
154  need_password = (dbgetpassword == 1 && !have_password);
155 
156  do
157  {
158  /* Get a new password if appropriate */
159  if (need_password)
160  {
161  simple_prompt("Password: ", password, sizeof(password), false);
162  have_password = true;
163  need_password = false;
164  }
165 
166  /* Use (or reuse, on a subsequent connection) password if we have it */
167  if (have_password)
168  {
169  keywords[i] = "password";
170  values[i] = password;
171  }
172  else
173  {
174  keywords[i] = NULL;
175  values[i] = NULL;
176  }
177 
178  tmpconn = PQconnectdbParams(keywords, values, true);
179 
180  /*
181  * If there is too little memory even to allocate the PGconn object
182  * and PQconnectdbParams returns NULL, we call exit(1) directly.
183  */
184  if (!tmpconn)
185  {
186  fprintf(stderr, _("%s: could not connect to server\n"),
187  progname);
188  exit(1);
189  }
190 
191  /* If we need a password and -w wasn't given, loop back and get one */
192  if (PQstatus(tmpconn) == CONNECTION_BAD &&
193  PQconnectionNeedsPassword(tmpconn) &&
194  dbgetpassword != -1)
195  {
196  PQfinish(tmpconn);
197  need_password = true;
198  }
199  }
200  while (need_password);
201 
202  if (PQstatus(tmpconn) != CONNECTION_OK)
203  {
204  fprintf(stderr, _("%s: could not connect to server: %s"),
205  progname, PQerrorMessage(tmpconn));
206  PQfinish(tmpconn);
207  free(values);
208  free(keywords);
209  if (conn_opts)
210  PQconninfoFree(conn_opts);
211  return NULL;
212  }
213 
214  /* Connection ok! */
215  free(values);
216  free(keywords);
217  if (conn_opts)
218  PQconninfoFree(conn_opts);
219 
220  /*
221  * Set always-secure search path, so malicious users can't get control.
222  * The capacity to run normal SQL queries was added in PostgreSQL
223  * 10, so the search path cannot be changed (by us or attackers) on
224  * earlier versions.
225  */
226  if (dbname != NULL && PQserverVersion(conn) >= 100000)
227  {
228  PGresult *res;
229 
230  res = PQexec(tmpconn, ALWAYS_SECURE_SEARCH_PATH_SQL);
231  if (PQresultStatus(res) != PGRES_TUPLES_OK)
232  {
233  fprintf(stderr, _("%s: could not clear search_path: %s\n"),
234  progname, PQerrorMessage(tmpconn));
235  PQclear(res);
236  PQfinish(tmpconn);
237  exit(1);
238  }
239  PQclear(res);
240  }
241 
242  /*
243  * Ensure we have the same value of integer_datetimes (now always "on") as
244  * the server we are connecting to.
245  */
246  tmpparam = PQparameterStatus(tmpconn, "integer_datetimes");
247  if (!tmpparam)
248  {
249  fprintf(stderr,
250  _("%s: could not determine server setting for integer_datetimes\n"),
251  progname);
252  PQfinish(tmpconn);
253  exit(1);
254  }
255 
256  if (strcmp(tmpparam, "on") != 0)
257  {
258  fprintf(stderr,
259  _("%s: integer_datetimes compile flag does not match server\n"),
260  progname);
261  PQfinish(tmpconn);
262  exit(1);
263  }
264 
265  /*
266  * Retrieve the source data directory mode and use it to construct a umask
267  * for creating directories and files.
268  */
269  if (!RetrieveDataDirCreatePerm(tmpconn))
270  {
271  PQfinish(tmpconn);
272  exit(1);
273  }
274 
275  return tmpconn;
276 }
277 
278 /*
279  * From version 10, explicitly set wal segment size using SHOW wal_segment_size
280  * since ControlFile is not accessible here.
281  */
282 bool
284 {
285  PGresult *res;
286  char xlog_unit[3];
287  int xlog_val,
288  multiplier = 1;
289 
290  /* check connection existence */
291  Assert(conn != NULL);
292 
293  /* for previous versions set the default xlog seg size */
295  {
297  return true;
298  }
299 
300  res = PQexec(conn, "SHOW wal_segment_size");
301  if (PQresultStatus(res) != PGRES_TUPLES_OK)
302  {
303  fprintf(stderr, _("%s: could not send replication command \"%s\": %s\n"),
304  progname, "SHOW wal_segment_size", PQerrorMessage(conn));
305 
306  PQclear(res);
307  return false;
308  }
309  if (PQntuples(res) != 1 || PQnfields(res) < 1)
310  {
311  fprintf(stderr,
312  _("%s: could not fetch WAL segment size: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
313  progname, PQntuples(res), PQnfields(res), 1, 1);
314 
315  PQclear(res);
316  return false;
317  }
318 
319  /* fetch xlog value and unit from the result */
320  if (sscanf(PQgetvalue(res, 0, 0), "%d%s", &xlog_val, xlog_unit) != 2)
321  {
322  fprintf(stderr, _("%s: WAL segment size could not be parsed\n"),
323  progname);
324  return false;
325  }
326 
327  /* set the multiplier based on unit to convert xlog_val to bytes */
328  if (strcmp(xlog_unit, "MB") == 0)
329  multiplier = 1024 * 1024;
330  else if (strcmp(xlog_unit, "GB") == 0)
331  multiplier = 1024 * 1024 * 1024;
332 
333  /* convert and set WalSegSz */
334  WalSegSz = xlog_val * multiplier;
335 
337  {
338  fprintf(stderr,
339  _("%s: WAL segment size must be a power of two between 1MB and 1GB, but the remote server reported a value of %d bytes\n"),
340  progname, WalSegSz);
341  return false;
342  }
343 
344  PQclear(res);
345  return true;
346 }
347 
348 /*
349  * RetrieveDataDirCreatePerm
350  *
351  * This function is used to determine the privileges on the server's PG data
352  * directory and, based on that, set what the permissions will be for
353  * directories and files we create.
354  *
355  * PG11 added support for (optionally) group read/execute rights to be set on
356  * the data directory. Prior to PG11, only the owner was allowed to have rights
357  * on the data directory.
358  */
359 static bool
361 {
362  PGresult *res;
364 
365  /* check connection existence */
366  Assert(conn != NULL);
367 
368  /* for previous versions leave the default group access */
370  return true;
371 
372  res = PQexec(conn, "SHOW data_directory_mode");
373  if (PQresultStatus(res) != PGRES_TUPLES_OK)
374  {
375  fprintf(stderr, _("%s: could not send replication command \"%s\": %s\n"),
376  progname, "SHOW data_directory_mode", PQerrorMessage(conn));
377 
378  PQclear(res);
379  return false;
380  }
381  if (PQntuples(res) != 1 || PQnfields(res) < 1)
382  {
383  fprintf(stderr,
384  _("%s: could not fetch group access flag: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
385  progname, PQntuples(res), PQnfields(res), 1, 1);
386 
387  PQclear(res);
388  return false;
389  }
390 
391  if (sscanf(PQgetvalue(res, 0, 0), "%o", &data_directory_mode) != 1)
392  {
393  fprintf(stderr, _("%s: group access flag could not be parsed: %s\n"),
394  progname, PQgetvalue(res, 0, 0));
395 
396  PQclear(res);
397  return false;
398  }
399 
400  SetDataDirectoryCreatePerm(data_directory_mode);
401 
402  PQclear(res);
403  return true;
404 }
405 
406 /*
407  * Run IDENTIFY_SYSTEM through a given connection and give back to caller
408  * some result information if requested:
409  * - System identifier
410  * - Current timeline ID
411  * - Start LSN position
412  * - Database name (NULL in servers prior to 9.4)
413  */
414 bool
415 RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
416  XLogRecPtr *startpos, char **db_name)
417 {
418  PGresult *res;
419  uint32 hi,
420  lo;
421 
422  /* Check connection existence */
423  Assert(conn != NULL);
424 
425  res = PQexec(conn, "IDENTIFY_SYSTEM");
426  if (PQresultStatus(res) != PGRES_TUPLES_OK)
427  {
428  fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
429  progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn));
430 
431  PQclear(res);
432  return false;
433  }
434  if (PQntuples(res) != 1 || PQnfields(res) < 3)
435  {
436  fprintf(stderr,
437  _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
438  progname, PQntuples(res), PQnfields(res), 1, 3);
439 
440  PQclear(res);
441  return false;
442  }
443 
444  /* Get system identifier */
445  if (sysid != NULL)
446  *sysid = pg_strdup(PQgetvalue(res, 0, 0));
447 
448  /* Get timeline ID to start streaming from */
449  if (starttli != NULL)
450  *starttli = atoi(PQgetvalue(res, 0, 1));
451 
452  /* Get LSN start position if necessary */
453  if (startpos != NULL)
454  {
455  if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2)
456  {
457  fprintf(stderr,
458  _("%s: could not parse write-ahead log location \"%s\"\n"),
459  progname, PQgetvalue(res, 0, 2));
460 
461  PQclear(res);
462  return false;
463  }
464  *startpos = ((uint64) hi) << 32 | lo;
465  }
466 
467  /* Get database name, only available in 9.4 and newer versions */
468  if (db_name != NULL)
469  {
470  *db_name = NULL;
471  if (PQserverVersion(conn) >= 90400)
472  {
473  if (PQnfields(res) < 4)
474  {
475  fprintf(stderr,
476  _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
477  progname, PQntuples(res), PQnfields(res), 1, 4);
478 
479  PQclear(res);
480  return false;
481  }
482  if (!PQgetisnull(res, 0, 3))
483  *db_name = pg_strdup(PQgetvalue(res, 0, 3));
484  }
485  }
486 
487  PQclear(res);
488  return true;
489 }
490 
491 /*
492  * Create a replication slot for the given connection. This function
493  * returns true in case of success.
494  */
495 bool
496 CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
497  bool is_temporary, bool is_physical, bool reserve_wal,
498  bool slot_exists_ok)
499 {
500  PQExpBuffer query;
501  PGresult *res;
502 
503  query = createPQExpBuffer();
504 
505  Assert((is_physical && plugin == NULL) ||
506  (!is_physical && plugin != NULL));
507  Assert(slot_name != NULL);
508 
509  /* Build query */
510  appendPQExpBuffer(query, "CREATE_REPLICATION_SLOT \"%s\"", slot_name);
511  if (is_temporary)
512  appendPQExpBuffer(query, " TEMPORARY");
513  if (is_physical)
514  {
515  appendPQExpBuffer(query, " PHYSICAL");
516  if (reserve_wal)
517  appendPQExpBuffer(query, " RESERVE_WAL");
518  }
519  else
520  {
521  appendPQExpBuffer(query, " LOGICAL \"%s\"", plugin);
522  if (PQserverVersion(conn) >= 100000)
523  /* pg_recvlogical doesn't use an exported snapshot, so suppress */
524  appendPQExpBuffer(query, " NOEXPORT_SNAPSHOT");
525  }
526 
527  res = PQexec(conn, query->data);
528  if (PQresultStatus(res) != PGRES_TUPLES_OK)
529  {
530  const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
531 
532  if (slot_exists_ok &&
533  sqlstate &&
534  strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
535  {
536  destroyPQExpBuffer(query);
537  PQclear(res);
538  return true;
539  }
540  else
541  {
542  fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
543  progname, query->data, PQerrorMessage(conn));
544 
545  destroyPQExpBuffer(query);
546  PQclear(res);
547  return false;
548  }
549  }
550 
551  if (PQntuples(res) != 1 || PQnfields(res) != 4)
552  {
553  fprintf(stderr,
554  _("%s: could not create replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"),
555  progname, slot_name,
556  PQntuples(res), PQnfields(res), 1, 4);
557 
558  destroyPQExpBuffer(query);
559  PQclear(res);
560  return false;
561  }
562 
563  destroyPQExpBuffer(query);
564  PQclear(res);
565  return true;
566 }
567 
568 /*
569  * Drop a replication slot for the given connection. This function
570  * returns true in case of success.
571  */
572 bool
573 DropReplicationSlot(PGconn *conn, const char *slot_name)
574 {
575  PQExpBuffer query;
576  PGresult *res;
577 
578  Assert(slot_name != NULL);
579 
580  query = createPQExpBuffer();
581 
582  /* Build query */
583  appendPQExpBuffer(query, "DROP_REPLICATION_SLOT \"%s\"",
584  slot_name);
585  res = PQexec(conn, query->data);
586  if (PQresultStatus(res) != PGRES_COMMAND_OK)
587  {
588  fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
589  progname, query->data, PQerrorMessage(conn));
590 
591  destroyPQExpBuffer(query);
592  PQclear(res);
593  return false;
594  }
595 
596  if (PQntuples(res) != 0 || PQnfields(res) != 0)
597  {
598  fprintf(stderr,
599  _("%s: could not drop replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"),
600  progname, slot_name,
601  PQntuples(res), PQnfields(res), 0, 0);
602 
603  destroyPQExpBuffer(query);
604  PQclear(res);
605  return false;
606  }
607 
608  destroyPQExpBuffer(query);
609  PQclear(res);
610  return true;
611 }
612 
613 
614 /*
615  * Frontend version of GetCurrentTimestamp(), since we are not linked with
616  * backend code.
617  */
620 {
621  TimestampTz result;
622  struct timeval tp;
623 
624  gettimeofday(&tp, NULL);
625 
626  result = (TimestampTz) tp.tv_sec -
628  result = (result * USECS_PER_SEC) + tp.tv_usec;
629 
630  return result;
631 }
632 
633 /*
634  * Frontend version of TimestampDifference(), since we are not linked with
635  * backend code.
636  */
637 void
639  long *secs, int *microsecs)
640 {
641  TimestampTz diff = stop_time - start_time;
642 
643  if (diff <= 0)
644  {
645  *secs = 0;
646  *microsecs = 0;
647  }
648  else
649  {
650  *secs = (long) (diff / USECS_PER_SEC);
651  *microsecs = (int) (diff % USECS_PER_SEC);
652  }
653 }
654 
655 /*
656  * Frontend version of TimestampDifferenceExceeds(), since we are not
657  * linked with backend code.
658  */
659 bool
661  TimestampTz stop_time,
662  int msec)
663 {
664  TimestampTz diff = stop_time - start_time;
665 
666  return (diff >= msec * INT64CONST(1000));
667 }
668 
669 /*
670  * Converts an int64 to network byte order.
671  */
672 void
673 fe_sendint64(int64 i, char *buf)
674 {
675  uint64 n64 = pg_hton64(i);
676 
677  memcpy(buf, &n64, sizeof(n64));
678 }
679 
680 /*
681  * Converts an int64 from network byte order to native format.
682  */
683 int64
685 {
686  uint64 n64;
687 
688  memcpy(&n64, buf, sizeof(n64));
689 
690  return pg_ntoh64(n64);
691 }
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:97
static char password[100]
Definition: streamutil.c:54
static const char * plugin
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2732
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6116
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: gettimeofday.c:105
uint32 TimeLineID
Definition: xlogdefs.h:45
TimestampTz feGetCurrentTimestamp(void)
Definition: streamutil.c:619
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3118
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:6081
#define pg_hton64(x)
Definition: pg_bswap.h:122
#define USECS_PER_SEC
Definition: timestamp.h:94
int64 TimestampTz
Definition: timestamp.h:39
#define DEFAULT_XLOG_SEG_SIZE
bool RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli, XLogRecPtr *startpos, char **db_name)
Definition: streamutil.c:415
void PQfinish(PGconn *conn)
Definition: fe-connect.c:3638
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6106
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2724
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
bool feTimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition: streamutil.c:660
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:2647
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:536
static time_t start_time
Definition: pg_ctl.c:96
#define MINIMUM_VERSION_FOR_SHOW_CMD
Definition: streamutil.c:39
static bool slot_exists_ok
Definition: pg_receivewal.c:42
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:113
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
Definition: fe-connect.c:4735
char * connection_string
Definition: streamutil.c:47
#define SECS_PER_DAY
Definition: timestamp.h:86
bool RetrieveWalSegSize(PGconn *conn)
Definition: streamutil.c:283
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
PGconn * conn
Definition: streamutil.c:55
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
void feTimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: streamutil.c:638
static char * buf
Definition: pg_test_fsync.c:67
void simple_prompt(const char *prompt, char *destination, size_t destlen, bool echo)
Definition: sprompt.c:37
void PQconninfoFree(PQconninfoOption *connOptions)
Definition: fe-connect.c:5965
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
unsigned int uint32
Definition: c.h:325
int dbgetpassword
Definition: streamutil.c:52
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
char * dbport
Definition: streamutil.c:50
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define free(a)
Definition: header.h:65
static bool have_password
Definition: streamutil.c:53
const char * progname
Definition: streamutil.c:46
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:2709
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:699
char * dbhost
Definition: streamutil.c:48
char * dbname
Definition: streamutil.c:51
static XLogRecPtr startpos
#define ALWAYS_SECURE_SEARCH_PATH_SQL
Definition: connect.h:25
bool CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, bool is_temporary, bool is_physical, bool reserve_wal, bool slot_exists_ok)
Definition: streamutil.c:496
uint32 WalSegSz
Definition: streamutil.c:34
static Datum values[MAXATTR]
Definition: bootstrap.c:164
#define MINIMUM_VERSION_FOR_GROUP_ACCESS
Definition: streamutil.c:44
int PQconnectionNeedsPassword(const PGconn *conn)
Definition: fe-connect.c:6150
int64 fe_recvint64(char *buf)
Definition: streamutil.c:684
char * dbuser
Definition: streamutil.c:49
int data_directory_mode
Definition: globals.c:69
void SetDataDirectoryCreatePerm(int dataDirMode)
Definition: file_perm.c:35
int i
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1897
bool DropReplicationSlot(PGconn *conn, const char *slot_name)
Definition: streamutil.c:573
#define UNIX_EPOCH_JDATE
Definition: timestamp.h:162
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
static bool RetrieveDataDirCreatePerm(PGconn *conn)
Definition: streamutil.c:360
void fe_sendint64(int64 i, char *buf)
Definition: streamutil.c:673
PGconn * GetConnection(void)
Definition: streamutil.c:63
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3143
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6063
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
#define _(x)
Definition: elog.c:84
#define pg_ntoh64(x)
Definition: pg_bswap.h:126