15
15
*
16
16
*
17
17
* IDENTIFICATION
18
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.153 2005/03/12 21:11:50 tgl Exp $
18
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.154 2005/03/12 21:33:55 tgl Exp $
19
19
*
20
20
*-------------------------------------------------------------------------
21
21
*/
54
54
55
55
/* non-export function prototypes */
56
56
static bool get_db_info (const char * name , Oid * dbIdP , int4 * ownerIdP ,
57
- int * encodingP , bool * dbIsTemplateP , Oid * dbLastSysOidP ,
57
+ int * encodingP , bool * dbIsTemplateP , bool * dbAllowConnP ,
58
+ Oid * dbLastSysOidP ,
58
59
TransactionId * dbVacuumXidP , TransactionId * dbFrozenXidP ,
59
60
Oid * dbTablespace );
60
61
static bool have_createdb_privilege (void );
@@ -73,6 +74,7 @@ createdb(const CreatedbStmt *stmt)
73
74
AclId src_owner ;
74
75
int src_encoding ;
75
76
bool src_istemplate ;
77
+ bool src_allowconn ;
76
78
Oid src_lastsysoid ;
77
79
TransactionId src_vacuumxid ;
78
80
TransactionId src_frozenxid ;
@@ -217,7 +219,8 @@ createdb(const CreatedbStmt *stmt)
217
219
* idea, so accept possibility of race to create. We will check again
218
220
* after we grab the exclusive lock.
219
221
*/
220
- if (get_db_info (dbname , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL ))
222
+ if (get_db_info (dbname , NULL , NULL , NULL ,
223
+ NULL , NULL , NULL , NULL , NULL , NULL ))
221
224
ereport (ERROR ,
222
225
(errcode (ERRCODE_DUPLICATE_DATABASE ),
223
226
errmsg ("database \"%s\" already exists" , dbname )));
@@ -229,7 +232,7 @@ createdb(const CreatedbStmt *stmt)
229
232
dbtemplate = "template1" ; /* Default template database name */
230
233
231
234
if (!get_db_info (dbtemplate , & src_dboid , & src_owner , & src_encoding ,
232
- & src_istemplate , & src_lastsysoid ,
235
+ & src_istemplate , & src_allowconn , & src_lastsysoid ,
233
236
& src_vacuumxid , & src_frozenxid , & src_deftablespace ))
234
237
ereport (ERROR ,
235
238
(errcode (ERRCODE_UNDEFINED_DATABASE ),
@@ -328,6 +331,16 @@ createdb(const CreatedbStmt *stmt)
328
331
/* Note there is no additional permission check in this path */
329
332
}
330
333
334
+ /*
335
+ * Normally we mark the new database with the same datvacuumxid and
336
+ * datfrozenxid as the source. However, if the source is not allowing
337
+ * connections then we assume it is fully frozen, and we can set the
338
+ * current transaction ID as the xid limits. This avoids immediately
339
+ * starting to generate warnings after cloning template0.
340
+ */
341
+ if (!src_allowconn )
342
+ src_vacuumxid = src_frozenxid = GetCurrentTransactionId ();
343
+
331
344
/*
332
345
* Preassign OID for pg_database tuple, so that we can compute db
333
346
* path.
@@ -455,7 +468,8 @@ createdb(const CreatedbStmt *stmt)
455
468
pg_database_rel = heap_openr (DatabaseRelationName , ExclusiveLock );
456
469
457
470
/* Check to see if someone else created same DB name meanwhile. */
458
- if (get_db_info (dbname , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL ))
471
+ if (get_db_info (dbname , NULL , NULL , NULL ,
472
+ NULL , NULL , NULL , NULL , NULL , NULL ))
459
473
{
460
474
/* Don't hold lock while doing recursive remove */
461
475
heap_close (pg_database_rel , ExclusiveLock );
@@ -552,7 +566,7 @@ dropdb(const char *dbname)
552
566
pgdbrel = heap_openr (DatabaseRelationName , ExclusiveLock );
553
567
554
568
if (!get_db_info (dbname , & db_id , & db_owner , NULL ,
555
- & db_istemplate , NULL , NULL , NULL , NULL ))
569
+ & db_istemplate , NULL , NULL , NULL , NULL , NULL ))
556
570
ereport (ERROR ,
557
571
(errcode (ERRCODE_UNDEFINED_DATABASE ),
558
572
errmsg ("database \"%s\" does not exist" , dbname )));
@@ -936,7 +950,8 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
936
950
937
951
static bool
938
952
get_db_info (const char * name , Oid * dbIdP , int4 * ownerIdP ,
939
- int * encodingP , bool * dbIsTemplateP , Oid * dbLastSysOidP ,
953
+ int * encodingP , bool * dbIsTemplateP , bool * dbAllowConnP ,
954
+ Oid * dbLastSysOidP ,
940
955
TransactionId * dbVacuumXidP , TransactionId * dbFrozenXidP ,
941
956
Oid * dbTablespace )
942
957
{
@@ -978,6 +993,9 @@ get_db_info(const char *name, Oid *dbIdP, int4 *ownerIdP,
978
993
/* allowed as template? */
979
994
if (dbIsTemplateP )
980
995
* dbIsTemplateP = dbform -> datistemplate ;
996
+ /* allowing connections? */
997
+ if (dbAllowConnP )
998
+ * dbAllowConnP = dbform -> datallowconn ;
981
999
/* last system OID used in database */
982
1000
if (dbLastSysOidP )
983
1001
* dbLastSysOidP = dbform -> datlastsysoid ;
0 commit comments