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 all
39  * 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:493
char* get_publication_name ( Oid  pubid)

Definition at line 398 of file pg_publication.c.

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

Referenced by getObjectDescription(), and getObjectIdentityParts().

399 {
400  HeapTuple tup;
401  char *pubname;
402  Form_pg_publication pubform;
403 
405 
406  if (!HeapTupleIsValid(tup))
407  elog(ERROR, "cache lookup failed for publication %u", pubid);
408 
409  pubform = (Form_pg_publication) GETSTRUCT(tup);
410  pubname = pstrdup(NameStr(pubform->pubname));
411 
412  ReleaseSysCache(tup);
413 
414  return pubname;
415 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NameStr(name)
Definition: c.h:499
#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 382 of file pg_publication.c.

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

Referenced by get_object_address_unqualified().

383 {
384  Oid oid;
385 
387  if (!OidIsValid(oid) && !missing_ok)
388  ereport(ERROR,
389  (errcode(ERRCODE_UNDEFINED_OBJECT),
390  errmsg("publication \"%s\" does not exist", pubname)));
391  return oid;
392 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:183
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
List* GetAllTablesPublicationRelations ( void  )

Definition at line 288 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, result, and ScanKeyInit().

Referenced by pg_get_publication_tables().

289 {
290  Relation classRel;
291  ScanKeyData key[1];
292  HeapScanDesc scan;
293  HeapTuple tuple;
294  List *result = NIL;
295 
297 
298  ScanKeyInit(&key[0],
300  BTEqualStrategyNumber, F_CHAREQ,
302 
303  scan = heap_beginscan_catalog(classRel, 1, key);
304 
305  while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
306  {
307  Oid relid = HeapTupleGetOid(tuple);
308  Form_pg_class relForm = (Form_pg_class) GETSTRUCT(tuple);
309 
310  if (is_publishable_class(relid, relForm))
311  result = lappend_oid(result, relid);
312  }
313 
314  heap_endscan(scan);
315  heap_close(classRel, AccessShareLock);
316 
317  return result;
318 }
#define NIL
Definition: pg_list.h:69
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1578
#define RelationRelationId
Definition: pg_class.h:29
#define AccessShareLock
Definition: lockdefs.h:36
return result
Definition: formatting.c:1632
#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:1399
HeapTuple heap_getnext(HeapScanDesc scan, ScanDirection direction)
Definition: heapam.c:1794
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define NULL
Definition: c.h:229
#define CharGetDatum(X)
Definition: postgres.h:422
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 255 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, result, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by GetRelationPublicationActions().

256 {
257  List *result;
258  Relation rel;
259  ScanKeyData scankey;
260  SysScanDesc scan;
261  HeapTuple tup;
262 
263  /* Find all publications that are marked as for all tables. */
265 
266  ScanKeyInit(&scankey,
268  BTEqualStrategyNumber, F_BOOLEQ,
269  BoolGetDatum(true));
270 
271  scan = systable_beginscan(rel, InvalidOid, false,
272  NULL, 1, &scankey);
273 
274  result = NIL;
275  while (HeapTupleIsValid(tup = systable_getnext(scan)))
276  result = lappend_oid(result, HeapTupleGetOid(tup));
277 
278  systable_endscan(scan);
280 
281  return result;
282 }
#define NIL
Definition: pg_list.h:69
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define AccessShareLock
Definition: lockdefs.h:36
#define PublicationRelationId
return result
Definition: formatting.c:1632
#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:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define BoolGetDatum(X)
Definition: postgres.h:408
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#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 326 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().

327 {
328  HeapTuple tup;
329  Publication *pub;
330  Form_pg_publication pubform;
331 
333 
334  if (!HeapTupleIsValid(tup))
335  elog(ERROR, "cache lookup failed for publication %u", pubid);
336 
337  pubform = (Form_pg_publication) GETSTRUCT(tup);
338 
339  pub = (Publication *) palloc(sizeof(Publication));
340  pub->oid = pubid;
341  pub->name = pstrdup(NameStr(pubform->pubname));
342  pub->alltables = pubform->puballtables;
343  pub->pubactions.pubinsert = pubform->pubinsert;
344  pub->pubactions.pubupdate = pubform->pubupdate;
345  pub->pubactions.pubdelete = pubform->pubdelete;
346 
347  ReleaseSysCache(tup);
348 
349  return pub;
350 }
PublicationActions pubactions
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char * pstrdup(const char *in)
Definition: mcxt.c:1077
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
void * palloc(Size size)
Definition: mcxt.c:849
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
FormData_pg_publication * Form_pg_publication
Publication* GetPublicationByName ( const char *  pubname,
bool  missing_ok 
)

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

358 {
359  Oid oid;
360 
362  if (!OidIsValid(oid))
363  {
364  if (missing_ok)
365  return NULL;
366 
367  ereport(ERROR,
368  (errcode(ERRCODE_UNDEFINED_OBJECT),
369  errmsg("publication \"%s\" does not exist", pubname)));
370  }
371 
372  return GetPublication(oid);
373 }
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define GetSysCacheOid1(cacheId, key1)
Definition: syscache.h:183
Publication * GetPublication(Oid pubid)
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:584
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
List* GetPublicationRelations ( Oid  pubid)

Definition at line 216 of file pg_publication.c.

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

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

217 {
218  List *result;
219  Relation pubrelsrel;
220  ScanKeyData scankey;
221  SysScanDesc scan;
222  HeapTuple tup;
223 
224  /* Find all publications associated with the relation. */
226 
227  ScanKeyInit(&scankey,
229  BTEqualStrategyNumber, F_OIDEQ,
230  ObjectIdGetDatum(pubid));
231 
233  true, NULL, 1, &scankey);
234 
235  result = NIL;
236  while (HeapTupleIsValid(tup = systable_getnext(scan)))
237  {
239 
240  pubrel = (Form_pg_publication_rel) GETSTRUCT(tup);
241 
242  result = lappend_oid(result, pubrel->prrelid);
243  }
244 
245  systable_endscan(scan);
246  heap_close(pubrelsrel, AccessShareLock);
247 
248  return result;
249 }
#define NIL
Definition: pg_list.h:69
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define AccessShareLock
Definition: lockdefs.h:36
return result
Definition: formatting.c:1632
#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:328
#define PublicationRelRelationId
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define Anum_pg_publication_rel_prpubid
#define PublicationRelPrrelidPrpubidIndexId
Definition: indexing.h:351
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
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 187 of file pg_publication.c.

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

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

188 {
189  List *result = NIL;
190  CatCList *pubrellist;
191  int i;
192 
193  /* Find all publications associated with the relation. */
195  ObjectIdGetDatum(relid));
196  for (i = 0; i < pubrellist->n_members; i++)
197  {
198  HeapTuple tup = &pubrellist->members[i]->tuple;
199  Oid pubid = ((Form_pg_publication_rel) GETSTRUCT(tup))->prpubid;
200 
201  result = lappend_oid(result, pubid);
202  }
203 
204  ReleaseSysCacheList(pubrellist);
205 
206  return result;
207 }
#define NIL
Definition: pg_list.h:69
int n_members
Definition: catcache.h:154
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
return result
Definition: formatting.c:1632
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:513
#define SearchSysCacheList1(cacheId, key1)
Definition: syscache.h:201
#define ReleaseSysCacheList(x)
Definition: syscache.h:210
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 421 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.

422 {
423  FuncCallContext *funcctx;
424  char *pubname = text_to_cstring(PG_GETARG_TEXT_PP(0));
425  Publication *publication;
426  List *tables;
427  ListCell **lcp;
428 
429  /* stuff done only on the first call of the function */
430  if (SRF_IS_FIRSTCALL())
431  {
432  MemoryContext oldcontext;
433 
434  /* create a function context for cross-call persistence */
435  funcctx = SRF_FIRSTCALL_INIT();
436 
437  /* switch to memory context appropriate for multiple function calls */
438  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
439 
440  publication = GetPublicationByName(pubname, false);
441  if (publication->alltables)
443  else
444  tables = GetPublicationRelations(publication->oid);
445  lcp = (ListCell **) palloc(sizeof(ListCell *));
446  *lcp = list_head(tables);
447  funcctx->user_fctx = (void *) lcp;
448 
449  MemoryContextSwitchTo(oldcontext);
450  }
451 
452  /* stuff done on every call of the function */
453  funcctx = SRF_PERCALL_SETUP();
454  lcp = (ListCell **) funcctx->user_fctx;
455 
456  while (*lcp != NULL)
457  {
458  Oid relid = lfirst_oid(*lcp);
459 
460  *lcp = lnext(*lcp);
461  SRF_RETURN_NEXT(funcctx, ObjectIdGetDatum(relid));
462  }
463 
464  SRF_RETURN_DONE(funcctx);
465 }
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:273
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
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:229
List * GetPublicationRelations(Oid pubid)
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
char * text_to_cstring(const text *t)
Definition: varlena.c:182
void * user_fctx
Definition: funcapi.h:90
void * palloc(Size size)
Definition: mcxt.c:849
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 112 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().

114 {
115  Relation rel;
116  HeapTuple tup;
118  bool nulls[Natts_pg_publication_rel];
119  Oid relid = RelationGetRelid(targetrel);
120  Oid prrelid;
121  Publication *pub = GetPublication(pubid);
122  ObjectAddress myself,
123  referenced;
124 
126 
127  /*
128  * Check for duplicates. Note that this does not really prevent
129  * duplicates, it's here just to provide nicer error message in common
130  * case. The real protection is the unique key on the catalog.
131  */
133  ObjectIdGetDatum(pubid)))
134  {
136 
137  if (if_not_exists)
138  return InvalidObjectAddress;
139 
140  ereport(ERROR,
142  errmsg("relation \"%s\" is already member of publication \"%s\"",
143  RelationGetRelationName(targetrel), pub->name)));
144  }
145 
147 
148  /* Form a tuple. */
149  memset(values, 0, sizeof(values));
150  memset(nulls, false, sizeof(nulls));
151 
152  values[Anum_pg_publication_rel_prpubid - 1] =
153  ObjectIdGetDatum(pubid);
154  values[Anum_pg_publication_rel_prrelid - 1] =
155  ObjectIdGetDatum(relid);
156 
157  tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
158 
159  /* Insert tuple into catalog. */
160  prrelid = CatalogTupleInsert(rel, tup);
161  heap_freetuple(tup);
162 
163  ObjectAddressSet(myself, PublicationRelRelationId, prrelid);
164 
165  /* Add dependency on the publication */
166  ObjectAddressSet(referenced, PublicationRelationId, pubid);
167  recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
168 
169  /* Add dependency on the relation */
170  ObjectAddressSet(referenced, RelationRelationId, relid);
171  recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
172 
173  /* Close the table. */
175 
176  /* Invalidate relcache so that publication info is rebuilt. */
177  CacheInvalidateRelcache(targetrel);
178 
179  return myself;
180 }
#define RelationGetDescr(relation)
Definition: rel.h:429
#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:1372
unsigned int Oid
Definition: postgres_ext.h:31
#define PublicationRelRelationId
Publication * GetPublication(Oid pubid)
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#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:437
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition: syscache.h:176
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void CacheInvalidateRelcache(Relation relation)
Definition: inval.c:1233
static Datum values[MAXATTR]
Definition: bootstrap.c:163
const ObjectAddress InvalidObjectAddress
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define Natts_pg_publication_rel
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:31
#define RelationGetRelid(relation)
Definition: rel.h:417

Variable Documentation

FormData_pg_publication

Definition at line 52 of file pg_publication.h.