@@ -152,7 +152,7 @@ typedef struct AlteredTableInfo
152152bool new_notnull ;/* T if we added new NOT NULL constraints */
153153bool rewrite ;/* T if a rewrite is forced */
154154Oid newTableSpace ;/* new tablespace; 0 means no change */
155- bool chgLoggedness ; /* T if SET LOGGED/UNLOGGED is used */
155+ bool chgPersistence ; /* T if SET LOGGED/UNLOGGED is used */
156156char newrelpersistence ;/* if above is true */
157157/* Objects to rebuild after completing ALTER TYPE operations */
158158List * changedConstraintOids ;/* OIDs of constraints to rebuild */
@@ -388,8 +388,8 @@ static void change_owner_recurse_to_sequences(Oid relationOid,
388388static void ATExecClusterOn (Relation rel ,const char * indexName ,
389389LOCKMODE lockmode );
390390static void ATExecDropCluster (Relation rel ,LOCKMODE lockmode );
391- static bool ATPrepChangeLoggedness (Relation rel ,bool toLogged );
392- static void ATChangeIndexesLoggedness (Oid relid ,char relpersistence );
391+ static bool ATPrepChangePersistence (Relation rel ,bool toLogged );
392+ static void ATChangeIndexesPersistence (Oid relid ,char relpersistence );
393393static void ATPrepSetTableSpace (AlteredTableInfo * tab ,Relation rel ,
394394char * tablespacename ,LOCKMODE lockmode );
395395static void ATExecSetTableSpace (Oid tableOid ,Oid newTableSpace ,LOCKMODE lockmode );
@@ -3174,19 +3174,19 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
31743174break ;
31753175case AT_SetLogged :/* SET LOGGED */
31763176ATSimplePermissions (rel ,ATT_TABLE );
3177- tab -> chgLoggedness = ATPrepChangeLoggedness (rel , true);
3177+ tab -> chgPersistence = ATPrepChangePersistence (rel , true);
31783178tab -> newrelpersistence = RELPERSISTENCE_PERMANENT ;
31793179/* force rewrite if necessary */
3180- if (tab -> chgLoggedness )
3180+ if (tab -> chgPersistence )
31813181tab -> rewrite = true;
31823182pass = AT_PASS_MISC ;
31833183break ;
31843184case AT_SetUnLogged :/* SET UNLOGGED */
31853185ATSimplePermissions (rel ,ATT_TABLE );
3186- tab -> chgLoggedness = ATPrepChangeLoggedness (rel , false);
3186+ tab -> chgPersistence = ATPrepChangePersistence (rel , false);
31873187tab -> newrelpersistence = RELPERSISTENCE_UNLOGGED ;
31883188/* force rewrite if necessary */
3189- if (tab -> chgLoggedness )
3189+ if (tab -> chgPersistence )
31903190tab -> rewrite = true;
31913191pass = AT_PASS_MISC ;
31923192break ;
@@ -3618,6 +3618,13 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
36183618 * We only need to rewrite the table if at least one column needs to
36193619 * be recomputed, we are adding/removing the OID column, or we are
36203620 * changing its persistence.
3621+ *
3622+ * There are two reasons for requiring a rewrite when changing
3623+ * persistence: on one hand, we need to ensure that the buffers
3624+ * belonging to each of the two relations are marked with or without
3625+ * BM_PERMANENT properly. On the other hand, since rewriting creates
3626+ * and assigns a new relfilenode, we automatically create or drop an
3627+ * init fork for the relation as appropriate.
36213628 */
36223629if (tab -> rewrite )
36233630{
@@ -3668,7 +3675,7 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
36683675 * Select persistence of transient table (same as original unless
36693676 * user requested a change)
36703677 */
3671- persistence = tab -> chgLoggedness ?
3678+ persistence = tab -> chgPersistence ?
36723679tab -> newrelpersistence :OldHeap -> rd_rel -> relpersistence ;
36733680
36743681heap_close (OldHeap ,NoLock );
@@ -3705,8 +3712,8 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
37053712 * because the rewrite step might read the indexes, and that would
37063713 * cause buffers for them to have the wrong setting.
37073714 */
3708- if (tab -> chgLoggedness )
3709- ATChangeIndexesLoggedness (tab -> relid ,tab -> newrelpersistence );
3715+ if (tab -> chgPersistence )
3716+ ATChangeIndexesPersistence (tab -> relid ,tab -> newrelpersistence );
37103717
37113718/*
37123719 * Swap the physical files of the old and new heaps, then rebuild
@@ -4119,7 +4126,7 @@ ATGetQueueEntry(List **wqueue, Relation rel)
41194126tab -> relkind = rel -> rd_rel -> relkind ;
41204127tab -> oldDesc = CreateTupleDescCopy (RelationGetDescr (rel ));
41214128tab -> newrelpersistence = RELPERSISTENCE_PERMANENT ;
4122- tab -> chgLoggedness = false;
4129+ tab -> chgPersistence = false;
41234130
41244131* wqueue = lappend (* wqueue ,tab );
41254132
@@ -10678,7 +10685,7 @@ ATExecGenericOptions(Relation rel, List *options)
1067810685 * checks are skipped), otherwise true.
1067910686 */
1068010687static bool
10681- ATPrepChangeLoggedness (Relation rel ,bool toLogged )
10688+ ATPrepChangePersistence (Relation rel ,bool toLogged )
1068210689{
1068310690Relation pg_constraint ;
1068410691HeapTuple tuple ;
@@ -10722,7 +10729,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
1072210729
1072310730/*
1072410731 * Scan conrelid if changing to permanent, else confrelid. This also
10725- * determines whetheran useful index exists.
10732+ * determines whethera useful index exists.
1072610733 */
1072710734ScanKeyInit (& skey [0 ],
1072810735toLogged ?Anum_pg_constraint_conrelid :
@@ -10792,7 +10799,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
1079210799 * given persistence.
1079310800 */
1079410801static void
10795- ATChangeIndexesLoggedness (Oid relid ,char relpersistence )
10802+ ATChangeIndexesPersistence (Oid relid ,char relpersistence )
1079610803{
1079710804Relation rel ;
1079810805Relation pg_class ;