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 417 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().

418 {
419  Relation rel;
420  HeapTuple tup;
421 
423 
425  CStringGetDatum(stmt->pubname));
426 
427  if (!HeapTupleIsValid(tup))
428  ereport(ERROR,
429  (errcode(ERRCODE_UNDEFINED_OBJECT),
430  errmsg("publication \"%s\" does not exist",
431  stmt->pubname)));
432 
433  /* must be owner */
436  stmt->pubname);
437 
438  if (stmt->options)
439  AlterPublicationOptions(stmt, rel, tup);
440  else
441  AlterPublicationTables(stmt, rel, tup);
442 
443  /* Cleanup. */
444  heap_freetuple(tup);
446 }
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:5059
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:1374
#define ERROR
Definition: elog.h:43
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3378
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:586
#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:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:158
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 701 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().

702 {
703  Oid subid;
704  HeapTuple tup;
705  Relation rel;
706  ObjectAddress address;
707 
709 
711 
712  if (!HeapTupleIsValid(tup))
713  ereport(ERROR,
714  (errcode(ERRCODE_UNDEFINED_OBJECT),
715  errmsg("publication \"%s\" does not exist", name)));
716 
717  subid = HeapTupleGetOid(tup);
718 
719  AlterPublicationOwner_internal(rel, tup, newOwnerId);
720 
721  ObjectAddressSet(address, PublicationRelationId, subid);
722 
723  heap_freetuple(tup);
724 
726 
727  return address;
728 }
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:1374
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:586
#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:1287
#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:158
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 734 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().

735 {
736  HeapTuple tup;
737  Relation rel;
738 
740 
742 
743  if (!HeapTupleIsValid(tup))
744  ereport(ERROR,
745  (errcode(ERRCODE_UNDEFINED_OBJECT),
746  errmsg("publication with OID %u does not exist", subid)));
747 
748  AlterPublicationOwner_internal(rel, tup, newOwnerId);
749 
750  heap_freetuple(tup);
751 
753 }
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:1374
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#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:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:158
int errmsg(const char *fmt,...)
Definition: elog.c:797
ObjectAddress CreatePublication ( CreatePublicationStmt stmt)

Definition at line 153 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().

154 {
155  Relation rel;
156  ObjectAddress myself;
157  Oid puboid;
158  bool nulls[Natts_pg_publication];
160  HeapTuple tup;
161  bool publish_insert_given;
162  bool publish_update_given;
163  bool publish_delete_given;
164  bool publish_insert;
165  bool publish_update;
166  bool publish_delete;
167  AclResult aclresult;
168 
169  /* must have CREATE privilege on database */
171  if (aclresult != ACLCHECK_OK)
174 
175  /* FOR ALL TABLES requires superuser */
176  if (stmt->for_all_tables && !superuser())
177  ereport(ERROR,
178  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
179  (errmsg("must be superuser to create FOR ALL TABLES publication"))));
180 
182 
183  /* Check if name is used */
185  if (OidIsValid(puboid))
186  {
187  ereport(ERROR,
189  errmsg("publication \"%s\" already exists",
190  stmt->pubname)));
191  }
192 
193  /* Form a tuple. */
194  memset(values, 0, sizeof(values));
195  memset(nulls, false, sizeof(nulls));
196 
197  values[Anum_pg_publication_pubname - 1] =
200 
202  &publish_insert_given, &publish_insert,
203  &publish_update_given, &publish_update,
204  &publish_delete_given, &publish_delete);
205 
208  values[Anum_pg_publication_pubinsert - 1] =
209  BoolGetDatum(publish_insert);
210  values[Anum_pg_publication_pubupdate - 1] =
211  BoolGetDatum(publish_update);
212  values[Anum_pg_publication_pubdelete - 1] =
213  BoolGetDatum(publish_delete);
214 
215  tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
216 
217  /* Insert tuple into catalog. */
218  puboid = CatalogTupleInsert(rel, tup);
219  heap_freetuple(tup);
220 
222 
223  ObjectAddressSet(myself, PublicationRelationId, puboid);
224 
225  /* Make the changes visible. */
227 
228  if (stmt->tables)
229  {
230  List *rels;
231 
232  Assert(list_length(stmt->tables) > 0);
233 
234  rels = OpenTableList(stmt->tables);
235  PublicationAddTables(puboid, rels, true, NULL);
236  CloseTableList(rels);
237  }
238 
240 
242 
243  return myself;
244 }
#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:425
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:555
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:158
static void parse_publication_options(List *options, bool *publish_insert_given, bool *publish_insert, bool *publish_update_given, bool *publish_update, bool *publish_delete_given, bool *publish_delete)
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1374
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
#define Anum_pg_publication_pubowner
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:176
static void CloseTableList(List *rels)
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:75
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:162
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2049
#define Anum_pg_publication_pubupdate
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3378
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:586
#define Anum_pg_publication_pubdelete
#define ereport(elevel, rest)
Definition: elog.h:122
AclResult
Definition: acl.h:170
uintptr_t Datum
Definition: postgres.h:374
void CommandCounterIncrement(void)
Definition: xact.c:921
#define Anum_pg_publication_pubinsert
Oid MyDatabaseId
Definition: globals.c:76
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define BoolGetDatum(X)
Definition: postgres.h:410
AclResult pg_database_aclcheck(Oid db_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4409
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
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:162
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define Anum_pg_publication_puballtables
#define Anum_pg_publication_pubname
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:34
Definition: pg_list.h:45
static List * OpenTableList(List *tables)
void RemovePublicationById ( Oid  pubid)

Definition at line 452 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().

453 {
454  Relation rel;
455  HeapTuple tup;
456 
458 
460 
461  if (!HeapTupleIsValid(tup))
462  elog(ERROR, "cache lookup failed for publication %u", pubid);
463 
464  CatalogTupleDelete(rel, &tup->t_self);
465 
466  ReleaseSysCache(tup);
467 
469 }
#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:149
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#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:1083
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define elog
Definition: elog.h:219
void RemovePublicationRelById ( Oid  proid)

Definition at line 475 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().

476 {
477  Relation rel;
478  HeapTuple tup;
480 
482 
484 
485  if (!HeapTupleIsValid(tup))
486  elog(ERROR, "cache lookup failed for publication table %u",
487  proid);
488 
489  pubrel = (Form_pg_publication_rel) GETSTRUCT(tup);
490 
491  /* Invalidate relcache so that publication info is rebuilt. */
492  CacheInvalidateRelcacheByRelid(pubrel->prrelid);
493 
494  CatalogTupleDelete(rel, &tup->t_self);
495 
496  ReleaseSysCache(tup);
497 
499 }
#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:149
#define PublicationRelRelationId
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#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:1284
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
FormData_pg_publication_rel * Form_pg_publication_rel
#define elog
Definition: elog.h:219