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 10, so
223  * the search path cannot be changed (by us or attackers) on earlier
224  * versions.
225  */
226  if (dbname != NULL && PQserverVersion(tmpconn) >= 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"),
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"),
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  ngettext("%s: WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d byte\n",
340  "%s: WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d bytes\n",
341  WalSegSz),
342  progname, WalSegSz);
343  return false;
344  }
345 
346  PQclear(res);
347  return true;
348 }
349 
350 /*
351  * RetrieveDataDirCreatePerm
352  *
353  * This function is used to determine the privileges on the server's PG data
354  * directory and, based on that, set what the permissions will be for
355  * directories and files we create.
356  *
357  * PG11 added support for (optionally) group read/execute rights to be set on
358  * the data directory. Prior to PG11, only the owner was allowed to have rights
359  * on the data directory.
360  */
361 static bool
363 {
364  PGresult *res;
366 
367  /* check connection existence */
368  Assert(conn != NULL);
369 
370  /* for previous versions leave the default group access */
372  return true;
373 
374  res = PQexec(conn, "SHOW data_directory_mode");
375  if (PQresultStatus(res) != PGRES_TUPLES_OK)
376  {
377  fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
378  progname, "SHOW data_directory_mode", PQerrorMessage(conn));
379 
380  PQclear(res);
381  return false;
382  }
383  if (PQntuples(res) != 1 || PQnfields(res) < 1)
384  {
385  fprintf(stderr,
386  _("%s: could not fetch group access flag: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
387  progname, PQntuples(res), PQnfields(res), 1, 1);
388 
389  PQclear(res);
390  return false;
391  }
392 
393  if (sscanf(PQgetvalue(res, 0, 0), "%o", &data_directory_mode) != 1)
394  {
395  fprintf(stderr, _("%s: group access flag could not be parsed: %s\n"),
396  progname, PQgetvalue(res, 0, 0));
397 
398  PQclear(res);
399  return false;
400  }
401 
402  SetDataDirectoryCreatePerm(data_directory_mode);
403 
404  PQclear(res);
405  return true;
406 }
407 
408 /*
409  * Run IDENTIFY_SYSTEM through a given connection and give back to caller
410  * some result information if requested:
411  * - System identifier
412  * - Current timeline ID
413  * - Start LSN position
414  * - Database name (NULL in servers prior to 9.4)
415  */
416 bool
417 RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
418  XLogRecPtr *startpos, char **db_name)
419 {
420  PGresult *res;
421  uint32 hi,
422  lo;
423 
424  /* Check connection existence */
425  Assert(conn != NULL);
426 
427  res = PQexec(conn, "IDENTIFY_SYSTEM");
428  if (PQresultStatus(res) != PGRES_TUPLES_OK)
429  {
430  fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
431  progname, "IDENTIFY_SYSTEM", PQerrorMessage(conn));
432 
433  PQclear(res);
434  return false;
435  }
436  if (PQntuples(res) != 1 || PQnfields(res) < 3)
437  {
438  fprintf(stderr,
439  _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
440  progname, PQntuples(res), PQnfields(res), 1, 3);
441 
442  PQclear(res);
443  return false;
444  }
445 
446  /* Get system identifier */
447  if (sysid != NULL)
448  *sysid = pg_strdup(PQgetvalue(res, 0, 0));
449 
450  /* Get timeline ID to start streaming from */
451  if (starttli != NULL)
452  *starttli = atoi(PQgetvalue(res, 0, 1));
453 
454  /* Get LSN start position if necessary */
455  if (startpos != NULL)
456  {
457  if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2)
458  {
459  fprintf(stderr,
460  _("%s: could not parse write-ahead log location \"%s\"\n"),
461  progname, PQgetvalue(res, 0, 2));
462 
463  PQclear(res);
464  return false;
465  }
466  *startpos = ((uint64) hi) << 32 | lo;
467  }
468 
469  /* Get database name, only available in 9.4 and newer versions */
470  if (db_name != NULL)
471  {
472  *db_name = NULL;
473  if (PQserverVersion(conn) >= 90400)
474  {
475  if (PQnfields(res) < 4)
476  {
477  fprintf(stderr,
478  _("%s: could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields\n"),
479  progname, PQntuples(res), PQnfields(res), 1, 4);
480 
481  PQclear(res);
482  return false;
483  }
484  if (!PQgetisnull(res, 0, 3))
485  *db_name = pg_strdup(PQgetvalue(res, 0, 3));
486  }
487  }
488 
489  PQclear(res);
490  return true;
491 }
492 
493 /*
494  * Create a replication slot for the given connection. This function
495  * returns true in case of success.
496  */
497 bool
498 CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
499  bool is_temporary, bool is_physical, bool reserve_wal,
500  bool slot_exists_ok)
501 {
502  PQExpBuffer query;
503  PGresult *res;
504 
505  query = createPQExpBuffer();
506 
507  Assert((is_physical && plugin == NULL) ||
508  (!is_physical && plugin != NULL));
509  Assert(slot_name != NULL);
510 
511  /* Build query */
512  appendPQExpBuffer(query, "CREATE_REPLICATION_SLOT \"%s\"", slot_name);
513  if (is_temporary)
514  appendPQExpBuffer(query, " TEMPORARY");
515  if (is_physical)
516  {
517  appendPQExpBuffer(query, " PHYSICAL");
518  if (reserve_wal)
519  appendPQExpBuffer(query, " RESERVE_WAL");
520  }
521  else
522  {
523  appendPQExpBuffer(query, " LOGICAL \"%s\"", plugin);
524  if (PQserverVersion(conn) >= 100000)
525  /* pg_recvlogical doesn't use an exported snapshot, so suppress */
526  appendPQExpBuffer(query, " NOEXPORT_SNAPSHOT");
527  }
528 
529  res = PQexec(conn, query->data);
530  if (PQresultStatus(res) != PGRES_TUPLES_OK)
531  {
532  const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
533 
534  if (slot_exists_ok &&
535  sqlstate &&
536  strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
537  {
538  destroyPQExpBuffer(query);
539  PQclear(res);
540  return true;
541  }
542  else
543  {
544  fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
545  progname, query->data, PQerrorMessage(conn));
546 
547  destroyPQExpBuffer(query);
548  PQclear(res);
549  return false;
550  }
551  }
552 
553  if (PQntuples(res) != 1 || PQnfields(res) != 4)
554  {
555  fprintf(stderr,
556  _("%s: could not create replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"),
557  progname, slot_name,
558  PQntuples(res), PQnfields(res), 1, 4);
559 
560  destroyPQExpBuffer(query);
561  PQclear(res);
562  return false;
563  }
564 
565  destroyPQExpBuffer(query);
566  PQclear(res);
567  return true;
568 }
569 
570 /*
571  * Drop a replication slot for the given connection. This function
572  * returns true in case of success.
573  */
574 bool
575 DropReplicationSlot(PGconn *conn, const char *slot_name)
576 {
577  PQExpBuffer query;
578  PGresult *res;
579 
580  Assert(slot_name != NULL);
581 
582  query = createPQExpBuffer();
583 
584  /* Build query */
585  appendPQExpBuffer(query, "DROP_REPLICATION_SLOT \"%s\"",
586  slot_name);
587  res = PQexec(conn, query->data);
588  if (PQresultStatus(res) != PGRES_COMMAND_OK)
589  {
590  fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
591  progname, query->data, PQerrorMessage(conn));
592 
593  destroyPQExpBuffer(query);
594  PQclear(res);
595  return false;
596  }
597 
598  if (PQntuples(res) != 0 || PQnfields(res) != 0)
599  {
600  fprintf(stderr,
601  _("%s: could not drop replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields\n"),
602  progname, slot_name,
603  PQntuples(res), PQnfields(res), 0, 0);
604 
605  destroyPQExpBuffer(query);
606  PQclear(res);
607  return false;
608  }
609 
610  destroyPQExpBuffer(query);
611  PQclear(res);
612  return true;
613 }
614 
615 
616 /*
617  * Frontend version of GetCurrentTimestamp(), since we are not linked with
618  * backend code.
619  */
622 {
623  TimestampTz result;
624  struct timeval tp;
625 
626  gettimeofday(&tp, NULL);
627 
628  result = (TimestampTz) tp.tv_sec -
630  result = (result * USECS_PER_SEC) + tp.tv_usec;
631 
632  return result;
633 }
634 
635 /*
636  * Frontend version of TimestampDifference(), since we are not linked with
637  * backend code.
638  */
639 void
641  long *secs, int *microsecs)
642 {
643  TimestampTz diff = stop_time - start_time;
644 
645  if (diff <= 0)
646  {
647  *secs = 0;
648  *microsecs = 0;
649  }
650  else
651  {
652  *secs = (long) (diff / USECS_PER_SEC);
653  *microsecs = (int) (diff % USECS_PER_SEC);
654  }
655 }
656 
657 /*
658  * Frontend version of TimestampDifferenceExceeds(), since we are not
659  * linked with backend code.
660  */
661 bool
663  TimestampTz stop_time,
664  int msec)
665 {
666  TimestampTz diff = stop_time - start_time;
667 
668  return (diff >= msec * INT64CONST(1000));
669 }
670 
671 /*
672  * Converts an int64 to network byte order.
673  */
674 void
675 fe_sendint64(int64 i, char *buf)
676 {
677  uint64 n64 = pg_hton64(i);
678 
679  memcpy(buf, &n64, sizeof(n64));
680 }
681 
682 /*
683  * Converts an int64 from network byte order to native format.
684  */
685 int64
687 {
688  uint64 n64;
689 
690  memcpy(&n64, buf, sizeof(n64));
691 
692  return pg_ntoh64(n64);
693 }
#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:621
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:417
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:662
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:640
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
#define ngettext(s, p, n)
Definition: c.h:1022
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:498
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:686
char * dbuser
Definition: streamutil.c:49
int data_directory_mode
Definition: globals.c:67
void SetDataDirectoryCreatePerm(int dataDirMode)
Definition: file_perm.c:34
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:575
#define UNIX_EPOCH_JDATE
Definition: timestamp.h:162
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
static bool RetrieveDataDirCreatePerm(PGconn *conn)
Definition: streamutil.c:362
void fe_sendint64(int64 i, char *buf)
Definition: streamutil.c:675
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