PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
publicationcmds.h File Reference
Include dependency graph for publicationcmds.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ObjectAddress CreatePublication (CreatePublicationStmt *stmt)
 
void AlterPublication (AlterPublicationStmt *stmt)
 
void RemovePublicationById (Oid pubid)
 
void RemovePublicationRelById (Oid proid)
 
ObjectAddress AlterPublicationOwner (const char *name, Oid newOwnerId)
 
void AlterPublicationOwner_oid (Oid pubid, Oid newOwnerId)
 

Function Documentation

void AlterPublication ( AlterPublicationStmt stmt)

Definition at line 388 of file publicationcmds.c.

References ACL_KIND_PUBLICATION, aclcheck_error(), ACLCHECK_NOT_OWNER, AlterPublicationOptions(), AlterPublicationTables(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GetUserId(), heap_close, heap_freetuple(), heap_open(), HeapTupleGetOid, HeapTupleIsValid, AlterPublicationStmt::options, pg_publication_ownercheck(), PUBLICATIONNAME, PublicationRelationId, AlterPublicationStmt::pubname, RowExclusiveLock, and SearchSysCacheCopy1.

Referenced by ProcessUtilitySlow().

389 {
390  Relation rel;
391  HeapTuple tup;
392 
394 
396  CStringGetDatum(stmt->pubname));
397 
398  if (!HeapTupleIsValid(tup))
399  ereport(ERROR,
400  (errcode(ERRCODE_UNDEFINED_OBJECT),
401  errmsg("publication \"%s\" does not exist",
402  stmt->pubname)));
403 
404  /* must be owner */
407  stmt->pubname);
408 
409  if (stmt->options)
410  AlterPublicationOptions(stmt, rel, tup);
411  else
412  AlterPublicationTables(stmt, rel, tup);
413 
414  /* Cleanup. */
415  heap_freetuple(tup);
417 }
static void AlterPublicationOptions(AlterPublicationStmt *stmt, Relation rel, HeapTuple tup)
Oid GetUserId(void)
Definition: miscinit.c:283
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5084
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PublicationRelationId
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1372
#define ERROR
Definition: elog.h:43
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
static void AlterPublicationTables(AlterPublicationStmt *stmt, Relation rel, HeapTuple tup)
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:165
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
ObjectAddress AlterPublicationOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 688 of file publicationcmds.c.

References AlterPublicationOwner_internal(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, heap_close, heap_freetuple(), heap_open(), HeapTupleGetOid, HeapTupleIsValid, ObjectAddressSet, PUBLICATIONNAME, PublicationRelationId, RowExclusiveLock, and SearchSysCacheCopy1.

Referenced by ExecAlterOwnerStmt().

689 {
690  Oid subid;
691  HeapTuple tup;
692  Relation rel;
693  ObjectAddress address;
694 
696 
698 
699  if (!HeapTupleIsValid(tup))
700  ereport(ERROR,
701  (errcode(ERRCODE_UNDEFINED_OBJECT),
702  errmsg("publication \"%s\" does not exist", name)));
703 
704  subid = HeapTupleGetOid(tup);
705 
706  AlterPublicationOwner_internal(rel, tup, newOwnerId);
707 
708  ObjectAddressSet(address, PublicationRelationId, subid);
709 
710  heap_freetuple(tup);
711 
713 
714  return address;
715 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PublicationRelationId
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1372
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
static void AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
const char * name
Definition: encode.c:521
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:165
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
void AlterPublicationOwner_oid ( Oid  pubid,
Oid  newOwnerId 
)

Definition at line 721 of file publicationcmds.c.

References AlterPublicationOwner_internal(), ereport, errcode(), errmsg(), ERROR, heap_close, heap_freetuple(), heap_open(), HeapTupleIsValid, ObjectIdGetDatum, PUBLICATIONOID, PublicationRelationId, RowExclusiveLock, and SearchSysCacheCopy1.

Referenced by shdepReassignOwned().

722 {
723  HeapTuple tup;
724  Relation rel;
725 
727 
729 
730  if (!HeapTupleIsValid(tup))
731  ereport(ERROR,
732  (errcode(ERRCODE_UNDEFINED_OBJECT),
733  errmsg("publication with OID %u does not exist", subid)));
734 
735  AlterPublicationOwner_internal(rel, tup, newOwnerId);
736 
737  heap_freetuple(tup);
738 
740 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PublicationRelationId
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1372
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel, rest)
Definition: elog.h:122
static void AlterPublicationOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:165
int errmsg(const char *fmt,...)
Definition: elog.c:797
ObjectAddress CreatePublication ( CreatePublicationStmt stmt)

Definition at line 136 of file publicationcmds.c.

References ACL_CREATE, ACL_KIND_DATABASE, aclcheck_error(), ACLCHECK_OK, Anum_pg_publication_puballtables, Anum_pg_publication_pubdelete, Anum_pg_publication_pubinsert, Anum_pg_publication_pubname, Anum_pg_publication_pubowner, Anum_pg_publication_pubupdate, Assert, BoolGetDatum, CatalogTupleInsert(), CloseTableList(), CommandCounterIncrement(), CStringGetDatum, DirectFunctionCall1, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, CreatePublicationStmt::for_all_tables, get_database_name(), GetSysCacheOid1, GetUserId(), heap_close, heap_form_tuple(), heap_freetuple(), heap_open(), InvokeObjectPostCreateHook, list_length(), MyDatabaseId, namein(), Natts_pg_publication, NULL, ObjectAddressSet, ObjectIdGetDatum, OidIsValid, OpenTableList(), CreatePublicationStmt::options, parse_publication_options(), pg_database_aclcheck(), PublicationAddTables(), PUBLICATIONNAME, PublicationRelationId, CreatePublicationStmt::pubname, recordDependencyOnOwner(), RelationGetDescr, RowExclusiveLock, superuser(), CreatePublicationStmt::tables, and values.

Referenced by ProcessUtilitySlow().

137 {
138  Relation rel;
139  ObjectAddress myself;
140  Oid puboid;
141  bool nulls[Natts_pg_publication];
143  HeapTuple tup;
144  bool publish_given;
145  bool publish_insert;
146  bool publish_update;
147  bool publish_delete;
148  AclResult aclresult;
149 
150  /* must have CREATE privilege on database */
152  if (aclresult != ACLCHECK_OK)
155 
156  /* FOR ALL TABLES requires superuser */
157  if (stmt->for_all_tables && !superuser())
158  ereport(ERROR,
159  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
160  (errmsg("must be superuser to create FOR ALL TABLES publication"))));
161 
163 
164  /* Check if name is used */
166  if (OidIsValid(puboid))
167  {
168  ereport(ERROR,
170  errmsg("publication \"%s\" already exists",
171  stmt->pubname)));
172  }
173 
174  /* Form a tuple. */
175  memset(values, 0, sizeof(values));
176  memset(nulls, false, sizeof(nulls));
177 
178  values[Anum_pg_publication_pubname - 1] =
181 
183  &publish_given, &publish_insert,
184  &publish_update, &publish_delete);
185 
188  values[Anum_pg_publication_pubinsert - 1] =
189  BoolGetDatum(publish_insert);
190  values[Anum_pg_publication_pubupdate - 1] =
191  BoolGetDatum(publish_update);
192  values[Anum_pg_publication_pubdelete - 1] =
193  BoolGetDatum(publish_delete);
194 
195  tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
196 
197  /* Insert tuple into catalog. */
198  puboid = CatalogTupleInsert(rel, tup);
199  heap_freetuple(tup);
200 
202 
203  ObjectAddressSet(myself, PublicationRelationId, puboid);
204 
205  /* Make the changes visible. */
207 
208  if (stmt->tables)
209  {
210  List *rels;
211 
212  Assert(list_length(stmt->tables) > 0);
213 
214  rels = OpenTableList(stmt->tables);
215  PublicationAddTables(puboid, rels, true, NULL);
216  CloseTableList(rels);
217  }
218 
220 
222 
223  return myself;
224 }
#define Natts_pg_publication
static void PublicationAddTables(Oid pubid, List *rels, bool if_not_exists, AlterPublicationStmt *stmt)
Datum namein(PG_FUNCTION_ARGS)
Definition: name.c:46
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:145
#define RelationGetDescr(relation)
Definition: rel.h:428
Oid GetUserId(void)
Definition: miscinit.c:283
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
#define PublicationRelationId
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define heap_close(r, l)
Definition: heapam.h:97
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:159
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1372
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define Anum_pg_publication_pubowner
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:183
static void CloseTableList(List *rels)
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:82
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:162
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2056
#define Anum_pg_publication_pubupdate
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:584
#define Anum_pg_publication_pubdelete
#define ereport(elevel, rest)
Definition: elog.h:122
AclResult
Definition: acl.h:170
uintptr_t Datum
Definition: postgres.h:372
void CommandCounterIncrement(void)
Definition: xact.c:922
#define Anum_pg_publication_pubinsert
Oid MyDatabaseId
Definition: globals.c:77
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define BoolGetDatum(X)
Definition: postgres.h:408
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4434
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static int list_length(const List *l)
Definition: pg_list.h:89
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
static Datum values[MAXATTR]
Definition: bootstrap.c:163
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define Anum_pg_publication_puballtables
#define Anum_pg_publication_pubname
static void parse_publication_options(List *options, bool *publish_given, bool *publish_insert, bool *publish_update, bool *publish_delete)
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:31
Definition: pg_list.h:45
static List * OpenTableList(List *tables)
void RemovePublicationById ( Oid  pubid)

Definition at line 423 of file publicationcmds.c.

References CatalogTupleDelete(), elog, ERROR, heap_close, heap_open(), HeapTupleIsValid, ObjectIdGetDatum, PUBLICATIONOID, PublicationRelationId, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1, and HeapTupleData::t_self.

Referenced by doDeletion().

424 {
425  Relation rel;
426  HeapTuple tup;
427 
429 
431 
432  if (!HeapTupleIsValid(tup))
433  elog(ERROR, "cache lookup failed for publication %u", pubid);
434 
435  CatalogTupleDelete(rel, &tup->t_self);
436 
437  ReleaseSysCache(tup);
438 
440 }
#define PublicationRelationId
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define elog
Definition: elog.h:219
void RemovePublicationRelById ( Oid  proid)

Definition at line 446 of file publicationcmds.c.

References CacheInvalidateRelcacheByRelid(), CatalogTupleDelete(), elog, ERROR, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, ObjectIdGetDatum, PUBLICATIONREL, PublicationRelRelationId, ReleaseSysCache(), RowExclusiveLock, SearchSysCache1, and HeapTupleData::t_self.

Referenced by doDeletion().

447 {
448  Relation rel;
449  HeapTuple tup;
451 
453 
455 
456  if (!HeapTupleIsValid(tup))
457  elog(ERROR, "cache lookup failed for publication table %u",
458  proid);
459 
460  pubrel = (Form_pg_publication_rel) GETSTRUCT(tup);
461 
462  /* Invalidate relcache so that publication info is rebuilt. */
463  CacheInvalidateRelcacheByRelid(pubrel->prrelid);
464 
465  CatalogTupleDelete(rel, &tup->t_self);
466 
467  ReleaseSysCache(tup);
468 
470 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define PublicationRelRelationId
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
void CacheInvalidateRelcacheByRelid(Oid relid)
Definition: inval.c:1292
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_publication_rel * Form_pg_publication_rel
#define elog
Definition: elog.h:219