Skip to content

Commit

Permalink
Allow publications FOR ALL TABLES to neon_superuser
Browse files Browse the repository at this point in the history
  • Loading branch information
save-buffer authored and tristan957 committed Feb 6, 2024
1 parent ddd992d commit d88acb5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/backend/commands/publicationcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,13 @@ CheckPubRelationColumnList(char *pubname, List *tables,
}
}

static bool
is_neon_superuser(void)
{
Oid neon_superuser_oid = get_role_oid("neon_superuser", true /*missing_ok*/);
return neon_superuser_oid != InvalidOid && has_privs_of_role(GetCurrentRoleId(), neon_superuser_oid);
}

/*
* Create new publication.
*/
Expand Down Expand Up @@ -755,7 +762,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
get_database_name(MyDatabaseId));

/* FOR ALL TABLES requires superuser */
if (stmt->for_all_tables && !superuser())
if (stmt->for_all_tables && !superuser() && !is_neon_superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to create FOR ALL TABLES publication")));
Expand Down Expand Up @@ -826,7 +833,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
&schemaidlist);

/* FOR TABLES IN SCHEMA requires superuser */
if (schemaidlist != NIL && !superuser())
if (schemaidlist != NIL && !superuser() && !is_neon_superuser())
ereport(ERROR,
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to create FOR TABLES IN SCHEMA publication"));
Expand Down

0 comments on commit d88acb5

Please sign in to comment.