PostgreSQL Source Code: src/bin/pg_dump/pg_backup_db.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

13

15#include <ctype.h>

16#ifdef HAVE_TERMIOS_H

17#include <termios.h>

18#endif

19

27

30

31static void

33{

34 const char *remoteversion_str;

35 int remoteversion;

37

40 if (remoteversion == 0 || !remoteversion_str)

41 pg_fatal("could not get \"server_version\" from libpq");

42

47

48 if (remoteversion != PG_VERSION_NUM

49 && (remoteversion < AH->public.minRemoteVersion ||

51 {

52 pg_log_error("aborting because of server version mismatch");

54 remoteversion_str, progname, PG_VERSION);

55 exit(1);

56 }

57

58

59

60

61

63 "SELECT pg_catalog.pg_is_in_recovery()");

66}

67

68

69

70

71

72void

74{

77

78

79

80

81

84

85

86

87

88

89

90 AH->connection = NULL;

91

93

95}

96

97

98

99

100

101

102

103

104

105

106

107

108void

111 bool isReconnect)

112{

116

118 pg_fatal("already connected to a database");

119

120

122

124

127

130 prompt_password, true,

132

133

136

139

140

141

142

143

145 {

148 }

149

150

152

154

155

157}

158

159

160

161

162

163void

165{

167 char errbuf[1];

168

170 return;

171

173 {

174

175

176

177

178

181

182

183

184

186 }

187

190}

191

194{

196

198}

199

200static void

202{

204}

205

206

207static void

209{

213 exit(1);

214}

215

216void

218{

221

226}

227

230{

233

237 return res;

238}

239

240

241

242

245{

247 int ntups;

248

250

251

253 if (ntups != 1)

254 pg_fatal(ngettext("query returned %d row instead of one: %s",

255 "query returned %d rows instead of one: %s",

256 ntups),

257 ntups, query);

258

259 return res;

260}

261

262

263

264

265

266static void

268{

271

272#ifdef NOT_USED

273 fprintf(stderr, "Executing: '%s'\n\n", qry);

274#endif

276

278 {

282

283 break;

285

287 break;

288 default:

289

292 break;

293 }

294

296}

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318static void

320{

321 const char *qry = buf;

322 const char *eos = buf + bufLen;

323

324

327

328 for (; qry < eos; qry++)

329 {

330 char ch = *qry;

331

332

335

337 {

338 case SQL_SCAN:

339 if (ch == ';')

340 {

341

342

343

344

346 "could not execute query");

348 }

349 else if (ch == '\'')

350 {

353 }

354 else if (ch == '"')

355 {

357 }

358 break;

359

361

366 else

368 break;

369

371

372 if (ch == '"')

374 break;

375 }

376 }

377}

378

379

380

381

382

383int

385{

387

389 {

390

391

392

393

394

395

396

399 pg_fatal("error returned by PQputCopyData: %s",

401 }

403 {

404

405

406

407

409 }

410 else

411 {

412

413

414

415

416

417

418

419 if (buf[bufLen] == '\0')

421 else

422 {

424

425 memcpy(str, buf, bufLen);

426 str[bufLen] = '\0';

429 }

430 }

431

432 return bufLen;

433}

434

435

436

437

438void

440{

442

444 {

446

448 pg_fatal("error returned by PQputCopyEnd: %s",

450

451

457

458

460 pg_log_warning("unexpected extra results during COPY of table \"%s\"",

461 tocEntryTag);

462

464 }

465}

466

467void

469{

471

472 ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction");

473}

474

475void

477{

479

480 ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction");

481}

482

483

484

485

486

487

488

489

490void

492 const char *cmdBegin, const char *cmdEnd)

493{

494

497 char *st;

498 char *en;

499

500 st = buf;

501 while ((en = strchr(st, '\n')) != NULL)

502 {

503 *en++ = '\0';

504 ahprintf(AH, "%s%s%s;\n", cmdBegin, st, cmdEnd);

505

506

507 if (ropt && ropt->txn_size > 0)

508 {

510 {

512 {

515 }

516 else

517 ahprintf(AH, "COMMIT;\nBEGIN;\n\n");

519 }

520 }

521

522 st = en;

523 }

526}

527

528

529

530

531

532

533

534

535

536

537void

539{

541 char *buf;

542 char *st;

543 char *st2;

544 char *en;

545 bool inquotes;

546

547 if (!blobte)

549 Assert(strcmp(blobte->desc, "BLOB METADATA") == 0);

550

551

553

554

555

556

557

558

559

560

561

562

563 inquotes = false;

564 st = en = buf;

565 st2 = NULL;

566 while (*en)

567 {

568

569 if (*en == '"')

570 inquotes = !inquotes;

571 if (inquotes)

572 {

573 en++;

574 continue;

575 }

576

577 if (strncmp(en, "LARGE OBJECT ", 13) == 0)

578 {

579

580 en += 13;

581 Assert(isdigit((unsigned char) *en));

582 *en++ = '\0';

583

584 while (isdigit((unsigned char) *en))

585 en++;

586

588 st2 = en;

589 }

590

591 else if (*en == ';')

592 {

593

594 *en++ = '\0';

596

598

599 while (isspace((unsigned char) *en))

600 en++;

601

602 st = en;

603 st2 = NULL;

604 }

605 else

606 en++;

607 }

609}

610

611void

613{

615 "SELECT pg_catalog.lo_unlink(oid) "

616 "FROM pg_catalog.pg_largeobject_metadata "

617 "WHERE oid = '%u';\n",

618 oid);

619}

void set_archive_cancel_info(ArchiveHandle *AH, PGconn *conn)

#define ngettext(s, p, n)

#define ALWAYS_SECURE_SEARCH_PATH_SQL

PGconn * ConnectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error, const char *progname, const char **connstr, int *server_version, char *password, char *override_dbname)

#define fprintf(file, fmt, msg)

int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize)

int PQserverVersion(const PGconn *conn)

PGTransactionStatusType PQtransactionStatus(const PGconn *conn)

int PQconnectionUsedPassword(const PGconn *conn)

const char * PQparameterStatus(const PGconn *conn, const char *paramName)

char * PQpass(const PGconn *conn)

void PQfinish(PGconn *conn)

PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)

char * PQerrorMessage(const PGconn *conn)

char * PQgetvalue(const PGresult *res, int tup_num, int field_num)

PGresult * PQgetResult(PGconn *conn)

ExecStatusType PQresultStatus(const PGresult *res)

void PQclear(PGresult *res)

int PQputCopyEnd(PGconn *conn, const char *errormsg)

int PQntuples(const PGresult *res)

int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)

PGresult * PQexec(PGconn *conn, const char *query)

void * pg_malloc(size_t size)

char * pg_strdup(const char *in)

Assert(PointerIsAligned(start, uint64))

#define pg_log_error(...)

#define pg_log_error_detail(...)

void warn_or_exit_horribly(ArchiveHandle *AH, const char *fmt,...)

TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)

int ahprintf(ArchiveHandle *AH, const char *fmt,...)

void ExecuteSqlStatement(Archive *AHX, const char *query)

PGconn * GetConnection(Archive *AHX)

void IssueACLPerBlob(ArchiveHandle *AH, TocEntry *te)

void EndDBCopyMode(Archive *AHX, const char *tocEntryTag)

static void die_on_query_failure(ArchiveHandle *AH, const char *query)

PGresult * ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)

PGresult * ExecuteSqlQueryForSingleRow(Archive *fout, const char *query)

static void _check_database_version(ArchiveHandle *AH)

void DropLOIfExists(ArchiveHandle *AH, Oid oid)

void ReconnectToServer(ArchiveHandle *AH, const char *dbname)

void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)

static void ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)

void StartTransaction(Archive *AHX)

void IssueCommandPerBlob(ArchiveHandle *AH, TocEntry *te, const char *cmdBegin, const char *cmdEnd)

int ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)

static void ExecuteSqlCommand(ArchiveHandle *AH, const char *qry, const char *desc)

static void notice_processor(void *arg, const char *message)

void DisconnectDatabase(Archive *AHX)

void CommitTransaction(Archive *AHX)

#define pg_log_warning(...)

PQExpBuffer createPQExpBuffer(void)

void resetPQExpBuffer(PQExpBuffer str)

void appendPQExpBufferChar(PQExpBuffer str, char ch)

char * simple_prompt(const char *prompt, bool echo)

PGcancel *volatile connCancel

ArchiverOutput outputKind

char * archiveRemoteVersion