Minor improvements in sequence decoding code and docs
authorTomas Vondra <tomas.vondra@postgresql.org>
Fri, 25 Mar 2022 19:12:50 +0000 (20:12 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Fri, 25 Mar 2022 20:07:17 +0000 (21:07 +0100)
A couple minor comment improvements and code cleanups, based on
post-commit feedback to the sequence decoding patch.

Author: Amit Kapila, vignesh C
Discussion: https://postgr.es/m/aeb2ba8d-e6f4-5486-cc4c-0d4982c291cb@enterprisedb.com

doc/src/sgml/protocol.sgml
src/backend/catalog/pg_publication.c
src/backend/commands/publicationcmds.c
src/backend/replication/pgoutput/pgoutput.c

index c61c310e176528559f33693bc9b42c844514e42e..8bb34a7c5baede04b237dda7cd8c5e800732411e 100644 (file)
@@ -7141,7 +7141,7 @@ Sequence
 </term>
 <listitem>
 <para>
-                1 if the sequence update is transactions, 0 otherwise.
+                1 if the sequence update is transactional, 0 otherwise.
 </para>
 </listitem>
 </varlistentry>
index 5bcfc94e2bab1be7a58c3d865c34e5247c3c3ed9..514a94796e19cdd7b5fe4e390fc1c506e289cc30 100644 (file)
@@ -193,7 +193,7 @@ AssertObjectTypeValid(char objectType)
 }
 
 /*
- * Determine object type given the object type set for a schema.
+ * Determine object type matching a given a relkind value.
  */
 char
 pub_get_object_type_for_relkind(char relkind)
index c6437799c53bb253a69b3da6bbda4e9f426179ac..e449e8e8f2963b55ca9ed437dac3371c0de93bc0 100644 (file)
@@ -175,8 +175,7 @@ parse_publication_options(ParseState *pstate,
 static void
 ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
                           List **tables, List **sequences,
-                          List **tables_schemas, List **sequences_schemas,
-                          List **schemas)
+                          List **tables_schemas, List **sequences_schemas)
 {
    ListCell   *cell;
    PublicationObjSpec *pubobj;
@@ -204,14 +203,12 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
 
                /* Filter out duplicates if user specifies "sch1, sch1" */
                *tables_schemas = list_append_unique_oid(*tables_schemas, schemaid);
-               *schemas = list_append_unique_oid(*schemas, schemaid);
                break;
            case PUBLICATIONOBJ_SEQUENCES_IN_SCHEMA:
                schemaid = get_namespace_oid(pubobj->name, false);
 
                /* Filter out duplicates if user specifies "sch1, sch1" */
                *sequences_schemas = list_append_unique_oid(*sequences_schemas, schemaid);
-               *schemas = list_append_unique_oid(*schemas, schemaid);
                break;
            case PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA:
                search_path = fetch_search_path(false);
@@ -225,7 +222,6 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
 
                /* Filter out duplicates if user specifies "sch1, sch1" */
                *tables_schemas = list_append_unique_oid(*tables_schemas, schemaid);
-               *schemas = list_append_unique_oid(*schemas, schemaid);
                break;
            case PUBLICATIONOBJ_SEQUENCES_IN_CUR_SCHEMA:
                search_path = fetch_search_path(false);
@@ -239,7 +235,6 @@ ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
 
                /* Filter out duplicates if user specifies "sch1, sch1" */
                *sequences_schemas = list_append_unique_oid(*sequences_schemas, schemaid);
-               *schemas = list_append_unique_oid(*schemas, schemaid);
                break;
            default:
                /* shouldn't happen */
@@ -679,7 +674,6 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
    List       *sequences = NIL;
    List       *tables_schemaidlist = NIL;
    List       *sequences_schemaidlist = NIL;
-   List       *schemaidlist = NIL;
 
    bool        for_all_tables = false;
    bool        for_all_sequences = false;
@@ -706,6 +700,12 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                 errmsg("must be superuser to create FOR ALL TABLES publication")));
 
+   /* FOR ALL SEQUENCES requires superuser */
+   if (for_all_sequences && !superuser())
+       ereport(ERROR,
+               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                errmsg("must be superuser to create FOR ALL SEQUENCES publication")));
+
    rel = table_open(PublicationRelationId, RowExclusiveLock);
 
    /* Check if name is used */
@@ -782,8 +782,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
        ObjectsInPublicationToOids(stmt->pubobjects, pstate,
                                   &tables, &sequences,
                                   &tables_schemaidlist,
-                                  &sequences_schemaidlist,
-                                  &schemaidlist);
+                                  &sequences_schemaidlist);
 
        /* FOR ALL TABLES IN SCHEMA requires superuser */
        if (list_length(tables_schemaidlist) > 0 && !superuser())
@@ -1321,7 +1320,7 @@ CheckAlterPublication(AlterPublicationStmt *stmt, HeapTuple tup,
                        NameStr(pubform->pubname)),
                 errdetail("Tables cannot be added to or dropped from FOR ALL TABLES publications.")));
 
-   /* Check that user is allowed to manipulate the publication tables. */
+   /* Check that user is allowed to manipulate the publication sequences. */
    if (sequences && pubform->puballsequences)
        ereport(ERROR,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
@@ -1462,14 +1461,12 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
        List       *sequences = NIL;
        List       *tables_schemaidlist = NIL;
        List       *sequences_schemaidlist = NIL;
-       List       *schemaidlist = NIL;
        Oid         pubid = pubform->oid;
 
        ObjectsInPublicationToOids(stmt->pubobjects, pstate,
                                   &tables, &sequences,
                                   &tables_schemaidlist,
-                                  &sequences_schemaidlist,
-                                  &schemaidlist);
+                                  &sequences_schemaidlist);
 
        CheckAlterPublication(stmt, tup,
                              tables, tables_schemaidlist,
index 4cdc698cbb3e3e5c706824b5855020aadadc3906..292e7299d8867e94508744bd47d91ace6e3e22a7 100644 (file)
@@ -1804,7 +1804,8 @@ get_rel_sync_entry(PGOutputData *data, Relation relation)
    {
        Oid         schemaId = get_rel_namespace(relid);
        List       *pubids = GetRelationPublications(relid);
-       char        objectType = pub_get_object_type_for_relkind(get_rel_relkind(relid));
+       char        relkind = get_rel_relkind(relid);
+       char        objectType = pub_get_object_type_for_relkind(relkind);
        /*
         * We don't acquire a lock on the namespace system table as we build
         * the cache entry using a historic snapshot and all the later changes
@@ -1815,7 +1816,6 @@ get_rel_sync_entry(PGOutputData *data, Relation relation)
        Oid         publish_as_relid = relid;
        int         publish_ancestor_level = 0;
        bool        am_partition = get_rel_relispartition(relid);
-       char        relkind = get_rel_relkind(relid);
        List       *rel_publications = NIL;
 
        /* Reload publications if needed before use. */