* Collect any database-specific or role-and-database-specific SET options * for this database, and append them to outbuf. */
| 3708 | * for this database, and append them to outbuf. |
| 3709 | */ |
| 3710 | static void |
| 3711 | dumpDatabaseConfig(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), |
no test coverage detected