diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 091797db402..627ac029db4 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -1651,6 +1651,9 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt) HeapTuple tup; Form_pg_publication pubform; Oid pubid; + List *relations = NIL; + List *exceptrelations = NIL; + List *schemaidlist = NIL; rel = table_open(PublicationRelationId, RowExclusiveLock); @@ -1672,68 +1675,36 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt) pubid = pubform->oid; - if (stmt->options) - { - /* - * Lock the publication so nobody else can change it while we validate - * and update it. This prevents a concurrent alter from adding - * partitioned table(s) with WHERE clause(s) and/or column lists, - * which we don't allow when not publishing via root, and it also - * prevents the publication definition from changing (for example, via - * SET ALL TABLES) between the validation performed by - * AlterPublicationOptions() and the subsequent catalog update. - */ - LockDatabaseObject(PublicationRelationId, pubid, 0, - AccessShareLock); + /* Convert the publication objects to OIDs if not altering options */ + if (!stmt->options) + ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations, + &exceptrelations, &schemaidlist); - heap_freetuple(tup); + LockDatabaseObject(PublicationRelationId, pubid, 0, + stmt->options ? AccessShareLock : AccessExclusiveLock); - /* - * It is possible that by the time we acquire the lock on publication, - * concurrent DDL has removed it. We can test this by checking the - * existence of publication. We get the tuple again to avoid the risk - * of any publication option getting changed. - */ - tup = SearchSysCacheCopy1(PUBLICATIONOID, - ObjectIdGetDatum(pubid)); - if (!HeapTupleIsValid(tup)) - ereport(ERROR, - errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("publication \"%s\" does not exist", - stmt->pubname)); + heap_freetuple(tup); + + /* + * It is possible that by the time we acquire the lock on publication, + * concurrent DDL has removed it. We can test this by checking the + * existence of publication. We get the tuple again to avoid the risk of + * any publication option getting changed. + */ + tup = SearchSysCacheCopy1(PUBLICATIONOID, + ObjectIdGetDatum(pubid)); + if (!HeapTupleIsValid(tup)) + ereport(ERROR, + errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("publication \"%s\" does not exist", + stmt->pubname)); + if (stmt->options) AlterPublicationOptions(pstate, stmt, rel, tup); - } else { - List *relations = NIL; - List *exceptrelations = NIL; - List *schemaidlist = NIL; - - ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations, - &exceptrelations, &schemaidlist); - CheckAlterPublication(stmt, tup, relations, schemaidlist); - heap_freetuple(tup); - - /* Lock the publication so nobody else can do anything with it. */ - LockDatabaseObject(PublicationRelationId, pubid, 0, - AccessExclusiveLock); - - /* - * It is possible that by the time we acquire the lock on publication, - * concurrent DDL has removed it. We can test this by checking the - * existence of publication. We get the tuple again to avoid the risk - * of any publication option getting changed. - */ - tup = SearchSysCacheCopy1(PUBLICATIONOID, ObjectIdGetDatum(pubid)); - if (!HeapTupleIsValid(tup)) - ereport(ERROR, - errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("publication \"%s\" does not exist", - stmt->pubname)); - relations = list_concat(relations, exceptrelations); AlterPublicationTables(stmt, tup, relations, pstate->p_sourcetext, schemaidlist != NIL);