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

Go to the source code of this file.

Data Structures

struct  PublicationActions
 
struct  Publication
 

Macros

#define PublicationRelationId   6104
 
#define Natts_pg_publication   6
 
#define Anum_pg_publication_pubname   1
 
#define Anum_pg_publication_pubowner   2
 
#define Anum_pg_publication_puballtables   3
 
#define Anum_pg_publication_pubinsert   4
 
#define Anum_pg_publication_pubupdate   5
 
#define Anum_pg_publication_pubdelete   6
 

Typedefs

typedef FormData_pg_publicationForm_pg_publication
 
typedef struct PublicationActions PublicationActions
 
typedef struct Publication Publication
 

Functions

 CATALOG (pg_publication, 6104)
 
PublicationGetPublication (Oid pubid)
 
PublicationGetPublicationByName (const char *pubname, bool missing_ok)
 
ListGetRelationPublications (Oid relid)
 
ListGetPublicationRelations (Oid pubid)
 
ListGetAllTablesPublications (void)
 
ListGetAllTablesPublicationRelations (void)
 
ObjectAddress publication_add_relation (Oid pubid, Relation targetrel, bool if_not_exists)
 
Oid get_publication_oid (const char *pubname, bool missing_ok)
 
char * get_publication_name (Oid pubid)
 
Datum pg_get_publication_tables (PG_FUNCTION_ARGS)
 

Variables

 FormData_pg_publication
 

Macro Definition Documentation

#define Anum_pg_publication_puballtables   3

Definition at line 69 of file pg_publication.h.

Referenced by CreatePublication(), and GetAllTablesPublications().

#define Anum_pg_publication_pubdelete   6

Definition at line 72 of file pg_publication.h.

Referenced by AlterPublicationOptions(), and CreatePublication().

#define Anum_pg_publication_pubinsert   4

Definition at line 70 of file pg_publication.h.

Referenced by AlterPublicationOptions(), and CreatePublication().

#define Anum_pg_publication_pubname   1

Definition at line 67 of file pg_publication.h.

Referenced by CreatePublication().

#define Anum_pg_publication_pubowner   2

Definition at line 68 of file pg_publication.h.

Referenced by CreatePublication().

#define Anum_pg_publication_pubupdate   5

Definition at line 71 of file pg_publication.h.

Referenced by AlterPublicationOptions(), and CreatePublication().

#define Natts_pg_publication   6

Definition at line 66 of file pg_publication.h.

Referenced by AlterPublicationOptions(), and CreatePublication().

Typedef Documentation

Function Documentation

CATALOG ( pg_publication  ,
6104   
)

Definition at line 31 of file pg_publication.h.

32 {
33  NameData pubname; /* name of the publication */
34 
35  Oid pubowner; /* publication owner */
36 
37  /*
38  * indicates that this is special publication which should encompass
39  * all tables in the database (except for the unlogged and temp ones)
40  */
41  bool puballtables;
42 
43  /* true if inserts are published */
44  bool pubinsert;
45 
46  /* true if updates are published */
47  bool pubupdate;
48 
49  /* true if deletes are published */
50  bool pubdelete;
51 
unsigned int Oid
Definition: postgres_ext.h:31
FormData_pg_publication
Definition: c.h:489
char* get_publication_name ( Oid  pubid)

Definition at line 390 of file pg_publication.c.

References elog, ERROR, GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, pstrdup(), PUBLICATIONOID, ReleaseSysCache(), and SearchSysCache1.

Referenced by getObjectDescription(), and getObjectIdentityParts().

391 {
392  HeapTuple tup;
393  char *pubname;
394  Form_pg_publication pubform;
395 
397 
398  if (!HeapTupleIsValid(tup))
399  elog(ERROR, "cache lookup failed for publication %u", pubid);
400 
401  pubform = (Form_pg_publication) GETSTRUCT(tup);
402  pubname = pstrdup(NameStr(pubform->pubname));
403 
404  ReleaseSysCache(tup);
405 
406  return pubname;
407 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1165
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NameStr(name)
Definition: c.h:495
#define elog
Definition: elog.h:219
FormData_pg_publication * Form_pg_publication
Oid get_publication_oid ( const char *  pubname,
bool  missing_ok 
)

Definition at line 374 of file pg_publication.c.

References CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GetSysCacheOid1, OidIsValid, and PUBLICATIONNAME.

Referenced by get_object_address_unqualified().

375 {
376  Oid oid;
377 
379  if (!OidIsValid(oid) && !missing_ok)
380  ereport(ERROR,
381  (errcode(ERRCODE_UNDEFINED_OBJECT),
382  errmsg("publication \"%s\" does not exist", pubname)));
383  return oid;
384 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:176
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:586
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
List* GetAllTablesPublicationRelations ( void  )

Definition at line 280 of file pg_publication.c.

References AccessShareLock, Anum_pg_class_relkind, BTEqualStrategyNumber, CharGetDatum, ForwardScanDirection, GETSTRUCT, heap_beginscan_catalog(), heap_close, heap_endscan(), heap_getnext(), heap_open(), HeapTupleGetOid, is_publishable_class(), lappend_oid(), NIL, NULL, RelationRelationId, RELKIND_RELATION, and ScanKeyInit().

Referenced by pg_get_publication_tables().

281 {
282  Relation classRel;
283  ScanKeyData key[1];
284  HeapScanDesc scan;
285  HeapTuple tuple;
286  List *result = NIL;
287 
289 
290  ScanKeyInit(&key[0],
292  BTEqualStrategyNumber, F_CHAREQ,
294 
295  scan = heap_beginscan_catalog(classRel, 1, key);
296 
297  while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
298  {
299  Oid relid = HeapTupleGetOid(tuple);
300  Form_pg_class relForm = (Form_pg_class) GETSTRUCT(tuple);
301 
302  if (is_publishable_class(relid, relForm))
303  result = lappend_oid(result, relid);
304  }
305 
306  heap_endscan(scan);
307  heap_close(classRel, AccessShareLock);
308 
309  return result;
310 }
#define NIL
Definition: pg_list.h:69
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1581
#define RelationRelationId
Definition: pg_class.h:29
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
#define Anum_pg_class_relkind
Definition: pg_class.h:118
HeapScanDesc heap_beginscan_catalog(Relation relation, int nkeys, ScanKey key)
Definition: heapam.c:1402
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1781
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
#define CharGetDatum(X)
Definition: postgres.h:424
FormData_pg_class * Form_pg_class
Definition: pg_class.h:95
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
static bool is_publishable_class(Oid relid, Form_pg_class reltuple)
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
#define RELKIND_RELATION
Definition: pg_class.h:160
Definition: pg_list.h:45
#define BTEqualStrategyNumber
Definition: stratnum.h:31
List* GetAllTablesPublications ( void  )

Definition at line 247 of file pg_publication.c.

References AccessShareLock, Anum_pg_publication_puballtables, BoolGetDatum, BTEqualStrategyNumber, heap_close, heap_open(), HeapTupleGetOid, HeapTupleIsValid, InvalidOid, lappend_oid(), NIL, NULL, PublicationRelationId, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by GetRelationPublicationActions().

248 {
249  List *result;
250  Relation rel;
251  ScanKeyData scankey;
252  SysScanDesc scan;
253  HeapTuple tup;
254 
255  /* Find all publications that are marked as for all tables. */
257 
258  ScanKeyInit(&scankey,
260  BTEqualStrategyNumber, F_BOOLEQ,
261  BoolGetDatum(true));
262 
263  scan = systable_beginscan(rel, InvalidOid, false,
264  NULL, 1, &scankey);
265 
266  result = NIL;
267  while (HeapTupleIsValid(tup = systable_getnext(scan)))
268  result = lappend_oid(result, HeapTupleGetOid(tup));
269 
270  systable_endscan(scan);
272 
273  return result;
274 }
#define NIL
Definition: pg_list.h:69
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define AccessShareLock
Definition: lockdefs.h:36
#define PublicationRelationId
#define heap_close(r, l)
Definition: heapam.h:97
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define BoolGetDatum(X)
Definition: postgres.h:410
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define Anum_pg_publication_puballtables
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
Definition: pg_list.h:45
#define BTEqualStrategyNumber
Definition: stratnum.h:31
Publication* GetPublication ( Oid  pubid)

Definition at line 318 of file pg_publication.c.

References Publication::alltables, elog, ERROR, GETSTRUCT, HeapTupleIsValid, Publication::name, NameStr, ObjectIdGetDatum, Publication::oid, palloc(), pstrdup(), Publication::pubactions, PublicationActions::pubdelete, PublicationActions::pubinsert, PUBLICATIONOID, PublicationActions::pubupdate, ReleaseSysCache(), and SearchSysCache1.

Referenced by GetPublicationByName(), and publication_add_relation().

319 {
320  HeapTuple tup;
321  Publication *pub;
322  Form_pg_publication pubform;
323 
325 
326  if (!HeapTupleIsValid(tup))
327  elog(ERROR, "cache lookup failed for publication %u", pubid);
328 
329  pubform = (Form_pg_publication) GETSTRUCT(tup);
330 
331  pub = (Publication *) palloc(sizeof(Publication));
332  pub->oid = pubid;
333  pub->name = pstrdup(NameStr(pubform->pubname));
334  pub->alltables = pubform->puballtables;
335  pub->pubactions.pubinsert = pubform->pubinsert;
336  pub->pubactions.pubupdate = pubform->pubupdate;
337  pub->pubactions.pubdelete = pubform->pubdelete;
338 
339  ReleaseSysCache(tup);
340 
341  return pub;
342 }
PublicationActions pubactions
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1165
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
void * palloc(Size size)
Definition: mcxt.c:891
#define NameStr(name)
Definition: c.h:495
#define elog
Definition: elog.h:219
FormData_pg_publication * Form_pg_publication
Publication* GetPublicationByName ( const char *  pubname,
bool  missing_ok 
)

Definition at line 349 of file pg_publication.c.

References CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GetPublication(), GetSysCacheOid1, NULL, OidIsValid, and PUBLICATIONNAME.

Referenced by get_object_address_publication_rel(), LoadPublications(), and pg_get_publication_tables().

350 {
351  Oid oid;
352 
354  if (!OidIsValid(oid))
355  {
356  if (missing_ok)
357  return NULL;
358 
359  ereport(ERROR,
360  (errcode(ERRCODE_UNDEFINED_OBJECT),
361  errmsg("publication \"%s\" does not exist", pubname)));
362  }
363 
364  return GetPublication(oid);
365 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:176
Publication * GetPublication(Oid pubid)
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:586
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:226
int errmsg(const char *fmt,...)
Definition: elog.c:797
List* GetPublicationRelations ( Oid  pubid)

Definition at line 208 of file pg_publication.c.

References AccessShareLock, Anum_pg_publication_rel_prpubid, BTEqualStrategyNumber, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, lappend_oid(), NIL, NULL, ObjectIdGetDatum, PublicationRelMapIndexId, PublicationRelRelationId, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterPublicationOptions(), AlterPublicationTables(), and pg_get_publication_tables().

209 {
210  List *result;
211  Relation pubrelsrel;
212  ScanKeyData scankey;
213  SysScanDesc scan;
214  HeapTuple tup;
215 
216  /* Find all publications associated with the relation. */
218 
219  ScanKeyInit(&scankey,
221  BTEqualStrategyNumber, F_OIDEQ,
222  ObjectIdGetDatum(pubid));
223 
224  scan = systable_beginscan(pubrelsrel, PublicationRelMapIndexId, true,
225  NULL, 1, &scankey);
226 
227  result = NIL;
228  while (HeapTupleIsValid(tup = systable_getnext(scan)))
229  {
231 
232  pubrel = (Form_pg_publication_rel) GETSTRUCT(tup);
233 
234  result = lappend_oid(result, pubrel->prrelid);
235  }
236 
237  systable_endscan(scan);
238  heap_close(pubrelsrel, AccessShareLock);
239 
240  return result;
241 }
#define NIL
Definition: pg_list.h:69
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define PublicationRelMapIndexId
Definition: indexing.h:344
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
#define PublicationRelRelationId
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define Anum_pg_publication_rel_prpubid
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
FormData_pg_publication_rel * Form_pg_publication_rel
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Definition: pg_list.h:45
#define BTEqualStrategyNumber
Definition: stratnum.h:31
List* GetRelationPublications ( Oid  relid)

Definition at line 179 of file pg_publication.c.

References GETSTRUCT, i, lappend_oid(), catclist::members, catclist::n_members, NIL, ObjectIdGetDatum, PUBLICATIONRELMAP, ReleaseSysCacheList, SearchSysCacheList1, and catctup::tuple.

Referenced by ATPrepChangePersistence(), get_rel_sync_entry(), and GetRelationPublicationActions().

180 {
181  List *result = NIL;
182  CatCList *pubrellist;
183  int i;
184 
185  /* Find all publications associated with the relation. */
187  ObjectIdGetDatum(relid));
188  for (i = 0; i < pubrellist->n_members; i++)
189  {
190  HeapTuple tup = &pubrellist->members[i]->tuple;
191  Oid pubid = ((Form_pg_publication_rel) GETSTRUCT(tup))->prpubid;
192 
193  result = lappend_oid(result, pubid);
194  }
195 
196  ReleaseSysCacheList(pubrellist);
197 
198  return result;
199 }
#define NIL
Definition: pg_list.h:69
int n_members
Definition: catcache.h:154
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
CatCTup * members[FLEXIBLE_ARRAY_MEMBER]
Definition: catcache.h:155
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define SearchSysCacheList1(cacheId, key1)
Definition: syscache.h:194
#define ReleaseSysCacheList(x)
Definition: syscache.h:203
FormData_pg_publication_rel * Form_pg_publication_rel
int i
HeapTupleData tuple
Definition: catcache.h:116
Definition: pg_list.h:45
Datum pg_get_publication_tables ( PG_FUNCTION_ARGS  )

Definition at line 413 of file pg_publication.c.

References Publication::alltables, GetAllTablesPublicationRelations(), GetPublicationByName(), GetPublicationRelations(), lfirst_oid, list_head(), lnext, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, NULL, ObjectIdGetDatum, Publication::oid, palloc(), PG_GETARG_TEXT_PP, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, text_to_cstring(), and FuncCallContext::user_fctx.

414 {
415  FuncCallContext *funcctx;
416  char *pubname = text_to_cstring(PG_GETARG_TEXT_PP(0));
417  Publication *publication;
418  List *tables;
419  ListCell **lcp;
420 
421  /* stuff done only on the first call of the function */
422  if (SRF_IS_FIRSTCALL())
423  {
424  MemoryContext oldcontext;
425 
426  /* create a function context for cross-call persistence */
427  funcctx = SRF_FIRSTCALL_INIT();
428 
429  /* switch to memory context appropriate for multiple function calls */
430  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
431 
432  publication = GetPublicationByName(pubname, false);
433  if (publication->alltables)
435  else
436  tables = GetPublicationRelations(publication->oid);
437  lcp = (ListCell **) palloc(sizeof(ListCell *));
438  *lcp = list_head(tables);
439  funcctx->user_fctx = (void *) lcp;
440 
441  MemoryContextSwitchTo(oldcontext);
442  }
443 
444  /* stuff done on every call of the function */
445  funcctx = SRF_PERCALL_SETUP();
446  lcp = (ListCell **) funcctx->user_fctx;
447 
448  while (*lcp != NULL)
449  {
450  Oid relid = lfirst_oid(*lcp);
451 
452  *lcp = lnext(*lcp);
453  SRF_RETURN_NEXT(funcctx, ObjectIdGetDatum(relid));
454  }
455 
456  SRF_RETURN_DONE(funcctx);
457 }
List * GetAllTablesPublicationRelations(void)
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
unsigned int Oid
Definition: postgres_ext.h:31
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:270
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
#define lnext(lc)
Definition: pg_list.h:105
#define NULL
Definition: c.h:226
List * GetPublicationRelations(Oid pubid)
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
char * text_to_cstring(const text *t)
Definition: varlena.c:184
void * user_fctx
Definition: funcapi.h:90
void * palloc(Size size)
Definition: mcxt.c:891
Definition: pg_list.h:45
#define lfirst_oid(lc)
Definition: pg_list.h:108
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
ObjectAddress publication_add_relation ( Oid  pubid,
Relation  targetrel,
bool  if_not_exists 
)

Definition at line 104 of file pg_publication.c.

References Anum_pg_publication_rel_prpubid, Anum_pg_publication_rel_prrelid, CacheInvalidateRelcache(), CatalogTupleInsert(), check_publication_add_relation(), DEPENDENCY_AUTO, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, GetPublication(), heap_close, heap_form_tuple(), heap_freetuple(), heap_open(), InvalidObjectAddress, Publication::name, Natts_pg_publication_rel, ObjectAddressSet, ObjectIdGetDatum, PublicationRelationId, PUBLICATIONRELMAP, PublicationRelRelationId, recordDependencyOn(), RelationGetDescr, RelationGetRelationName, RelationGetRelid, RelationRelationId, RowExclusiveLock, SearchSysCacheExists2, and values.

Referenced by PublicationAddTables().

106 {
107  Relation rel;
108  HeapTuple tup;
110  bool nulls[Natts_pg_publication_rel];
111  Oid relid = RelationGetRelid(targetrel);
112  Oid prrelid;
113  Publication *pub = GetPublication(pubid);
114  ObjectAddress myself,
115  referenced;
116 
118 
119  /*
120  * Check for duplicates. Note that this does not really prevent
121  * duplicates, it's here just to provide nicer error message in common
122  * case. The real protection is the unique key on the catalog.
123  */
125  ObjectIdGetDatum(pubid)))
126  {
128 
129  if (if_not_exists)
130  return InvalidObjectAddress;
131 
132  ereport(ERROR,
134  errmsg("relation \"%s\" is already member of publication \"%s\"",
135  RelationGetRelationName(targetrel), pub->name)));
136  }
137 
139 
140  /* Form a tuple. */
141  memset(values, 0, sizeof(values));
142  memset(nulls, false, sizeof(nulls));
143 
144  values[Anum_pg_publication_rel_prpubid - 1] =
145  ObjectIdGetDatum(pubid);
146  values[Anum_pg_publication_rel_prrelid - 1] =
147  ObjectIdGetDatum(relid);
148 
149  tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
150 
151  /* Insert tuple into catalog. */
152  prrelid = CatalogTupleInsert(rel, tup);
153  heap_freetuple(tup);
154 
155  ObjectAddressSet(myself, PublicationRelRelationId, prrelid);
156 
157  /* Add dependency on the publication */
158  ObjectAddressSet(referenced, PublicationRelationId, pubid);
159  recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
160 
161  /* Add dependency on the relation */
162  ObjectAddressSet(referenced, RelationRelationId, relid);
163  recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
164 
165  /* Close the table. */
167 
168  /* Invalidate relcache so that publication info is rebuilt. */
169  CacheInvalidateRelcache(targetrel);
170 
171  return myself;
172 }
#define RelationGetDescr(relation)
Definition: rel.h:425
#define RelationRelationId
Definition: pg_class.h:29
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PublicationRelationId
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#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 PublicationRelRelationId
Publication * GetPublication(Oid pubid)
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:162
static void check_publication_add_relation(Relation targetrel)
#define Anum_pg_publication_rel_prpubid
#define Anum_pg_publication_rel_prrelid
#define RowExclusiveLock
Definition: lockdefs.h:38
#define RelationGetRelationName(relation)
Definition: rel.h:433
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:374
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition: syscache.h:169
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void CacheInvalidateRelcache(Relation relation)
Definition: inval.c:1225
static Datum values[MAXATTR]
Definition: bootstrap.c:162
const ObjectAddress InvalidObjectAddress
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define Natts_pg_publication_rel
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:34
#define RelationGetRelid(relation)
Definition: rel.h:413

Variable Documentation

FormData_pg_publication

Definition at line 52 of file pg_publication.h.