@@ -590,7 +590,8 @@ static ObjectAddress ATExecClusterOn(Relation rel, const char *indexName,
590590static void ATExecDropCluster(Relation rel, LOCKMODE lockmode);
591591static void ATPrepSetAccessMethod(AlteredTableInfo *tab, Relation rel, const char *amname);
592592static void ATExecSetAccessMethodNoStorage(Relation rel, Oid newAccessMethodId);
593- static bool ATPrepChangePersistence(Relation rel, bool toLogged);
593+ static void ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel,
594+ bool toLogged);
594595static void ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel,
595596const char *tablespacename, LOCKMODE lockmode);
596597static void ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode);
@@ -4953,33 +4954,13 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
49534954pass = AT_PASS_MISC;
49544955break;
49554956case AT_SetLogged:/* SET LOGGED */
4956- ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_SEQUENCE);
4957- if (tab->chgPersistence)
4958- ereport(ERROR,
4959- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4960- errmsg("cannot change persistence setting twice")));
4961- tab->chgPersistence = ATPrepChangePersistence(rel, true);
4962- /* force rewrite if necessary; see comment in ATRewriteTables */
4963- if (tab->chgPersistence)
4964- {
4965- tab->rewrite |= AT_REWRITE_ALTER_PERSISTENCE;
4966- tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
4967- }
4968- pass = AT_PASS_MISC;
4969- break;
49704957case AT_SetUnLogged:/* SET UNLOGGED */
49714958ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_SEQUENCE);
49724959if (tab->chgPersistence)
49734960ereport(ERROR,
49744961(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
49754962 errmsg("cannot change persistence setting twice")));
4976- tab->chgPersistence = ATPrepChangePersistence(rel, false);
4977- /* force rewrite if necessary; see comment in ATRewriteTables */
4978- if (tab->chgPersistence)
4979- {
4980- tab->rewrite |= AT_REWRITE_ALTER_PERSISTENCE;
4981- tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
4982- }
4963+ ATPrepChangePersistence(tab, rel, cmd->subtype == AT_SetLogged);
49834964pass = AT_PASS_MISC;
49844965break;
49854966case AT_DropOids:/* SET WITHOUT OIDS */
@@ -16894,12 +16875,9 @@ ATExecSetCompression(Relation rel,
1689416875 * This verifies that we're not trying to change a temp table. Also,
1689516876 * existing foreign key constraints are checked to avoid ending up with
1689616877 * permanent tables referencing unlogged tables.
16897- *
16898- * Return value is false if the operation is a no-op (in which case the
16899- * checks are skipped), otherwise true.
1690016878 */
16901- staticbool
16902- ATPrepChangePersistence(Relation rel, bool toLogged)
16879+ staticvoid
16880+ ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel, bool toLogged)
1690316881{
1690416882Relationpg_constraint;
1690516883HeapTupletuple;
@@ -16923,12 +16901,12 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
1692316901case RELPERSISTENCE_PERMANENT:
1692416902if (toLogged)
1692516903/* nothing to do */
16926- return false ;
16904+ return;
1692716905break;
1692816906case RELPERSISTENCE_UNLOGGED:
1692916907if (!toLogged)
1693016908/* nothing to do */
16931- return false ;
16909+ return;
1693216910break;
1693316911}
1693416912
@@ -17011,7 +16989,13 @@ ATPrepChangePersistence(Relation rel, bool toLogged)
1701116989
1701216990table_close(pg_constraint, AccessShareLock);
1701316991
17014- return true;
16992+ /* force rewrite if necessary; see comment in ATRewriteTables */
16993+ tab->rewrite |= AT_REWRITE_ALTER_PERSISTENCE;
16994+ if (toLogged)
16995+ tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
16996+ else
16997+ tab->newrelpersistence = RELPERSISTENCE_UNLOGGED;
16998+ tab->chgPersistence = true;
1701516999}
1701617000
1701717001/*