MCPcopy Create free account
hub / github.com/apache/cloudberry / dumpDatabaseConfig

Function dumpDatabaseConfig

src/bin/pg_dump/pg_dump.c:3710–3785  ·  view source on GitHub ↗

* Collect any database-specific or role-and-database-specific SET options * for this database, and append them to outbuf. */

Source from the content-addressed store, hash-verified

3708 * for this database, and append them to outbuf.
3709 */
3710static void
3711dumpDatabaseConfig(Archive *AH, PQExpBuffer outbuf,
3712 const char *dbname, Oid dboid)
3713{
3714 PGconn *conn = GetConnection(AH);
3715 PQExpBuffer buf = createPQExpBuffer();
3716 PGresult *res;
3717 int count = 1;
3718
3719 /*
3720 * First collect database-specific options. Pre-8.4 server versions lack
3721 * unnest(), so we do this the hard way by querying once per subscript.
3722 */
3723 for (;;)
3724 {
3725 if (AH->remoteVersion >= 90000)
3726 printfPQExpBuffer(buf, "SELECT setconfig[%d] FROM pg_db_role_setting "
3727 "WHERE setrole = 0 AND setdatabase = '%u'::oid",
3728 count, dboid);
3729 else
3730 printfPQExpBuffer(buf, "SELECT datconfig[%d] FROM pg_database WHERE oid = '%u'::oid", count, dboid);
3731
3732 res = ExecuteSqlQuery(AH, buf->data, PGRES_TUPLES_OK);
3733
3734 if (PQntuples(res) == 1 &&
3735 !PQgetisnull(res, 0, 0))
3736 {
3737 makeAlterConfigCommand(conn, PQgetvalue(res, 0, 0),
3738 "DATABASE", dbname, NULL, NULL,
3739 outbuf);
3740 PQclear(res);
3741 count++;
3742 }
3743 else
3744 {
3745 PQclear(res);
3746 break;
3747 }
3748 }
3749
3750 /* Now look for role-and-database-specific options */
3751 if (AH->remoteVersion >= 90000)
3752 {
3753 /* Here we can assume we have unnest() */
3754 printfPQExpBuffer(buf, "SELECT rolname, unnest(setconfig) "
3755 "FROM pg_db_role_setting s, pg_roles r "
3756 "WHERE setrole = r.oid AND setdatabase = '%u'::oid",
3757 dboid);
3758
3759 res = ExecuteSqlQuery(AH, buf->data, PGRES_TUPLES_OK);
3760
3761 if (PQntuples(res) > 0)
3762 {
3763 int i;
3764
3765 for (i = 0; i < PQntuples(res); i++)
3766 makeAlterConfigCommand(conn, PQgetvalue(res, i, 1),
3767 "ROLE", PQgetvalue(res, i, 0),

Callers 1

dumpDatabaseFunction · 0.85

Calls 10

createPQExpBufferFunction · 0.85
printfPQExpBufferFunction · 0.85
ExecuteSqlQueryFunction · 0.85
PQntuplesFunction · 0.85
PQgetisnullFunction · 0.85
makeAlterConfigCommandFunction · 0.85
PQgetvalueFunction · 0.85
PQclearFunction · 0.85
destroyPQExpBufferFunction · 0.85
GetConnectionFunction · 0.70

Tested by

no test coverage detected