@@ -152,7 +152,7 @@ typedef struct AlteredTableInfo
152
152
bool new_notnull ; /* T if we added new NOT NULL constraints */
153
153
bool rewrite ; /* T if a rewrite is forced */
154
154
Oid 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 */
156
156
char newrelpersistence ; /* if above is true */
157
157
/* Objects to rebuild after completing ALTER TYPE operations */
158
158
List * changedConstraintOids ; /* OIDs of constraints to rebuild */
@@ -388,8 +388,8 @@ static void change_owner_recurse_to_sequences(Oid relationOid,
388
388
static void ATExecClusterOn (Relation rel , const char * indexName ,
389
389
LOCKMODE lockmode );
390
390
static 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 );
393
393
static void ATPrepSetTableSpace (AlteredTableInfo * tab , Relation rel ,
394
394
char * tablespacename , LOCKMODE lockmode );
395
395
static void ATExecSetTableSpace (Oid tableOid , Oid newTableSpace , LOCKMODE lockmode );
@@ -3174,19 +3174,19 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
3174
3174
break ;
3175
3175
case AT_SetLogged : /* SET LOGGED */
3176
3176
ATSimplePermissions (rel , ATT_TABLE );
3177
- tab -> chgLoggedness = ATPrepChangeLoggedness (rel , true);
3177
+ tab -> chgPersistence = ATPrepChangePersistence (rel , true);
3178
3178
tab -> newrelpersistence = RELPERSISTENCE_PERMANENT ;
3179
3179
/* force rewrite if necessary */
3180
- if (tab -> chgLoggedness )
3180
+ if (tab -> chgPersistence )
3181
3181
tab -> rewrite = true;
3182
3182
pass = AT_PASS_MISC ;
3183
3183
break ;
3184
3184
case AT_SetUnLogged : /* SET UNLOGGED */
3185
3185
ATSimplePermissions (rel , ATT_TABLE );
3186
- tab -> chgLoggedness = ATPrepChangeLoggedness (rel , false);
3186
+ tab -> chgPersistence = ATPrepChangePersistence (rel , false);
3187
3187
tab -> newrelpersistence = RELPERSISTENCE_UNLOGGED ;
3188
3188
/* force rewrite if necessary */
3189
- if (tab -> chgLoggedness )
3189
+ if (tab -> chgPersistence )
3190
3190
tab -> rewrite = true;
3191
3191
pass = AT_PASS_MISC ;
3192
3192
break ;
@@ -3618,6 +3618,13 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
3618
3618
* We only need to rewrite the table if at least one column needs to
3619
3619
* be recomputed, we are adding/removing the OID column, or we are
3620
3620
* 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.
3621
3628
*/
3622
3629
if (tab -> rewrite )
3623
3630
{
@@ -3668,7 +3675,7 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
3668
3675
* Select persistence of transient table (same as original unless
3669
3676
* user requested a change)
3670
3677
*/
3671
- persistence = tab -> chgLoggedness ?
3678
+ persistence = tab -> chgPersistence ?
3672
3679
tab -> newrelpersistence : OldHeap -> rd_rel -> relpersistence ;
3673
3680
3674
3681
heap_close (OldHeap , NoLock );
@@ -3705,8 +3712,8 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
3705
3712
* because the rewrite step might read the indexes, and that would
3706
3713
* cause buffers for them to have the wrong setting.
3707
3714
*/
3708
- if (tab -> chgLoggedness )
3709
- ATChangeIndexesLoggedness (tab -> relid , tab -> newrelpersistence );
3715
+ if (tab -> chgPersistence )
3716
+ ATChangeIndexesPersistence (tab -> relid , tab -> newrelpersistence );
3710
3717
3711
3718
/*
3712
3719
* Swap the physical files of the old and new heaps, then rebuild
@@ -4119,7 +4126,7 @@ ATGetQueueEntry(List **wqueue, Relation rel)
4119
4126
tab -> relkind = rel -> rd_rel -> relkind ;
4120
4127
tab -> oldDesc = CreateTupleDescCopy (RelationGetDescr (rel ));
4121
4128
tab -> newrelpersistence = RELPERSISTENCE_PERMANENT ;
4122
- tab -> chgLoggedness = false;
4129
+ tab -> chgPersistence = false;
4123
4130
4124
4131
* wqueue = lappend (* wqueue , tab );
4125
4132
@@ -10678,7 +10685,7 @@ ATExecGenericOptions(Relation rel, List *options)
10678
10685
* checks are skipped), otherwise true.
10679
10686
*/
10680
10687
static bool
10681
- ATPrepChangeLoggedness (Relation rel , bool toLogged )
10688
+ ATPrepChangePersistence (Relation rel , bool toLogged )
10682
10689
{
10683
10690
Relation pg_constraint ;
10684
10691
HeapTuple tuple ;
@@ -10722,7 +10729,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
10722
10729
10723
10730
/*
10724
10731
* Scan conrelid if changing to permanent, else confrelid. This also
10725
- * determines whether an useful index exists.
10732
+ * determines whether a useful index exists.
10726
10733
*/
10727
10734
ScanKeyInit (& skey [0 ],
10728
10735
toLogged ? Anum_pg_constraint_conrelid :
@@ -10792,7 +10799,7 @@ ATPrepChangeLoggedness(Relation rel, bool toLogged)
10792
10799
* given persistence.
10793
10800
*/
10794
10801
static void
10795
- ATChangeIndexesLoggedness (Oid relid , char relpersistence )
10802
+ ATChangeIndexesPersistence (Oid relid , char relpersistence )
10796
10803
{
10797
10804
Relation rel ;
10798
10805
Relation pg_class ;
0 commit comments