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-2019, 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/fe_memutils.h"
22 #include "common/file_perm.h"
23 #include "common/logging.h"
24 #include "datatype/timestamp.h"
25 #include "fe_utils/connect.h"
26 #include "port/pg_bswap.h"
27 #include "pqexpbuffer.h"
28 #include "receivelog.h"
29 #include "streamutil.h"
30 
31 #define ERRCODE_DUPLICATE_OBJECT "42710"
32 
34 
36 
37 /* SHOW command for replication connection was introduced in version 10 */
38 #define MINIMUM_VERSION_FOR_SHOW_CMD 100000
39 
40 /*
41  * Group access is supported from version 11.
42  */
43 #define MINIMUM_VERSION_FOR_GROUP_ACCESS 110000
44 
45 const char *progname;
46 char *connection_string = NULL;
47 char *dbhost = NULL;
48 char *dbuser = NULL;
49 char *dbport = NULL;
50 char *dbname = NULL;
51 int dbgetpassword = 0; /* 0=auto, -1=never, 1=always */
52 static bool have_password = false;
53 static char password[100];
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 && !have_password);
154 
155  do
156  {
157  /* Get a new password if appropriate */
158  if (need_password)
159  {
160  simple_prompt("Password: ", password, sizeof(password), false);
161  have_password = true;
162  need_password = false;
163  }
164 
165  /* Use (or reuse, on a subsequent connection) password if we have it */
166  if (have_password)
167  {
168  keywords[i] = "password";
169  values[i] = password;
170  }
171  else
172  {
173  keywords[i] = NULL;
174  values[i] = NULL;
175  }
176 
177  tmpconn = PQconnectdbParams(keywords, values, true);
178 
179  /*
180  * If there is too little memory even to allocate the PGconn object
181  * and PQconnectdbParams returns NULL, we call exit(1) directly.
182  */
183  if (!tmpconn)
184  {
185  pg_log_error("could not connect to server");
186  exit(1);
187  }
188 
189  /* If we need a password and -w wasn't given, loop back and get one */
190  if (PQstatus(tmpconn) == CONNECTION_BAD &&
191  PQconnectionNeedsPassword(tmpconn) &&
192  dbgetpassword != -1)
193  {
194  PQfinish(tmpconn);
195  need_password = true;
196  }
197  }
198  while (need_password);
199 
200  if (PQstatus(tmpconn) != CONNECTION_OK)
201  {
202  pg_log_error("could not connect to server: %s",
203  PQerrorMessage(tmpconn));
204  PQfinish(tmpconn);
205  free(values);
206  free(keywords);
207  if (conn_opts)
208  PQconninfoFree(conn_opts);
209  return NULL;
210  }
211 
212  /* Connection ok! */
213  free(values);
214  free(keywords);
215  if (conn_opts)
216  PQconninfoFree(conn_opts);
217 
218  /*
219  * Set always-secure search path, so malicious users can't get control.
220  * The capacity to run normal SQL queries was added in PostgreSQL 10, so
221  * the search path cannot be changed (by us or attackers) on earlier
222  * versions.
223  */
224  if (dbname != NULL && PQserverVersion(tmpconn) >= 100000)
225  {
226  PGresult *res;
227 
228  res = PQexec(tmpconn, ALWAYS_SECURE_SEARCH_PATH_SQL);
229  if (PQresultStatus(res) != PGRES_TUPLES_OK)
230  {
231  pg_log_error("could not clear search_path: %s",
232  PQerrorMessage(tmpconn));
233  PQclear(res);
234  PQfinish(tmpconn);
235  exit(1);
236  }
237  PQclear(res);
238  }
239 
240  /*
241  * Ensure we have the same value of integer_datetimes (now always "on") as
242  * the server we are connecting to.
243  */
244  tmpparam = PQparameterStatus(tmpconn, "integer_datetimes");
245  if (!tmpparam)
246  {
247  pg_log_error("could not determine server setting for integer_datetimes");
248  PQfinish(tmpconn);
249  exit(1);
250  }
251 
252  if (strcmp(tmpparam, "on") != 0)
253  {
254  pg_log_error("integer_datetimes compile flag does not match server");
255  PQfinish(tmpconn);
256  exit(1);
257  }
258 
259  /*
260  * Retrieve the source data directory mode and use it to construct a umask
261  * for creating directories and files.
262  */
263  if (!RetrieveDataDirCreatePerm(tmpconn))
264  {
265  PQfinish(tmpconn);
266  exit(1);
267  }
268 
269  return tmpconn;
270 }
271 
272 /*
273  * From version 10, explicitly set wal segment size using SHOW wal_segment_size
274  * since ControlFile is not accessible here.
275  */
276 bool
278 {
279  PGresult *res;
280  char xlog_unit[3];
281  int xlog_val,
282  multiplier = 1;
283 
284  /* check connection existence */
285  Assert(conn != NULL);
286 
287  /* for previous versions set the default xlog seg size */
289  {
291  return true;
292  }
293 
294  res = PQexec(conn, "SHOW wal_segment_size");
295  if (PQresultStatus(res) != PGRES_TUPLES_OK)
296  {
297  pg_log_error("could not send replication command \"%s\": %s",
298  "SHOW wal_segment_size", PQerrorMessage(conn));
299 
300  PQclear(res);
301  return false;
302  }
303  if (PQntuples(res) != 1 || PQnfields(res) < 1)
304  {
305  pg_log_error("could not fetch WAL segment size: got %d rows and %d fields, expected %d rows and %d or more fields",
306  PQntuples(res), PQnfields(res), 1, 1);
307 
308  PQclear(res);
309  return false;
310  }
311 
312  /* fetch xlog value and unit from the result */
313  if (sscanf(PQgetvalue(res, 0, 0), "%d%s", &xlog_val, xlog_unit) != 2)
314  {
315  pg_log_error("WAL segment size could not be parsed");
316  return false;
317  }
318 
319  /* set the multiplier based on unit to convert xlog_val to bytes */
320  if (strcmp(xlog_unit, "MB") == 0)
321  multiplier = 1024 * 1024;
322  else if (strcmp(xlog_unit, "GB") == 0)
323  multiplier = 1024 * 1024 * 1024;
324 
325  /* convert and set WalSegSz */
326  WalSegSz = xlog_val * multiplier;
327 
329  {
330  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",
331  "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",
332  WalSegSz),
333  WalSegSz);
334  return false;
335  }
336 
337  PQclear(res);
338  return true;
339 }
340 
341 /*
342  * RetrieveDataDirCreatePerm
343  *
344  * This function is used to determine the privileges on the server's PG data
345  * directory and, based on that, set what the permissions will be for
346  * directories and files we create.
347  *
348  * PG11 added support for (optionally) group read/execute rights to be set on
349  * the data directory. Prior to PG11, only the owner was allowed to have rights
350  * on the data directory.
351  */
352 static bool
354 {
355  PGresult *res;
357 
358  /* check connection existence */
359  Assert(conn != NULL);
360 
361  /* for previous versions leave the default group access */
363  return true;
364 
365  res = PQexec(conn, "SHOW data_directory_mode");
366  if (PQresultStatus(res) != PGRES_TUPLES_OK)
367  {
368  pg_log_error("could not send replication command \"%s\": %s",
369  "SHOW data_directory_mode", PQerrorMessage(conn));
370 
371  PQclear(res);
372  return false;
373  }
374  if (PQntuples(res) != 1 || PQnfields(res) < 1)
375  {
376  pg_log_error("could not fetch group access flag: got %d rows and %d fields, expected %d rows and %d or more fields",
377  PQntuples(res), PQnfields(res), 1, 1);
378 
379  PQclear(res);
380  return false;
381  }
382 
383  if (sscanf(PQgetvalue(res, 0, 0), "%o", &data_directory_mode) != 1)
384  {
385  pg_log_error("group access flag could not be parsed: %s",
386  PQgetvalue(res, 0, 0));
387 
388  PQclear(res);
389  return false;
390  }
391 
392  SetDataDirectoryCreatePerm(data_directory_mode);
393 
394  PQclear(res);
395  return true;
396 }
397 
398 /*
399  * Run IDENTIFY_SYSTEM through a given connection and give back to caller
400  * some result information if requested:
401  * - System identifier
402  * - Current timeline ID
403  * - Start LSN position
404  * - Database name (NULL in servers prior to 9.4)
405  */
406 bool
407 RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
408  XLogRecPtr *startpos, char **db_name)
409 {
410  PGresult *res;
411  uint32 hi,
412  lo;
413 
414  /* Check connection existence */
415  Assert(conn != NULL);
416 
417  res = PQexec(conn, "IDENTIFY_SYSTEM");
418  if (PQresultStatus(res) != PGRES_TUPLES_OK)
419  {
420  pg_log_error("could not send replication command \"%s\": %s",
421  "IDENTIFY_SYSTEM", PQerrorMessage(conn));
422 
423  PQclear(res);
424  return false;
425  }
426  if (PQntuples(res) != 1 || PQnfields(res) < 3)
427  {
428  pg_log_error("could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields",
429  PQntuples(res), PQnfields(res), 1, 3);
430 
431  PQclear(res);
432  return false;
433  }
434 
435  /* Get system identifier */
436  if (sysid != NULL)
437  *sysid = pg_strdup(PQgetvalue(res, 0, 0));
438 
439  /* Get timeline ID to start streaming from */
440  if (starttli != NULL)
441  *starttli = atoi(PQgetvalue(res, 0, 1));
442 
443  /* Get LSN start position if necessary */
444  if (startpos != NULL)
445  {
446  if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2)
447  {
448  pg_log_error("could not parse write-ahead log location \"%s\"",
449  PQgetvalue(res, 0, 2));
450 
451  PQclear(res);
452  return false;
453  }
454  *startpos = ((uint64) hi) << 32 | lo;
455  }
456 
457  /* Get database name, only available in 9.4 and newer versions */
458  if (db_name != NULL)
459  {
460  *db_name = NULL;
461  if (PQserverVersion(conn) >= 90400)
462  {
463  if (PQnfields(res) < 4)
464  {
465  pg_log_error("could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields",
466  PQntuples(res), PQnfields(res), 1, 4);
467 
468  PQclear(res);
469  return false;
470  }
471  if (!PQgetisnull(res, 0, 3))
472  *db_name = pg_strdup(PQgetvalue(res, 0, 3));
473  }
474  }
475 
476  PQclear(res);
477  return true;
478 }
479 
480 /*
481  * Create a replication slot for the given connection. This function
482  * returns true in case of success.
483  */
484 bool
485 CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
486  bool is_temporary, bool is_physical, bool reserve_wal,
487  bool slot_exists_ok)
488 {
489  PQExpBuffer query;
490  PGresult *res;
491 
492  query = createPQExpBuffer();
493 
494  Assert((is_physical && plugin == NULL) ||
495  (!is_physical && plugin != NULL));
496  Assert(slot_name != NULL);
497 
498  /* Build query */
499  appendPQExpBuffer(query, "CREATE_REPLICATION_SLOT \"%s\"", slot_name);
500  if (is_temporary)
501  appendPQExpBufferStr(query, " TEMPORARY");
502  if (is_physical)
503  {
504  appendPQExpBufferStr(query, " PHYSICAL");
505  if (reserve_wal)
506  appendPQExpBufferStr(query, " RESERVE_WAL");
507  }
508  else
509  {
510  appendPQExpBuffer(query, " LOGICAL \"%s\"", plugin);
511  if (PQserverVersion(conn) >= 100000)
512  /* pg_recvlogical doesn't use an exported snapshot, so suppress */
513  appendPQExpBufferStr(query, " NOEXPORT_SNAPSHOT");
514  }
515 
516  res = PQexec(conn, query->data);
517  if (PQresultStatus(res) != PGRES_TUPLES_OK)
518  {
519  const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
520 
521  if (slot_exists_ok &&
522  sqlstate &&
523  strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
524  {
525  destroyPQExpBuffer(query);
526  PQclear(res);
527  return true;
528  }
529  else
530  {
531  pg_log_error("could not send replication command \"%s\": %s",
532  query->data, PQerrorMessage(conn));
533 
534  destroyPQExpBuffer(query);
535  PQclear(res);
536  return false;
537  }
538  }
539 
540  if (PQntuples(res) != 1 || PQnfields(res) != 4)
541  {
542  pg_log_error("could not create replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields",
543  slot_name,
544  PQntuples(res), PQnfields(res), 1, 4);
545 
546  destroyPQExpBuffer(query);
547  PQclear(res);
548  return false;
549  }
550 
551  destroyPQExpBuffer(query);
552  PQclear(res);
553  return true;
554 }
555 
556 /*
557  * Drop a replication slot for the given connection. This function
558  * returns true in case of success.
559  */
560 bool
561 DropReplicationSlot(PGconn *conn, const char *slot_name)
562 {
563  PQExpBuffer query;
564  PGresult *res;
565 
566  Assert(slot_name != NULL);
567 
568  query = createPQExpBuffer();
569 
570  /* Build query */
571  appendPQExpBuffer(query, "DROP_REPLICATION_SLOT \"%s\"",
572  slot_name);
573  res = PQexec(conn, query->data);
574  if (PQresultStatus(res) != PGRES_COMMAND_OK)
575  {
576  pg_log_error("could not send replication command \"%s\": %s",
577  query->data, PQerrorMessage(conn));
578 
579  destroyPQExpBuffer(query);
580  PQclear(res);
581  return false;
582  }
583 
584  if (PQntuples(res) != 0 || PQnfields(res) != 0)
585  {
586  pg_log_error("could not drop replication slot \"%s\": got %d rows and %d fields, expected %d rows and %d fields",
587  slot_name,
588  PQntuples(res), PQnfields(res), 0, 0);
589 
590  destroyPQExpBuffer(query);
591  PQclear(res);
592  return false;
593  }
594 
595  destroyPQExpBuffer(query);
596  PQclear(res);
597  return true;
598 }
599 
600 
601 /*
602  * Frontend version of GetCurrentTimestamp(), since we are not linked with
603  * backend code.
604  */
607 {
608  TimestampTz result;
609  struct timeval tp;
610 
611  gettimeofday(&tp, NULL);
612 
613  result = (TimestampTz) tp.tv_sec -
615  result = (result * USECS_PER_SEC) + tp.tv_usec;
616 
617  return result;
618 }
619 
620 /*
621  * Frontend version of TimestampDifference(), since we are not linked with
622  * backend code.
623  */
624 void
626  long *secs, int *microsecs)
627 {
628  TimestampTz diff = stop_time - start_time;
629 
630  if (diff <= 0)
631  {
632  *secs = 0;
633  *microsecs = 0;
634  }
635  else
636  {
637  *secs = (long) (diff / USECS_PER_SEC);
638  *microsecs = (int) (diff % USECS_PER_SEC);
639  }
640 }
641 
642 /*
643  * Frontend version of TimestampDifferenceExceeds(), since we are not
644  * linked with backend code.
645  */
646 bool
648  TimestampTz stop_time,
649  int msec)
650 {
651  TimestampTz diff = stop_time - start_time;
652 
653  return (diff >= msec * INT64CONST(1000));
654 }
655 
656 /*
657  * Converts an int64 to network byte order.
658  */
659 void
660 fe_sendint64(int64 i, char *buf)
661 {
662  uint64 n64 = pg_hton64(i);
663 
664  memcpy(buf, &n64, sizeof(n64));
665 }
666 
667 /*
668  * Converts an int64 from network byte order to native format.
669  */
670 int64
672 {
673  uint64 n64;
674 
675  memcpy(&n64, buf, sizeof(n64));
676 
677  return pg_ntoh64(n64);
678 }
#define IsValidWalSegSize(size)
Definition: xlog_internal.h:97
static char password[100]
Definition: streamutil.c:53
static const char * plugin
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2777
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6623
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: gettimeofday.c:105
uint32 TimeLineID
Definition: xlogdefs.h:52
TimestampTz feGetCurrentTimestamp(void)
Definition: streamutil.c:606
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:6588
#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:79
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:407
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4125
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6613
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:647
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:624
static time_t start_time
Definition: pg_ctl.c:99
#define MINIMUM_VERSION_FOR_SHOW_CMD
Definition: streamutil.c:38
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:5225
char * connection_string
Definition: streamutil.c:46
#define SECS_PER_DAY
Definition: timestamp.h:86
bool RetrieveWalSegSize(PGconn *conn)
Definition: streamutil.c:277
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:625
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:6455
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
unsigned int uint32
Definition: c.h:359
int dbgetpassword
Definition: streamutil.c:51
#define ngettext(s, p, n)
Definition: c.h:1134
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74
char * dbport
Definition: streamutil.c:49
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define free(a)
Definition: header.h:65
static bool have_password
Definition: streamutil.c:52
const char * progname
Definition: streamutil.c:45
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:2754
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:739
char * dbhost
Definition: streamutil.c:47
char * dbname
Definition: streamutil.c:50
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:485
uint32 WalSegSz
Definition: streamutil.c:33
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define MINIMUM_VERSION_FOR_GROUP_ACCESS
Definition: streamutil.c:43
int PQconnectionNeedsPassword(const PGconn *conn)
Definition: fe-connect.c:6657
int64 fe_recvint64(char *buf)
Definition: streamutil.c:671
char * dbuser
Definition: streamutil.c:48
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:561
#define UNIX_EPOCH_JDATE
Definition: timestamp.h:162
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
static bool RetrieveDataDirCreatePerm(PGconn *conn)
Definition: streamutil.c:353
void fe_sendint64(int64 i, char *buf)
Definition: streamutil.c:660
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:6570
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:31
#define pg_ntoh64(x)
Definition: pg_bswap.h:126