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