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

Function dumpUserConfig

src/bin/pg_dump/pg_dumpall.c:1929–1980  ·  view source on GitHub ↗

* Dump user-specific configuration */

Source from the content-addressed store, hash-verified

1927 * Dump user-specific configuration
1928 */
1929static void
1930dumpUserConfig(PGconn *conn, const char *username)
1931{
1932 PQExpBuffer buf = createPQExpBuffer();
1933 int count = 1;
1934 bool first = true;
1935
1936 for (;;)
1937 {
1938 PGresult *res;
1939
1940 if (server_version >= 90000)
1941 printfPQExpBuffer(buf, "SELECT setconfig[%d] FROM pg_db_role_setting WHERE "
1942 "setdatabase = 0 AND setrole = "
1943 "(SELECT oid FROM %s WHERE rolname = ", count, role_catalog);
1944 else if (server_version >= 80100)
1945 printfPQExpBuffer(buf, "SELECT rolconfig[%d] FROM %s WHERE rolname = ", count, role_catalog);
1946 else
1947 printfPQExpBuffer(buf, "SELECT useconfig[%d] FROM pg_shadow WHERE usename = ", count);
1948 appendStringLiteralConn(buf, username, conn);
1949 if (server_version >= 90000)
1950 appendPQExpBufferChar(buf, ')');
1951
1952 res = executeQuery(conn, buf->data);
1953 if (PQntuples(res) == 1 &&
1954 !PQgetisnull(res, 0, 0))
1955 {
1956 /* comment at section start, only if needed */
1957 if (first)
1958 {
1959 fprintf(OPF, "--\n-- User Configurations\n--\n\n");
1960 first = false;
1961 }
1962
1963 fprintf(OPF, "--\n-- User Config \"%s\"\n--\n\n", username);
1964 resetPQExpBuffer(buf);
1965 makeAlterConfigCommand(conn, PQgetvalue(res, 0, 0),
1966 "ROLE", username, NULL, NULL,
1967 buf);
1968 fprintf(OPF, "%s", buf->data);
1969 PQclear(res);
1970 count++;
1971 }
1972 else
1973 {
1974 PQclear(res);
1975 break;
1976 }
1977 }
1978
1979 destroyPQExpBuffer(buf);
1980}
1981
1982/*
1983 * Dump profiles

Callers 1

dumpRolesFunction · 0.85

Calls 12

createPQExpBufferFunction · 0.85
printfPQExpBufferFunction · 0.85
appendStringLiteralConnFunction · 0.85
appendPQExpBufferCharFunction · 0.85
PQntuplesFunction · 0.85
PQgetisnullFunction · 0.85
resetPQExpBufferFunction · 0.85
makeAlterConfigCommandFunction · 0.85
PQgetvalueFunction · 0.85
PQclearFunction · 0.85
destroyPQExpBufferFunction · 0.85
executeQueryFunction · 0.70

Tested by

no test coverage detected