9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.146 2004/10/28 00:39:58 tgl Exp $
12
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.147 2004/11/18 01:14:26 tgl Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -330,7 +330,7 @@ createdb(const CreatedbStmt *stmt)
330
330
/*
331
331
* Force dirty buffers out to disk, to ensure source database is
332
332
* up-to-date for the copy. (We really only need to flush buffers for
333
- * the source database.. .)
333
+ * the source database, but bufmgr.c provides no API for that .)
334
334
*/
335
335
BufferSync (-1 ,-1 );
336
336
@@ -497,15 +497,15 @@ createdb(const CreatedbStmt *stmt)
497
497
/* Update indexes */
498
498
CatalogUpdateIndexes (pg_database_rel ,tuple );
499
499
500
- /* Close pg_database, but keep lock till commit */
501
- heap_close (pg_database_rel ,NoLock );
502
-
503
500
/*
504
501
* Force dirty buffers out to disk, so that newly-connecting backends
505
502
* will see the new database in pg_database right away. (They'll see
506
503
* an uncommitted tuple, but they don't care; see GetRawDatabaseInfo.)
507
504
*/
508
- BufferSync (-1 ,-1 );
505
+ FlushRelationBuffers (pg_database_rel ,MaxBlockNumber );
506
+
507
+ /* Close pg_database, but keep exclusive lock till commit */
508
+ heap_close (pg_database_rel ,NoLock );
509
509
}
510
510
511
511
@@ -607,12 +607,6 @@ dropdb(const char *dbname)
607
607
*/
608
608
DeleteComments (db_id ,RelationGetRelid (pgdbrel ),0 );
609
609
610
- /*
611
- * Close pg_database, but keep exclusive lock till commit to ensure
612
- * that any new backend scanning pg_database will see the tuple dead.
613
- */
614
- heap_close (pgdbrel ,NoLock );
615
-
616
610
/*
617
611
* Drop pages for this database that are in the shared buffer cache.
618
612
* This is important to ensure that no remaining backend tries to
@@ -644,7 +638,10 @@ dropdb(const char *dbname)
644
638
* (They'll see an uncommitted deletion, but they don't care; see
645
639
* GetRawDatabaseInfo.)
646
640
*/
647
- BufferSync (-1 ,-1 );
641
+ FlushRelationBuffers (pgdbrel ,MaxBlockNumber );
642
+
643
+ /* Close pg_database, but keep exclusive lock till commit */
644
+ heap_close (pgdbrel ,NoLock );
648
645
}
649
646
650
647
@@ -733,15 +730,17 @@ RenameDatabase(const char *oldname, const char *newname)
733
730
CatalogUpdateIndexes (rel ,newtup );
734
731
735
732
systable_endscan (scan );
736
- heap_close (rel ,NoLock );
737
733
738
734
/*
739
735
* Force dirty buffers out to disk, so that newly-connecting backends
740
736
* will see the renamed database in pg_database right away. (They'll
741
737
* see an uncommitted tuple, but they don't care; see
742
738
* GetRawDatabaseInfo.)
743
739
*/
744
- BufferSync (-1 ,-1 );
740
+ FlushRelationBuffers (rel ,MaxBlockNumber );
741
+
742
+ /* Close pg_database, but keep exclusive lock till commit */
743
+ heap_close (rel ,NoLock );
745
744
}
746
745
747
746
@@ -763,7 +762,10 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
763
762
764
763
valuestr = flatten_set_variable_args (stmt -> variable ,stmt -> value );
765
764
766
- rel = heap_openr (DatabaseRelationName ,RowExclusiveLock );
765
+ /*
766
+ * We need AccessExclusiveLock so we can safely do FlushRelationBuffers.
767
+ */
768
+ rel = heap_openr (DatabaseRelationName ,AccessExclusiveLock );
767
769
ScanKeyInit (& scankey ,
768
770
Anum_pg_database_datname ,
769
771
BTEqualStrategyNumber ,F_NAMEEQ ,
@@ -821,6 +823,16 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
821
823
CatalogUpdateIndexes (rel ,newtuple );
822
824
823
825
systable_endscan (scan );
826
+
827
+ /*
828
+ * Force dirty buffers out to disk, so that newly-connecting backends
829
+ * will see the altered row in pg_database right away. (They'll
830
+ * see an uncommitted tuple, but they don't care; see
831
+ * GetRawDatabaseInfo.)
832
+ */
833
+ FlushRelationBuffers (rel ,MaxBlockNumber );
834
+
835
+ /* Close pg_database, but keep exclusive lock till commit */
824
836
heap_close (rel ,NoLock );
825
837
}
826
838
@@ -837,7 +849,10 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
837
849
SysScanDesc scan ;
838
850
Form_pg_database datForm ;
839
851
840
- rel = heap_openr (DatabaseRelationName ,RowExclusiveLock );
852
+ /*
853
+ * We need AccessExclusiveLock so we can safely do FlushRelationBuffers.
854
+ */
855
+ rel = heap_openr (DatabaseRelationName ,AccessExclusiveLock );
841
856
ScanKeyInit (& scankey ,
842
857
Anum_pg_database_datname ,
843
858
BTEqualStrategyNumber ,F_NAMEEQ ,
@@ -901,9 +916,22 @@ AlterDatabaseOwner(const char *dbname, AclId newOwnerSysId)
901
916
CatalogUpdateIndexes (rel ,newtuple );
902
917
903
918
heap_freetuple (newtuple );
919
+
920
+ /* must release buffer pins before FlushRelationBuffers */
921
+ systable_endscan (scan );
922
+
923
+ /*
924
+ * Force dirty buffers out to disk, so that newly-connecting backends
925
+ * will see the altered row in pg_database right away. (They'll
926
+ * see an uncommitted tuple, but they don't care; see
927
+ * GetRawDatabaseInfo.)
928
+ */
929
+ FlushRelationBuffers (rel ,MaxBlockNumber );
904
930
}
931
+ else
932
+ systable_endscan (scan );
905
933
906
- systable_endscan ( scan );
934
+ /* Close pg_database, but keep exclusive lock till commit */
907
935
heap_close (rel ,NoLock );
908
936
}
909
937
@@ -1176,7 +1204,7 @@ dbase_redo(XLogRecPtr lsn, XLogRecord *record)
1176
1204
/*
1177
1205
* Force dirty buffers out to disk, to ensure source database is
1178
1206
* up-to-date for the copy. (We really only need to flush buffers for
1179
- * the source database.. .)
1207
+ * the source database, but bufmgr.c provides no API for that .)
1180
1208
*/
1181
1209
BufferSync (-1 ,-1 );
1182
1210