63 #include "utils/fmgroids.h" 82 static void movedb(
const char *
dbname,
const char *tblspcname);
86 int *encodingP,
bool *dbIsTemplateP,
bool *dbAllowConnP,
89 Oid *dbTablespace,
char **dbCollate,
char **dbCtype);
106 int src_encoding = -1;
107 char *src_collate = NULL;
108 char *src_ctype = NULL;
114 Oid src_deftablespace;
115 volatile Oid dst_deftablespace;
118 Datum new_record[Natts_pg_database];
119 bool new_record_nulls[Natts_pg_database];
123 DefElem *dtablespacename = NULL;
131 DefElem *dallowconnections = NULL;
134 char *dbowner = NULL;
135 const char *dbtemplate = NULL;
136 char *dbcollate = NULL;
137 char *dbctype = NULL;
140 bool dbistemplate =
false;
141 bool dballowconnections =
true;
142 int dbconnlimit = -1;
152 if (strcmp(defel->
defname,
"tablespace") == 0)
156 (
errcode(ERRCODE_SYNTAX_ERROR),
157 errmsg(
"conflicting or redundant options"),
159 dtablespacename = defel;
161 else if (strcmp(defel->
defname,
"owner") == 0)
165 (
errcode(ERRCODE_SYNTAX_ERROR),
166 errmsg(
"conflicting or redundant options"),
170 else if (strcmp(defel->
defname,
"template") == 0)
174 (
errcode(ERRCODE_SYNTAX_ERROR),
175 errmsg(
"conflicting or redundant options"),
179 else if (strcmp(defel->
defname,
"encoding") == 0)
183 (
errcode(ERRCODE_SYNTAX_ERROR),
184 errmsg(
"conflicting or redundant options"),
188 else if (strcmp(defel->
defname,
"locale") == 0)
192 (
errcode(ERRCODE_SYNTAX_ERROR),
193 errmsg(
"conflicting or redundant options"),
197 else if (strcmp(defel->
defname,
"lc_collate") == 0)
201 (
errcode(ERRCODE_SYNTAX_ERROR),
202 errmsg(
"conflicting or redundant options"),
206 else if (strcmp(defel->
defname,
"lc_ctype") == 0)
210 (
errcode(ERRCODE_SYNTAX_ERROR),
211 errmsg(
"conflicting or redundant options"),
215 else if (strcmp(defel->
defname,
"is_template") == 0)
219 (
errcode(ERRCODE_SYNTAX_ERROR),
220 errmsg(
"conflicting or redundant options"),
224 else if (strcmp(defel->
defname,
"allow_connections") == 0)
226 if (dallowconnections)
228 (
errcode(ERRCODE_SYNTAX_ERROR),
229 errmsg(
"conflicting or redundant options"),
231 dallowconnections = defel;
233 else if (strcmp(defel->
defname,
"connection_limit") == 0)
237 (
errcode(ERRCODE_SYNTAX_ERROR),
238 errmsg(
"conflicting or redundant options"),
242 else if (strcmp(defel->
defname,
"location") == 0)
245 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
246 errmsg(
"LOCATION is not supported anymore"),
247 errhint(
"Consider using tablespaces instead."),
252 (
errcode(ERRCODE_SYNTAX_ERROR),
257 if (dlocale && (dcollate || dctype))
259 (
errcode(ERRCODE_SYNTAX_ERROR),
260 errmsg(
"conflicting or redundant options"),
261 errdetail(
"LOCALE cannot be specified together with LC_COLLATE or LC_CTYPE.")));
263 if (downer && downer->
arg)
265 if (dtemplate && dtemplate->
arg)
267 if (dencoding && dencoding->
arg)
269 const char *encoding_name;
271 if (
IsA(dencoding->
arg, Integer))
275 if (strcmp(encoding_name,
"") == 0 ||
278 (
errcode(ERRCODE_UNDEFINED_OBJECT),
279 errmsg(
"%d is not a valid encoding code",
289 (
errcode(ERRCODE_UNDEFINED_OBJECT),
290 errmsg(
"%s is not a valid encoding name",
295 if (dlocale && dlocale->
arg)
300 if (dcollate && dcollate->
arg)
302 if (dctype && dctype->
arg)
304 if (distemplate && distemplate->
arg)
306 if (dallowconnections && dallowconnections->
arg)
308 if (dconnlimit && dconnlimit->
arg)
311 if (dbconnlimit < -1)
313 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
314 errmsg(
"invalid connection limit: %d", dbconnlimit)));
332 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
333 errmsg(
"permission denied to create database")));
347 dbtemplate =
"template1";
350 &src_dboid, &src_owner, &src_encoding,
351 &src_istemplate, &src_allowconn, &src_lastsysoid,
352 &src_frozenxid, &src_minmxid, &src_deftablespace,
353 &src_collate, &src_ctype))
355 (
errcode(ERRCODE_UNDEFINED_DATABASE),
356 errmsg(
"template database \"%s\" does not exist",
367 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
368 errmsg(
"permission denied to copy database \"%s\"",
374 encoding = src_encoding;
375 if (dbcollate == NULL)
376 dbcollate = src_collate;
383 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
384 errmsg(
"invalid server encoding %d", encoding)));
389 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
390 errmsg(
"invalid locale name: \"%s\"", dbcollate)));
391 dbcollate = canonname;
394 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
395 errmsg(
"invalid locale name: \"%s\"", dbctype)));
410 if (strcmp(dbtemplate,
"template0") != 0)
412 if (encoding != src_encoding)
414 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
415 errmsg(
"new encoding (%s) is incompatible with the encoding of the template database (%s)",
418 errhint(
"Use the same encoding as in the template database, or use template0 as template.")));
420 if (strcmp(dbcollate, src_collate) != 0)
422 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
423 errmsg(
"new collation (%s) is incompatible with the collation of the template database (%s)",
424 dbcollate, src_collate),
425 errhint(
"Use the same collation as in the template database, or use template0 as template.")));
427 if (strcmp(dbctype, src_ctype) != 0)
429 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
430 errmsg(
"new LC_CTYPE (%s) is incompatible with the LC_CTYPE of the template database (%s)",
432 errhint(
"Use the same LC_CTYPE as in the template database, or use template0 as template.")));
436 if (dtablespacename && dtablespacename->
arg)
438 char *tablespacename;
451 if (dst_deftablespace == GLOBALTABLESPACE_OID)
453 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
454 errmsg(
"pg_global cannot be used as default tablespace")));
468 if (dst_deftablespace != src_deftablespace)
475 if (
stat(srcpath, &st) == 0 &&
479 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
480 errmsg(
"cannot assign new default tablespace \"%s\"",
482 errdetail(
"There is a conflict because database \"%s\" already has some tables in this tablespace.",
490 dst_deftablespace = src_deftablespace;
499 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS 501 elog(
WARNING,
"databases created by regression test cases should have names including \"regression\"");
511 (
errcode(ERRCODE_DUPLICATE_DATABASE),
512 errmsg(
"database \"%s\" already exists", dbname)));
525 (
errcode(ERRCODE_OBJECT_IN_USE),
526 errmsg(
"source database \"%s\" is being accessed by other users",
540 Anum_pg_database_oid);
550 MemSet(new_record, 0,
sizeof(new_record));
551 MemSet(new_record_nulls,
false,
sizeof(new_record_nulls));
554 new_record[Anum_pg_database_datname - 1] =
557 new_record[Anum_pg_database_encoding - 1] =
Int32GetDatum(encoding);
558 new_record[Anum_pg_database_datcollate - 1] =
560 new_record[Anum_pg_database_datctype - 1] =
562 new_record[Anum_pg_database_datistemplate - 1] =
BoolGetDatum(dbistemplate);
563 new_record[Anum_pg_database_datallowconn - 1] =
BoolGetDatum(dballowconnections);
564 new_record[Anum_pg_database_datconnlimit - 1] =
Int32GetDatum(dbconnlimit);
565 new_record[Anum_pg_database_datlastsysoid - 1] =
ObjectIdGetDatum(src_lastsysoid);
568 new_record[Anum_pg_database_dattablespace - 1] =
ObjectIdGetDatum(dst_deftablespace);
575 new_record_nulls[Anum_pg_database_datacl - 1] =
true;
578 new_record, new_record_nulls);
629 Oid srctablespace = spaceform->oid;
636 if (srctablespace == GLOBALTABLESPACE_OID)
649 if (srctablespace == src_deftablespace)
650 dsttablespace = dst_deftablespace;
652 dsttablespace = srctablespace;
661 copydir(srcpath, dstpath,
false);
760 if (!(ctype_encoding == encoding ||
762 ctype_encoding == -1 ||
768 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
769 errmsg(
"encoding \"%s\" does not match locale \"%s\"",
772 errdetail(
"The chosen LC_CTYPE setting requires encoding \"%s\".",
775 if (!(collate_encoding == encoding ||
777 collate_encoding == -1 ||
783 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
784 errmsg(
"encoding \"%s\" does not match locale \"%s\"",
787 errdetail(
"The chosen LC_COLLATE setting requires encoding \"%s\".",
835 &db_istemplate, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
840 (
errcode(ERRCODE_UNDEFINED_DATABASE),
841 errmsg(
"database \"%s\" does not exist", dbname)));
848 (
errmsg(
"database \"%s\" does not exist, skipping",
871 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
872 errmsg(
"cannot drop a template database")));
877 (
errcode(ERRCODE_OBJECT_IN_USE),
878 errmsg(
"cannot drop the currently open database")));
890 (
errcode(ERRCODE_OBJECT_IN_USE),
891 errmsg(
"database \"%s\" is used by an active logical replication slot",
894 "There are %d active slots.",
895 nslots_active, nslots_active)));
906 (
errcode(ERRCODE_OBJECT_IN_USE),
907 errmsg(
"database \"%s\" is being used by logical replication subscription",
910 "There are %d subscriptions.",
911 nsubscriptions, nsubscriptions)));
929 (
errcode(ERRCODE_OBJECT_IN_USE),
930 errmsg(
"database \"%s\" is being accessed by other users",
939 elog(
ERROR,
"cache lookup failed for database %u", db_id);
1034 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL))
1036 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1037 errmsg(
"database \"%s\" does not exist", oldname)));
1047 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1048 errmsg(
"permission denied to rename database")));
1054 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS 1055 if (strstr(newname,
"regression") == NULL)
1056 elog(
WARNING,
"databases created by regression test cases should have names including \"regression\"");
1065 (
errcode(ERRCODE_DUPLICATE_DATABASE),
1066 errmsg(
"database \"%s\" already exists", newname)));
1076 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1077 errmsg(
"current database cannot be renamed")));
1087 (
errcode(ERRCODE_OBJECT_IN_USE),
1088 errmsg(
"database \"%s\" is being accessed by other users",
1095 elog(
ERROR,
"cache lookup failed for database %u", db_id);
1126 Datum new_record[Natts_pg_database];
1127 bool new_record_nulls[Natts_pg_database];
1128 bool new_record_repl[Natts_pg_database];
1147 NULL, NULL, NULL, NULL, NULL, &src_tblspcoid, NULL, NULL))
1149 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1150 errmsg(
"database \"%s\" does not exist", dbname)));
1173 (
errcode(ERRCODE_OBJECT_IN_USE),
1174 errmsg(
"cannot change the tablespace of the currently open database")));
1193 if (dst_tblspcoid == GLOBALTABLESPACE_OID)
1195 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1196 errmsg(
"pg_global cannot be used as default tablespace")));
1201 if (src_tblspcoid == dst_tblspcoid)
1217 (
errcode(ERRCODE_OBJECT_IN_USE),
1218 errmsg(
"database \"%s\" is being accessed by other users",
1269 while ((xlde =
ReadDir(dstdir, dst_dbpath)) != NULL)
1271 if (strcmp(xlde->
d_name,
".") == 0 ||
1272 strcmp(xlde->
d_name,
"..") == 0)
1276 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1277 errmsg(
"some relations of database \"%s\" are already in tablespace \"%s\"",
1278 dbname, tblspcname),
1279 errhint(
"You must move them back to the database's default tablespace before using this command.")));
1288 if (rmdir(dst_dbpath) != 0)
1289 elog(
ERROR,
"could not remove directory \"%s\": %m",
1307 copydir(src_dbpath, dst_dbpath,
false);
1315 xlrec.
db_id = db_id;
1331 Anum_pg_database_datname,
1339 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1340 errmsg(
"database \"%s\" does not exist", dbname)));
1342 MemSet(new_record, 0,
sizeof(new_record));
1343 MemSet(new_record_nulls,
false,
sizeof(new_record_nulls));
1344 MemSet(new_record_repl,
false,
sizeof(new_record_repl));
1346 new_record[Anum_pg_database_dattablespace - 1] =
ObjectIdGetDatum(dst_tblspcoid);
1347 new_record_repl[Anum_pg_database_dattablespace - 1] =
true;
1351 new_record_nulls, new_record_repl);
1402 if (!
rmtree(src_dbpath,
true))
1404 (
errmsg(
"some useless files may be left behind in old database directory \"%s\"",
1413 xlrec.
db_id = db_id;
1439 (void)
rmtree(dstpath,
true);
1455 if (strcmp(opt->
defname,
"force") == 0)
1459 (
errcode(ERRCODE_SYNTAX_ERROR),
1460 errmsg(
"unrecognized DROP DATABASE option \"%s\"", opt->
defname),
1481 bool dbistemplate =
false;
1482 bool dballowconnections =
true;
1483 int dbconnlimit = -1;
1485 DefElem *dallowconnections = NULL;
1488 Datum new_record[Natts_pg_database];
1489 bool new_record_nulls[Natts_pg_database];
1490 bool new_record_repl[Natts_pg_database];
1493 foreach(option, stmt->
options)
1497 if (strcmp(defel->
defname,
"is_template") == 0)
1501 (
errcode(ERRCODE_SYNTAX_ERROR),
1502 errmsg(
"conflicting or redundant options"),
1504 distemplate = defel;
1506 else if (strcmp(defel->
defname,
"allow_connections") == 0)
1508 if (dallowconnections)
1510 (
errcode(ERRCODE_SYNTAX_ERROR),
1511 errmsg(
"conflicting or redundant options"),
1513 dallowconnections = defel;
1515 else if (strcmp(defel->
defname,
"connection_limit") == 0)
1519 (
errcode(ERRCODE_SYNTAX_ERROR),
1520 errmsg(
"conflicting or redundant options"),
1524 else if (strcmp(defel->
defname,
"tablespace") == 0)
1528 (
errcode(ERRCODE_SYNTAX_ERROR),
1529 errmsg(
"conflicting or redundant options"),
1531 dtablespace = defel;
1535 (
errcode(ERRCODE_SYNTAX_ERROR),
1549 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1550 errmsg(
"option \"%s\" cannot be specified with other options",
1559 if (distemplate && distemplate->
arg)
1561 if (dallowconnections && dallowconnections->
arg)
1563 if (dconnlimit && dconnlimit->
arg)
1566 if (dbconnlimit < -1)
1568 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1569 errmsg(
"invalid connection limit: %d", dbconnlimit)));
1579 Anum_pg_database_datname,
1587 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1588 errmsg(
"database \"%s\" does not exist", stmt->
dbname)));
1591 dboid = datform->oid;
1605 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1606 errmsg(
"cannot disallow connections for current database")));
1611 MemSet(new_record, 0,
sizeof(new_record));
1612 MemSet(new_record_nulls,
false,
sizeof(new_record_nulls));
1613 MemSet(new_record_repl,
false,
sizeof(new_record_repl));
1617 new_record[Anum_pg_database_datistemplate - 1] =
BoolGetDatum(dbistemplate);
1618 new_record_repl[Anum_pg_database_datistemplate - 1] =
true;
1620 if (dallowconnections)
1622 new_record[Anum_pg_database_datallowconn - 1] =
BoolGetDatum(dballowconnections);
1623 new_record_repl[Anum_pg_database_datallowconn - 1] =
true;
1627 new_record[Anum_pg_database_datconnlimit - 1] =
Int32GetDatum(dbconnlimit);
1628 new_record_repl[Anum_pg_database_datconnlimit - 1] =
true;
1632 new_record_nulls, new_record_repl);
1693 Anum_pg_database_datname,
1701 (
errcode(ERRCODE_UNDEFINED_DATABASE),
1702 errmsg(
"database \"%s\" does not exist", dbname)));
1705 db_id = datForm->oid;
1712 if (datForm->datdba != newOwnerId)
1714 Datum repl_val[Natts_pg_database];
1715 bool repl_null[Natts_pg_database];
1716 bool repl_repl[Natts_pg_database];
1741 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1742 errmsg(
"permission denied to change owner of database")));
1744 memset(repl_null,
false,
sizeof(repl_null));
1745 memset(repl_repl,
false,
sizeof(repl_repl));
1747 repl_repl[Anum_pg_database_datdba - 1] =
true;
1755 Anum_pg_database_datacl,
1761 datForm->datdba, newOwnerId);
1762 repl_repl[Anum_pg_database_datacl - 1] =
true;
1800 Oid *dbIdP,
Oid *ownerIdP,
1801 int *encodingP,
bool *dbIsTemplateP,
bool *dbAllowConnP,
1804 Oid *dbTablespace,
char **dbCollate,
char **dbCtype)
1806 bool result =
false;
1831 Anum_pg_database_datname,
1867 if (strcmp(name,
NameStr(dbform->datname)) == 0)
1874 *ownerIdP = dbform->datdba;
1877 *encodingP = dbform->encoding;
1880 *dbIsTemplateP = dbform->datistemplate;
1883 *dbAllowConnP = dbform->datallowconn;
1886 *dbLastSysOidP = dbform->datlastsysoid;
1889 *dbFrozenXidP = dbform->datfrozenxid;
1892 *dbMinMultiP = dbform->datminmxid;
1895 *dbTablespace = dbform->dattablespace;
1922 bool result =
false;
1954 Oid *tablespace_ids;
1961 Oid dsttablespace = spcform->oid;
1966 if (dsttablespace == GLOBALTABLESPACE_OID)
1978 if (!
rmtree(dstpath,
true))
1980 (
errmsg(
"some useless files may be left behind in old database directory \"%s\"",
1995 tablespace_ids = (
Oid *)
palloc(ntblspc *
sizeof(
Oid));
1997 foreach(cell, ltblspc)
2004 xlrec.
db_id = db_id;
2016 pfree(tablespace_ids);
2037 bool result =
false;
2047 Oid dsttablespace = spcform->oid;
2052 if (dsttablespace == GLOBALTABLESPACE_OID)
2057 if (
lstat(dstpath, &st) == 0)
2080 if (notherbackends > 0 && npreparedxacts > 0)
2086 errdetail(
"There are %d other session(s) and %d prepared transaction(s) using the database.",
2087 notherbackends, npreparedxacts);
2088 else if (notherbackends > 0)
2090 "There are %d other sessions using the database.",
2095 "There are %d prepared transactions using the database.",
2122 Anum_pg_database_datname,
2141 (
errcode(ERRCODE_UNDEFINED_DATABASE),
2142 errmsg(
"database \"%s\" does not exist",
2200 if (!
rmtree(dst_path,
true))
2203 (
errmsg(
"some useless files may be left behind in old database directory \"%s\"",
2218 copydir(src_path, dst_path,
false);
2259 if (!
rmtree(dst_path,
true))
2261 (
errmsg(
"some useless files may be left behind in old database directory \"%s\"",
2279 elog(
PANIC,
"dbase_redo: unknown op code %u", info);
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
#define IsA(nodeptr, _type_)
AclResult pg_tablespace_aclcheck(Oid spc_oid, Oid roleid, AclMode mode)
Datum namein(PG_FUNCTION_ARGS)
#define CHECKPOINT_FLUSH_ALL
void table_close(Relation relation, LOCKMODE lockmode)
int errhint(const char *fmt,...)
void systable_endscan(SysScanDesc sysscan)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define XLR_SPECIAL_REL_UPDATE
void check_encoding_locale_matches(int encoding, const char *collate, const char *ctype)
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
#define MinSizeOfDbaseDropRec
#define RelationGetDescr(relation)
void namestrcpy(Name name, const char *str)
FormData_pg_database * Form_pg_database
int pg_valid_server_encoding(const char *name)
#define PointerGetDatum(X)
static bool have_createdb_privilege(void)
char * pstrdup(const char *in)
void CommitTransactionCommand(void)
static void createdb_failure_callback(int code, Datum arg)
void AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
#define InvokeObjectDropHook(classId, objectId, subId)
int CountDBSubscriptions(Oid dbid)
bool check_locale(int category, const char *locale, char **canonname)
void ForceSyncCommit(void)
int32 defGetInt32(DefElem *def)
int errcode(int sqlerrcode)
#define MemSet(start, val, len)
void copydir(char *fromdir, char *todir, bool recurse)
static void remove_dbtablespaces(Oid db_id)
bool directory_is_empty(const char *path)
#define DatabaseNameIndexId
void PopActiveSnapshot(void)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
#define DirectFunctionCall1(func, arg1)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
void heap_freetuple(HeapTuple htup)
static bool get_db_info(const char *name, LOCKMODE lockmode, Oid *dbIdP, Oid *ownerIdP, int *encodingP, bool *dbIsTemplateP, bool *dbAllowConnP, Oid *dbLastSysOidP, TransactionId *dbFrozenXidP, MultiXactId *dbMinMultiP, Oid *dbTablespace, char **dbCollate, char **dbCtype)
List * lappend_oid(List *list, Oid datum)
#define OidIsValid(objectId)
static void movedb_failure_callback(int code, Datum arg)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
VariableSetStmt * setstmt
void dbase_redo(XLogReaderState *record)
ObjectAddress RenameDatabase(const char *oldname, const char *newname)
void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Oid get_role_oid(const char *rolname, bool missing_ok)
void dropdb(const char *dbname, bool missing_ok, bool force)
FormData_pg_authid * Form_pg_authid
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
#define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
bool defGetBoolean(DefElem *def)
HeapTuple systable_getnext(SysScanDesc sysscan)
void pfree(void *pointer)
#define XLogRecGetData(decoder)
#define ObjectIdGetDatum(X)
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
char * defGetString(DefElem *def)
static bool check_db_file_conflict(Oid db_id)
void shdepLockAndCheckObject(Oid classId, Oid objectId)
char * get_database_name(Oid dbid)
void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
void FlushDatabaseBuffers(Oid dbid)
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
int errdetail(const char *fmt,...)
#define CStringGetDatum(X)
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
#define InvalidTransactionId
FormData_pg_tablespace * Form_pg_tablespace
DIR * AllocateDir(const char *dirname)
void check_is_member_of_role(Oid member, Oid role)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define AssertArg(condition)
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
#define XLogRecGetInfo(decoder)
static char dstpath[MAXPGPATH]
char * GetDatabasePath(Oid dbNode, Oid spcNode)
void copyTemplateDependencies(Oid templateDbId, Oid newDbId)
void pgstat_drop_database(Oid databaseid)
#define DatabaseOidIndexId
void dropDatabaseDependencies(Oid databaseId)
#define heap_getattr(tup, attnum, tupleDesc, isnull)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
bool rmtree(const char *path, bool rmtopdir)
void XLogRegisterData(char *data, int len)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
#define TransactionIdGetDatum(X)
void ReleaseSysCache(HeapTuple tuple)
#define InvalidMultiXactId
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Oid get_database_oid(const char *dbname, bool missing_ok)
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
#define ereport(elevel,...)
void ForgetDatabaseSyncRequests(Oid dbid)
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
void ResolveRecoveryConflictWithDatabase(Oid dbid)
const char * pg_encoding_to_char(int encoding)
TransactionId MultiXactId
#define PG_VALID_BE_ENCODING(_enc)
#define HeapTupleIsValid(tuple)
#define Assert(condition)
struct dirent * ReadDir(DIR *dir, const char *dirname)
static void movedb(const char *dbname, const char *tblspcname)
void StartTransactionCommand(void)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
static int list_length(const List *l)
int parser_errposition(ParseState *pstate, int location)
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
#define XLOG_DBASE_CREATE
#define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
#define ObjectAddressSet(addr, class_id, object_id)
bool ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive)
Oid tablespace_ids[FLEXIBLE_ARRAY_MEMBER]
#define DatumGetPointer(X)
void DeleteSharedSecurityLabel(Oid objectId, Oid classId)
static void table_endscan(TableScanDesc scan)
#define SearchSysCacheCopy1(cacheId, key1)
#define AccessExclusiveLock
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
int errmsg(const char *fmt,...)
void XLogDropDatabase(Oid dbid)
void list_free(List *list)
#define CHECKPOINT_IMMEDIATE
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
#define XLogRecHasAnyBlockRefs(decoder)
void TerminateOtherDBBackends(Oid databaseId)
bool CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared)
static int errdetail_busy_db(int notherbackends, int npreparedxacts)
Relation table_open(Oid relationId, LOCKMODE lockmode)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
void DropSetting(Oid databaseid, Oid roleid)
void XLogBeginInsert(void)
void DropDatabaseBuffers(Oid dbid)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void ReplicationSlotsDropDBSlots(Oid dboid)
void DropDatabase(ParseState *pstate, DropdbStmt *stmt)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
#define BTEqualStrategyNumber
void RequestCheckpoint(int flags)