PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_backup_db.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_backup_db.c
4  *
5  * Implements the basic DB functions used by the archiver.
6  *
7  * IDENTIFICATION
8  * src/bin/pg_dump/pg_backup_db.c
9  *
10  *-------------------------------------------------------------------------
11  */
12 #include "postgres_fe.h"
13 
14 #include "dumputils.h"
15 #include "fe_utils/string_utils.h"
16 #include "parallel.h"
17 #include "pg_backup_archiver.h"
18 #include "pg_backup_db.h"
19 #include "pg_backup_utils.h"
20 
21 #include <unistd.h>
22 #include <ctype.h>
23 #ifdef HAVE_TERMIOS_H
24 #include <termios.h>
25 #endif
26 
27 
28 #define DB_MAX_ERR_STMT 128
29 
30 /* translator: this is a module name */
31 static const char *modulename = gettext_noop("archiver (db)");
32 
33 static void _check_database_version(ArchiveHandle *AH);
34 static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser);
35 static void notice_processor(void *arg, const char *message);
36 
37 static void
39 {
40  const char *remoteversion_str;
41  int remoteversion;
42  PGresult *res;
43 
44  remoteversion_str = PQparameterStatus(AH->connection, "server_version");
45  remoteversion = PQserverVersion(AH->connection);
46  if (remoteversion == 0 || !remoteversion_str)
47  exit_horribly(modulename, "could not get server_version from libpq\n");
48 
49  AH->public.remoteVersionStr = pg_strdup(remoteversion_str);
50  AH->public.remoteVersion = remoteversion;
51  if (!AH->archiveRemoteVersion)
53 
54  if (remoteversion != PG_VERSION_NUM
55  && (remoteversion < AH->public.minRemoteVersion ||
56  remoteversion > AH->public.maxRemoteVersion))
57  {
58  write_msg(NULL, "server version: %s; %s version: %s\n",
59  remoteversion_str, progname, PG_VERSION);
60  exit_horribly(NULL, "aborting because of server version mismatch\n");
61  }
62 
63  /*
64  * When running against 9.0 or later, check if we are in recovery mode,
65  * which means we are on a hot standby.
66  */
67  if (remoteversion >= 90000)
68  {
69  res = ExecuteSqlQueryForSingleRow((Archive *) AH, "SELECT pg_catalog.pg_is_in_recovery()");
70 
71  AH->public.isStandby = (strcmp(PQgetvalue(res, 0, 0), "t") == 0);
72  PQclear(res);
73  }
74  else
75  AH->public.isStandby = false;
76 }
77 
78 /*
79  * Reconnect to the server. If dbname is not NULL, use that database,
80  * else the one associated with the archive handle. If username is
81  * not NULL, use that user name, else the one from the handle. If
82  * both the database and the user match the existing connection already,
83  * nothing will be done.
84  *
85  * Returns 1 in any case.
86  */
87 int
88 ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
89 {
90  PGconn *newConn;
91  const char *newdbname;
92  const char *newusername;
93 
94  if (!dbname)
95  newdbname = PQdb(AH->connection);
96  else
97  newdbname = dbname;
98 
99  if (!username)
100  newusername = PQuser(AH->connection);
101  else
102  newusername = username;
103 
104  /* Let's see if the request is already satisfied */
105  if (strcmp(newdbname, PQdb(AH->connection)) == 0 &&
106  strcmp(newusername, PQuser(AH->connection)) == 0)
107  return 1;
108 
109  newConn = _connectDB(AH, newdbname, newusername);
110 
111  /* Update ArchiveHandle's connCancel before closing old connection */
112  set_archive_cancel_info(AH, newConn);
113 
114  PQfinish(AH->connection);
115  AH->connection = newConn;
116 
117  return 1;
118 }
119 
120 /*
121  * Connect to the db again.
122  *
123  * Note: it's not really all that sensible to use a single-entry password
124  * cache if the username keeps changing. In current usage, however, the
125  * username never does change, so one savedPassword is sufficient. We do
126  * update the cache on the off chance that the password has changed since the
127  * start of the run.
128  */
129 static PGconn *
130 _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
131 {
133  PGconn *newConn;
134  const char *newdb;
135  const char *newuser;
136  char *password;
137  char passbuf[100];
138  bool new_pass;
139 
140  if (!reqdb)
141  newdb = PQdb(AH->connection);
142  else
143  newdb = reqdb;
144 
145  if (!requser || strlen(requser) == 0)
146  newuser = PQuser(AH->connection);
147  else
148  newuser = requser;
149 
150  ahlog(AH, 1, "connecting to database \"%s\" as user \"%s\"\n",
151  newdb, newuser);
152 
153  password = AH->savedPassword;
154 
155  if (AH->promptPassword == TRI_YES && password == NULL)
156  {
157  simple_prompt("Password: ", passbuf, sizeof(passbuf), false);
158  password = passbuf;
159  }
160 
161  initPQExpBuffer(&connstr);
162  appendPQExpBuffer(&connstr, "dbname=");
163  appendConnStrVal(&connstr, newdb);
164 
165  do
166  {
167  const char *keywords[7];
168  const char *values[7];
169 
170  keywords[0] = "host";
171  values[0] = PQhost(AH->connection);
172  keywords[1] = "port";
173  values[1] = PQport(AH->connection);
174  keywords[2] = "user";
175  values[2] = newuser;
176  keywords[3] = "password";
177  values[3] = password;
178  keywords[4] = "dbname";
179  values[4] = connstr.data;
180  keywords[5] = "fallback_application_name";
181  values[5] = progname;
182  keywords[6] = NULL;
183  values[6] = NULL;
184 
185  new_pass = false;
186  newConn = PQconnectdbParams(keywords, values, true);
187 
188  if (!newConn)
189  exit_horribly(modulename, "failed to reconnect to database\n");
190 
191  if (PQstatus(newConn) == CONNECTION_BAD)
192  {
193  if (!PQconnectionNeedsPassword(newConn))
194  exit_horribly(modulename, "could not reconnect to database: %s",
195  PQerrorMessage(newConn));
196  PQfinish(newConn);
197 
198  if (password)
199  fprintf(stderr, "Password incorrect\n");
200 
201  fprintf(stderr, "Connecting to %s as %s\n",
202  newdb, newuser);
203 
204  if (AH->promptPassword != TRI_NO)
205  {
206  simple_prompt("Password: ", passbuf, sizeof(passbuf), false);
207  password = passbuf;
208  }
209  else
210  exit_horribly(modulename, "connection needs password\n");
211 
212  new_pass = true;
213  }
214  } while (new_pass);
215 
216  /*
217  * We want to remember connection's actual password, whether or not we got
218  * it by prompting. So we don't just store the password variable.
219  */
220  if (PQconnectionUsedPassword(newConn))
221  {
222  if (AH->savedPassword)
223  free(AH->savedPassword);
224  AH->savedPassword = pg_strdup(PQpass(newConn));
225  }
226 
227  termPQExpBuffer(&connstr);
228 
229  /* check for version mismatch */
231 
233 
234  return newConn;
235 }
236 
237 
238 /*
239  * Make a database connection with the given parameters. The
240  * connection handle is returned, the parameters are stored in AHX.
241  * An interactive password prompt is automatically issued if required.
242  *
243  * Note: it's not really all that sensible to use a single-entry password
244  * cache if the username keeps changing. In current usage, however, the
245  * username never does change, so one savedPassword is sufficient.
246  */
247 void
249  const char *dbname,
250  const char *pghost,
251  const char *pgport,
252  const char *username,
253  trivalue prompt_password)
254 {
255  ArchiveHandle *AH = (ArchiveHandle *) AHX;
256  char *password;
257  char passbuf[100];
258  bool new_pass;
259 
260  if (AH->connection)
261  exit_horribly(modulename, "already connected to a database\n");
262 
263  password = AH->savedPassword;
264 
265  if (prompt_password == TRI_YES && password == NULL)
266  {
267  simple_prompt("Password: ", passbuf, sizeof(passbuf), false);
268  password = passbuf;
269  }
270  AH->promptPassword = prompt_password;
271 
272  /*
273  * Start the connection. Loop until we have a password if requested by
274  * backend.
275  */
276  do
277  {
278  const char *keywords[7];
279  const char *values[7];
280 
281  keywords[0] = "host";
282  values[0] = pghost;
283  keywords[1] = "port";
284  values[1] = pgport;
285  keywords[2] = "user";
286  values[2] = username;
287  keywords[3] = "password";
288  values[3] = password;
289  keywords[4] = "dbname";
290  values[4] = dbname;
291  keywords[5] = "fallback_application_name";
292  values[5] = progname;
293  keywords[6] = NULL;
294  values[6] = NULL;
295 
296  new_pass = false;
297  AH->connection = PQconnectdbParams(keywords, values, true);
298 
299  if (!AH->connection)
300  exit_horribly(modulename, "failed to connect to database\n");
301 
302  if (PQstatus(AH->connection) == CONNECTION_BAD &&
304  password == NULL &&
305  prompt_password != TRI_NO)
306  {
307  PQfinish(AH->connection);
308  simple_prompt("Password: ", passbuf, sizeof(passbuf), false);
309  password = passbuf;
310  new_pass = true;
311  }
312  } while (new_pass);
313 
314  /* check to see that the backend connection was successfully made */
315  if (PQstatus(AH->connection) == CONNECTION_BAD)
316  exit_horribly(modulename, "connection to database \"%s\" failed: %s",
317  PQdb(AH->connection) ? PQdb(AH->connection) : "",
319 
320  /*
321  * We want to remember connection's actual password, whether or not we got
322  * it by prompting. So we don't just store the password variable.
323  */
325  {
326  if (AH->savedPassword)
327  free(AH->savedPassword);
329  }
330 
331  /* check for version mismatch */
333 
335 
336  /* arrange for SIGINT to issue a query cancel on this connection */
338 }
339 
340 /*
341  * Close the connection to the database and also cancel off the query if we
342  * have one running.
343  */
344 void
346 {
347  ArchiveHandle *AH = (ArchiveHandle *) AHX;
348  char errbuf[1];
349 
350  if (!AH->connection)
351  return;
352 
353  if (AH->connCancel)
354  {
355  /*
356  * If we have an active query, send a cancel before closing. This is
357  * of no use for a normal exit, but might be helpful during
358  * exit_horribly().
359  */
361  PQcancel(AH->connCancel, errbuf, sizeof(errbuf));
362 
363  /*
364  * Prevent signal handler from sending a cancel after this.
365  */
367  }
368 
369  PQfinish(AH->connection);
370  AH->connection = NULL;
371 }
372 
373 PGconn *
375 {
376  ArchiveHandle *AH = (ArchiveHandle *) AHX;
377 
378  return AH->connection;
379 }
380 
381 static void
382 notice_processor(void *arg, const char *message)
383 {
384  write_msg(NULL, "%s", message);
385 }
386 
387 /* Like exit_horribly(), but with a complaint about a particular query. */
388 static void
389 die_on_query_failure(ArchiveHandle *AH, const char *modulename, const char *query)
390 {
391  write_msg(modulename, "query failed: %s",
393  exit_horribly(modulename, "query was: %s\n", query);
394 }
395 
396 void
397 ExecuteSqlStatement(Archive *AHX, const char *query)
398 {
399  ArchiveHandle *AH = (ArchiveHandle *) AHX;
400  PGresult *res;
401 
402  res = PQexec(AH->connection, query);
403  if (PQresultStatus(res) != PGRES_COMMAND_OK)
404  die_on_query_failure(AH, modulename, query);
405  PQclear(res);
406 }
407 
408 PGresult *
409 ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
410 {
411  ArchiveHandle *AH = (ArchiveHandle *) AHX;
412  PGresult *res;
413 
414  res = PQexec(AH->connection, query);
415  if (PQresultStatus(res) != status)
416  die_on_query_failure(AH, modulename, query);
417  return res;
418 }
419 
420 /*
421  * Execute an SQL query and verify that we got exactly one row back.
422  */
423 PGresult *
425 {
426  PGresult *res;
427  int ntups;
428 
429  res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK);
430 
431  /* Expecting a single result only */
432  ntups = PQntuples(res);
433  if (ntups != 1)
435  ngettext("query returned %d row instead of one: %s\n",
436  "query returned %d rows instead of one: %s\n",
437  ntups),
438  ntups, query);
439 
440  return res;
441 }
442 
443 /*
444  * Convenience function to send a query.
445  * Monitors result to detect COPY statements
446  */
447 static void
448 ExecuteSqlCommand(ArchiveHandle *AH, const char *qry, const char *desc)
449 {
450  PGconn *conn = AH->connection;
451  PGresult *res;
452  char errStmt[DB_MAX_ERR_STMT];
453 
454 #ifdef NOT_USED
455  fprintf(stderr, "Executing: '%s'\n\n", qry);
456 #endif
457  res = PQexec(conn, qry);
458 
459  switch (PQresultStatus(res))
460  {
461  case PGRES_COMMAND_OK:
462  case PGRES_TUPLES_OK:
463  case PGRES_EMPTY_QUERY:
464  /* A-OK */
465  break;
466  case PGRES_COPY_IN:
467  /* Assume this is an expected result */
468  AH->pgCopyIn = true;
469  break;
470  default:
471  /* trouble */
472  strncpy(errStmt, qry, DB_MAX_ERR_STMT); /* strncpy required here */
473  if (errStmt[DB_MAX_ERR_STMT - 1] != '\0')
474  {
475  errStmt[DB_MAX_ERR_STMT - 4] = '.';
476  errStmt[DB_MAX_ERR_STMT - 3] = '.';
477  errStmt[DB_MAX_ERR_STMT - 2] = '.';
478  errStmt[DB_MAX_ERR_STMT - 1] = '\0';
479  }
480  warn_or_exit_horribly(AH, modulename, "%s: %s Command was: %s\n",
481  desc, PQerrorMessage(conn), errStmt);
482  break;
483  }
484 
485  PQclear(res);
486 }
487 
488 
489 /*
490  * Process non-COPY table data (that is, INSERT commands).
491  *
492  * The commands have been run together as one long string for compressibility,
493  * and we are receiving them in bufferloads with arbitrary boundaries, so we
494  * have to locate command boundaries and save partial commands across calls.
495  * All state must be kept in AH->sqlparse, not in local variables of this
496  * routine. We assume that AH->sqlparse was filled with zeroes when created.
497  *
498  * We have to lex the data to the extent of identifying literals and quoted
499  * identifiers, so that we can recognize statement-terminating semicolons.
500  * We assume that INSERT data will not contain SQL comments, E'' literals,
501  * or dollar-quoted strings, so this is much simpler than a full SQL lexer.
502  *
503  * Note: when restoring from a pre-9.0 dump file, this code is also used to
504  * process BLOB COMMENTS data, which has the same problem of containing
505  * multiple SQL commands that might be split across bufferloads. Fortunately,
506  * that data won't contain anything complicated to lex either.
507  */
508 static void
509 ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
510 {
511  const char *qry = buf;
512  const char *eos = buf + bufLen;
513 
514  /* initialize command buffer if first time through */
515  if (AH->sqlparse.curCmd == NULL)
517 
518  for (; qry < eos; qry++)
519  {
520  char ch = *qry;
521 
522  /* For neatness, we skip any newlines between commands */
523  if (!(ch == '\n' && AH->sqlparse.curCmd->len == 0))
525 
526  switch (AH->sqlparse.state)
527  {
528  case SQL_SCAN: /* Default state == 0, set in _allocAH */
529  if (ch == ';')
530  {
531  /*
532  * We've found the end of a statement. Send it and reset
533  * the buffer.
534  */
536  "could not execute query");
538  }
539  else if (ch == '\'')
540  {
542  AH->sqlparse.backSlash = false;
543  }
544  else if (ch == '"')
545  {
547  }
548  break;
549 
550  case SQL_IN_SINGLE_QUOTE:
551  /* We needn't handle '' specially */
552  if (ch == '\'' && !AH->sqlparse.backSlash)
553  AH->sqlparse.state = SQL_SCAN;
554  else if (ch == '\\' && !AH->public.std_strings)
556  else
557  AH->sqlparse.backSlash = false;
558  break;
559 
560  case SQL_IN_DOUBLE_QUOTE:
561  /* We needn't handle "" specially */
562  if (ch == '"')
563  AH->sqlparse.state = SQL_SCAN;
564  break;
565  }
566  }
567 }
568 
569 
570 /*
571  * Implement ahwrite() for direct-to-DB restore
572  */
573 int
574 ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)
575 {
576  ArchiveHandle *AH = (ArchiveHandle *) AHX;
577 
578  if (AH->outputKind == OUTPUT_COPYDATA)
579  {
580  /*
581  * COPY data.
582  *
583  * We drop the data on the floor if libpq has failed to enter COPY
584  * mode; this allows us to behave reasonably when trying to continue
585  * after an error in a COPY command.
586  */
587  if (AH->pgCopyIn &&
588  PQputCopyData(AH->connection, buf, bufLen) <= 0)
589  exit_horribly(modulename, "error returned by PQputCopyData: %s",
591  }
592  else if (AH->outputKind == OUTPUT_OTHERDATA)
593  {
594  /*
595  * Table data expressed as INSERT commands; or, in old dump files,
596  * BLOB COMMENTS data (which is expressed as COMMENT ON commands).
597  */
598  ExecuteSimpleCommands(AH, buf, bufLen);
599  }
600  else
601  {
602  /*
603  * General SQL commands; we assume that commands will not be split
604  * across calls.
605  *
606  * In most cases the data passed to us will be a null-terminated
607  * string, but if it's not, we have to add a trailing null.
608  */
609  if (buf[bufLen] == '\0')
610  ExecuteSqlCommand(AH, buf, "could not execute query");
611  else
612  {
613  char *str = (char *) pg_malloc(bufLen + 1);
614 
615  memcpy(str, buf, bufLen);
616  str[bufLen] = '\0';
617  ExecuteSqlCommand(AH, str, "could not execute query");
618  free(str);
619  }
620  }
621 
622  return bufLen;
623 }
624 
625 /*
626  * Terminate a COPY operation during direct-to-DB restore
627  */
628 void
629 EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
630 {
631  ArchiveHandle *AH = (ArchiveHandle *) AHX;
632 
633  if (AH->pgCopyIn)
634  {
635  PGresult *res;
636 
637  if (PQputCopyEnd(AH->connection, NULL) <= 0)
638  exit_horribly(modulename, "error returned by PQputCopyEnd: %s",
640 
641  /* Check command status and return to normal libpq state */
642  res = PQgetResult(AH->connection);
643  if (PQresultStatus(res) != PGRES_COMMAND_OK)
644  warn_or_exit_horribly(AH, modulename, "COPY failed for table \"%s\": %s",
645  tocEntryTag, PQerrorMessage(AH->connection));
646  PQclear(res);
647 
648  /* Do this to ensure we've pumped libpq back to idle state */
649  if (PQgetResult(AH->connection) != NULL)
650  write_msg(NULL, "WARNING: unexpected extra results during COPY of table \"%s\"\n",
651  tocEntryTag);
652 
653  AH->pgCopyIn = false;
654  }
655 }
656 
657 void
659 {
660  ArchiveHandle *AH = (ArchiveHandle *) AHX;
661 
662  ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction");
663 }
664 
665 void
667 {
668  ArchiveHandle *AH = (ArchiveHandle *) AHX;
669 
670  ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction");
671 }
672 
673 void
675 {
676  /*
677  * If we are not restoring to a direct database connection, we have to
678  * guess about how to detect whether the blob exists. Assume new-style.
679  */
680  if (AH->connection == NULL ||
681  PQserverVersion(AH->connection) >= 90000)
682  {
683  ahprintf(AH,
684  "SELECT pg_catalog.lo_unlink(oid) "
685  "FROM pg_catalog.pg_largeobject_metadata "
686  "WHERE oid = '%u';\n",
687  oid);
688  }
689  else
690  {
691  /* Restoring to pre-9.0 server, so do it the old way */
692  ahprintf(AH,
693  "SELECT CASE WHEN EXISTS("
694  "SELECT 1 FROM pg_catalog.pg_largeobject WHERE loid = '%u'"
695  ") THEN pg_catalog.lo_unlink('%u') END;\n",
696  oid, oid);
697  }
698 }
int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
Definition: fe-exec.c:2221
static char password[100]
Definition: streamutil.c:41
PQExpBuffer curCmd
void EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
Definition: pg_backup_db.c:629
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:5959
sqlparseState state
int ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)
Definition: pg_backup_db.c:574
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
Definition: fe-connect.c:6135
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:5924
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
static void ExecuteSqlCommand(ArchiveHandle *AH, const char *qry, const char *desc)
Definition: pg_backup_db.c:448
void DisconnectDatabase(Archive *AHX)
Definition: pg_backup_db.c:345
static PGconn * _connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser)
Definition: pg_backup_db.c:130
void CommitTransaction(Archive *AHX)
Definition: pg_backup_db.c:666
#define gettext_noop(x)
Definition: c.h:139
void appendConnStrVal(PQExpBuffer buf, const char *str)
Definition: string_utils.c:536
void StartTransaction(Archive *AHX)
Definition: pg_backup_db.c:658
void PQfinish(PGconn *conn)
Definition: fe-connect.c:3516
char * PQport(const PGconn *conn)
Definition: fe-connect.c:5880
int PQputCopyEnd(PGconn *conn, const char *errormsg)
Definition: fe-exec.c:2288
ExecStatusType
Definition: libpq-fe.h:82
PGcancel *volatile connCancel
unsigned int Oid
Definition: postgres_ext.h:31
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:5949
const char * progname
Definition: pg_standby.c:37
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
PGconn * GetConnection(Archive *AHX)
Definition: pg_backup_db.c:374
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:2596
int maxRemoteVersion
Definition: pg_backup.h:187
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:470
char * PQuser(const PGconn *conn)
Definition: fe-connect.c:5835
void warn_or_exit_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
void ConnectDatabase(Archive *AHX, const char *dbname, const char *pghost, const char *pgport, const char *username, trivalue prompt_password)
Definition: pg_backup_db.c:248
bool isStandby
Definition: pg_backup.h:184
PGconn * conn
Definition: streamutil.c:42
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
static char * buf
Definition: pg_test_fsync.c:65
void simple_prompt(const char *prompt, char *destination, size_t destlen, bool echo)
Definition: sprompt.c:37
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
char * PQpass(const PGconn *conn)
Definition: fe-connect.c:5843
static void notice_processor(void *arg, const char *message)
Definition: pg_backup_db.c:382
sqlparseInfo sqlparse
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, char *query)
Definition: pg_backup_db.c:424
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:5914
#define DB_MAX_ERR_STMT
Definition: pg_backup_db.c:28
char * pghost
Definition: pgbench.c:180
trivalue
Definition: vacuumlo.c:31
#define ngettext(s, p, n)
Definition: c.h:127
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:71
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:396
static const char * modulename
Definition: pg_backup_db.c:31
static char * username
Definition: initdb.c:129
static void ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
Definition: pg_backup_db.c:509
static void die_on_query_failure(ArchiveHandle *AH, const char *modulename, const char *query)
Definition: pg_backup_db.c:389
char * PQhost(const PGconn *conn)
Definition: fe-connect.c:5860
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define free(a)
Definition: header.h:60
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:5827
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:226
void ExecuteSqlStatement(Archive *AHX, const char *query)
Definition: pg_backup_db.c:397
char * dbname
Definition: streamutil.c:38
ArchiverOutput outputKind
void exit_horribly(const char *modulename, const char *fmt,...)
static Datum values[MAXATTR]
Definition: bootstrap.c:162
static void _check_database_version(ArchiveHandle *AH)
Definition: pg_backup_db.c:38
int PQconnectionUsedPassword(const PGconn *conn)
Definition: fe-connect.c:6008
int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)
Definition: fe-connect.c:3792
char * remoteVersionStr
Definition: pg_backup.h:182
int PQconnectionNeedsPassword(const PGconn *conn)
Definition: fe-connect.c:5993
void ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
void set_archive_cancel_info(ArchiveHandle *AH, PGconn *conn)
Definition: parallel.c:742
int ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
Definition: pg_backup_db.c:88
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1846
void * arg
void DropBlobIfExists(ArchiveHandle *AH, Oid oid)
Definition: pg_backup_db.c:674
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:145
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:222
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:5906
char * pgport
Definition: pgbench.c:181
PGresult * PQgetResult(PGconn *conn)
Definition: fe-exec.c:1702
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
bool std_strings
Definition: pg_backup.h:195
PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
Definition: pg_backup_db.c:409
int remoteVersion
Definition: pg_backup.h:183
static char * connstr
Definition: pg_dumpall.c:63