- Relation pg_database;
- ScanKeyData entry[1];
- HeapScanDesc scan;
- HeapTuple dbtuple;
- int32 dba;
-
- /* There's no syscache for pg_database, so must look the hard way */
- pg_database = heap_openr(DatabaseRelationName, AccessShareLock);
- ScanKeyEntryInitialize(&entry[0], 0x0,
- ObjectIdAttributeNumber, F_OIDEQ,
- ObjectIdGetDatum(dbid));
- scan = heap_beginscan(pg_database, 0, SnapshotNow, 1, entry);
- dbtuple = heap_getnext(scan, 0);
- if (!HeapTupleIsValid(dbtuple))
- elog(ERROR, "database %u does not exist", dbid);
- dba = ((Form_pg_database) GETSTRUCT(dbtuple))->datdba;
- heap_endscan(scan);
- heap_close(pg_database, AccessShareLock);
-
- /* XXX some confusion about whether userids are OID or int4 ... */
- return (GetUserId() == (Oid) dba);