PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_subscription.h File Reference
#include "access/xlogdefs.h"
#include "catalog/genbki.h"
#include "catalog/pg_subscription_d.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
Include dependency graph for pg_subscription.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Subscription
 

Typedefs

typedef struct Subscription Subscription
 

Functions

BEGIN_CATALOG_STRUCT CATALOG (pg_subscription, 6100, SubscriptionRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101
 
Oid subdbid BKI_LOOKUP (pg_database)
 
Oid subowner BKI_LOOKUP (pg_authid)
 
Oid subserver BKI_LOOKUP_OPT (pg_foreign_server)
 
 DECLARE_TOAST_WITH_MACRO (pg_subscription, 4183, 4184, PgSubscriptionToastTable, PgSubscriptionToastIndex)
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_subscription_oid_index, 6114, SubscriptionObjectIndexId, pg_subscription, btree(oid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_subscription_subname_index, 6115, SubscriptionNameIndexId, pg_subscription, btree(subdbid oid_ops, subname name_ops))
 
 MAKE_SYSCACHE (SUBSCRIPTIONOID, pg_subscription_oid_index, 4)
 
 MAKE_SYSCACHE (SUBSCRIPTIONNAME, pg_subscription_subname_index, 4)
 
SubscriptionGetSubscription (Oid subid, bool missing_ok, bool conninfo_needed, bool conninfo_aclcheck)
 
void DisableSubscription (Oid subid)
 
int CountDBSubscriptions (Oid dbid)
 
void GetPublicationsStr (List *publications, StringInfo dest, bool quote_literal)
 

Variables

END_CATALOG_STRUCT typedef FormData_pg_subscriptionForm_pg_subscription
 
BEGIN_CATALOG_STRUCT SubscriptionRelation_Rowtype_Id BKI_SCHEMA_MACRO
 
XLogRecPtr subskiplsn
 
NameData subname
 
bool subenabled
 
bool subbinary
 
char substream
 
char subtwophasestate
 
bool subdisableonerr
 
bool subpasswordrequired
 
bool subrunasowner
 
bool subfailover
 
bool subretaindeadtuples
 
int32 submaxretention
 
bool subretentionactive
 
Oid subconflictlogrelid
 
 FormData_pg_subscription
 

Typedef Documentation

◆ Subscription

Function Documentation

◆ BKI_LOOKUP() [1/2]

Oid subowner BKI_LOOKUP ( pg_authid  )

◆ BKI_LOOKUP() [2/2]

Oid subdbid BKI_LOOKUP ( pg_database  )

◆ BKI_LOOKUP_OPT()

Oid subserver BKI_LOOKUP_OPT ( pg_foreign_server  )

◆ CATALOG()

◆ CountDBSubscriptions()

int CountDBSubscriptions ( Oid  dbid)
extern

Definition at line 234 of file pg_subscription.c.

235{
236 int nsubs = 0;
237 Relation rel;
239 SysScanDesc scan;
241
243
247 ObjectIdGetDatum(dbid));
248
249 scan = systable_beginscan(rel, InvalidOid, false,
250 NULL, 1, &scankey);
251
252 while (HeapTupleIsValid(tup = systable_getnext(scan)))
253 nsubs++;
254
255 systable_endscan(scan);
256
257 table_close(rel, NoLock);
258
259 return nsubs;
260}
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:604
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:515
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
#define HeapTupleIsValid(tuple)
Definition htup.h:78
#define NoLock
Definition lockdefs.h:34
#define RowExclusiveLock
Definition lockdefs.h:38
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
#define InvalidOid
static int fb(int x)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
#define BTEqualStrategyNumber
Definition stratnum.h:31
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References BTEqualStrategyNumber, fb(), HeapTupleIsValid, InvalidOid, NoLock, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by dropdb().

◆ DECLARE_TOAST_WITH_MACRO()

DECLARE_TOAST_WITH_MACRO ( pg_subscription  ,
4183  ,
4184  ,
PgSubscriptionToastTable  ,
PgSubscriptionToastIndex   
)

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_subscription_subname_index  ,
6115  ,
SubscriptionNameIndexId  ,
pg_subscription  ,
btree(subdbid oid_ops, subname name_ops  
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_subscription_oid_index  ,
6114  ,
SubscriptionObjectIndexId  ,
pg_subscription  ,
btree(oid oid_ops  
)

◆ DisableSubscription()

void DisableSubscription ( Oid  subid)
extern

Definition at line 266 of file pg_subscription.c.

267{
268 Relation rel;
269 bool nulls[Natts_pg_subscription];
273
274 /* Look up the subscription in the catalog */
277
278 if (!HeapTupleIsValid(tup))
279 elog(ERROR, "cache lookup failed for subscription %u", subid);
280
281 /* Must only modify subscriptions belonging to the current database. */
283
285
286 /* Form a new tuple. */
287 memset(values, 0, sizeof(values));
288 memset(nulls, false, sizeof(nulls));
289 memset(replaces, false, sizeof(replaces));
290
291 /* Set the subscription to disabled. */
294
295 /* Update the catalog */
297 replaces);
298 CatalogTupleUpdate(rel, &tup->t_self, tup);
300
301 table_close(rel, NoLock);
302}
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define Assert(condition)
Definition c.h:1002
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
Oid MyDatabaseId
Definition globals.c:96
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition heaptuple.c:1118
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1372
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1088
#define AccessShareLock
Definition lockdefs.h:36
END_CATALOG_STRUCT typedef FormData_pg_subscription * Form_pg_subscription
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
uint64_t Datum
Definition postgres.h:70
#define RelationGetDescr(relation)
Definition rel.h:542
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91

References AccessShareLock, Assert, BoolGetDatum(), CatalogTupleUpdate(), elog, ERROR, fb(), Form_pg_subscription, GETSTRUCT(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, LockSharedObject(), MyDatabaseId, NoLock, ObjectIdGetDatum(), RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy1, table_close(), table_open(), and values.

Referenced by DisableSubscriptionAndExit().

◆ GetPublicationsStr()

void GetPublicationsStr ( List publications,
StringInfo  dest,
bool  quote_literal 
)
extern

Definition at line 50 of file pg_subscription.c.

51{
52 ListCell *lc;
53 bool first = true;
54
55 Assert(publications != NIL);
56
57 foreach(lc, publications)
58 {
59 char *pubname = strVal(lfirst(lc));
60
61 if (quote_literal)
62 {
63 if (!first)
64 appendStringInfoString(dest, ", ");
66 }
67 else
68 {
69 if (first)
70 appendStringInfo(dest, _("\"%s\""), pubname);
71 else
72 appendStringInfo(dest, _(", \"%s\""), pubname);
73 }
74
75 first = false;
76 }
77}
#define _(x)
Definition elog.c:96
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
char * quote_literal_cstr(const char *rawstr)
Definition quote.c:101
Datum quote_literal(PG_FUNCTION_ARGS)
Definition quote.c:76
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
#define strVal(v)
Definition value.h:82

References _, appendStringInfo(), appendStringInfoString(), Assert, fb(), lfirst, NIL, quote_literal(), quote_literal_cstr(), and strVal.

Referenced by check_publications_origin_sequences(), check_publications_origin_tables(), fetch_relation_list(), and fetch_remote_table_info().

◆ GetSubscription()

Subscription * GetSubscription ( Oid  subid,
bool  missing_ok,
bool  conninfo_needed,
bool  conninfo_aclcheck 
)
extern

Definition at line 88 of file pg_subscription.c.

90{
92 Subscription *sub;
94 Datum datum;
95 bool isnull;
96 MemoryContext cxt;
98
100
102
103 if (!HeapTupleIsValid(tup))
104 {
105 if (missing_ok)
106 return NULL;
107
108 elog(ERROR, "cache lookup failed for subscription %u", subid);
109 }
110
111 cxt = AllocSetContextCreate(CurrentMemoryContext, "subscription",
114
116
117 /*
118 * It's only safe to access subscriptions from another database from the
119 * launcher process, which does not call GetSubscription().
120 */
121 Assert(subform->subdbid == MyDatabaseId);
122
124 sub->cxt = cxt;
125 sub->oid = subid;
126 sub->dbid = subform->subdbid;
127 sub->skiplsn = subform->subskiplsn;
128 sub->name = pstrdup(NameStr(subform->subname));
129 sub->owner = subform->subowner;
130 sub->enabled = subform->subenabled;
131 sub->binary = subform->subbinary;
132 sub->stream = subform->substream;
133 sub->twophasestate = subform->subtwophasestate;
134 sub->disableonerr = subform->subdisableonerr;
135 sub->passwordrequired = subform->subpasswordrequired;
136 sub->runasowner = subform->subrunasowner;
137 sub->failover = subform->subfailover;
138 sub->retaindeadtuples = subform->subretaindeadtuples;
139 sub->maxretention = subform->submaxretention;
140 sub->retentionactive = subform->subretentionactive;
141 sub->conflictlogrelid = subform->subconflictlogrelid;
142
143 if (conninfo_needed)
144 {
145 if (OidIsValid(subform->subserver))
146 {
148 ForeignServer *server;
149
150 server = GetForeignServer(subform->subserver);
151
153 {
154 /* recheck ACL if requested */
156 subform->subserver,
157 subform->subowner, ACL_USAGE);
158
159 if (aclresult != ACLCHECK_OK)
162 errmsg("subscription owner \"%s\" does not have permission on foreign server \"%s\"",
163 GetUserNameFromId(subform->subowner, false),
164 server->servername)));
165 }
166
168 server);
169 }
170 else
171 {
173 tup,
175 sub->conninfo = TextDatumGetCString(datum);
176 }
177 }
178
179 /* Get slotname */
181 tup,
183 &isnull);
184 if (!isnull)
185 sub->slotname = pstrdup(NameStr(*DatumGetName(datum)));
186 else
187 sub->slotname = NULL;
188
189 /* Get synccommit */
191 tup,
193 sub->synccommit = TextDatumGetCString(datum);
194
195 /* Get walrcvtimeout */
197 tup,
200
201 /* Get publications */
203 tup,
206
207 /* Get origin */
209 tup,
211 sub->origin = TextDatumGetCString(datum);
212
213 /* Get conflict log destination */
215 tup,
218
219 /* Is the subscription owner a superuser? */
221
223
225
226 return sub;
227}
AclResult
Definition acl.h:183
@ ACLCHECK_OK
Definition acl.h:184
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3902
#define DatumGetArrayTypeP(X)
Definition array.h:261
#define TextDatumGetCString(d)
Definition builtins.h:99
#define NameStr(name)
Definition c.h:894
#define OidIsValid(objectId)
Definition c.h:917
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
#define palloc0_object(type)
Definition fe_memutils.h:90
char * ForeignServerConnectionString(Oid userid, ForeignServer *server)
Definition foreign.c:202
ForeignServer * GetForeignServer(Oid serverid)
Definition foreign.c:114
char * pstrdup(const char *in)
Definition mcxt.c:1910
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_SMALL_SIZES
Definition memutils.h:170
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition miscinit.c:990
static char * errmsg
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
#define ACL_USAGE
Definition parsenodes.h:84
static List * textarray_to_stringlist(ArrayType *textarray)
static Name DatumGetName(Datum X)
Definition postgres.h:393
char * servername
Definition foreign.h:40
MemoryContext cxt
XLogRecPtr skiplsn
bool superuser_arg(Oid roleid)
Definition superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596

References ACL_USAGE, ACLCHECK_OK, ALLOCSET_SMALL_SIZES, AllocSetContextCreate, Assert, Subscription::binary, Subscription::conflictlogdest, Subscription::conflictlogrelid, Subscription::conninfo, CurrentMemoryContext, Subscription::cxt, DatumGetArrayTypeP, DatumGetName(), Subscription::dbid, Subscription::disableonerr, elog, Subscription::enabled, ereport, errcode(), errmsg, ERROR, Subscription::failover, fb(), ForeignServerConnectionString(), Form_pg_subscription, GetForeignServer(), GETSTRUCT(), GetUserNameFromId(), HeapTupleIsValid, Subscription::maxretention, MemoryContextSwitchTo(), MyDatabaseId, Subscription::name, NameStr, object_aclcheck(), ObjectIdGetDatum(), Subscription::oid, OidIsValid, Subscription::origin, Subscription::owner, Subscription::ownersuperuser, palloc0_object, Subscription::passwordrequired, pstrdup(), Subscription::publications, ReleaseSysCache(), Subscription::retaindeadtuples, Subscription::retentionactive, Subscription::runasowner, SearchSysCache1(), ForeignServer::servername, Subscription::skiplsn, Subscription::slotname, Subscription::stream, superuser_arg(), Subscription::synccommit, SysCacheGetAttr(), SysCacheGetAttrNotNull(), textarray_to_stringlist(), TextDatumGetCString, Subscription::twophasestate, and Subscription::walrcvtimeout.

Referenced by AlterSubscription(), InitializeLogRepWorker(), and maybe_reread_subscription().

◆ MAKE_SYSCACHE() [1/2]

MAKE_SYSCACHE ( SUBSCRIPTIONNAME  ,
pg_subscription_subname_index  ,
 
)

◆ MAKE_SYSCACHE() [2/2]

MAKE_SYSCACHE ( SUBSCRIPTIONOID  ,
pg_subscription_oid_index  ,
 
)

Variable Documentation

◆ BKI_SCHEMA_MACRO

Initial value:
{
Oid oid
unsigned int Oid

Definition at line 45 of file pg_subscription.h.

◆ Form_pg_subscription

◆ FormData_pg_subscription

FormData_pg_subscription

Definition at line 125 of file pg_subscription.h.

◆ subbinary

bool subbinary

Definition at line 62 of file pg_subscription.h.

◆ subconflictlogrelid

Oid subconflictlogrelid

Definition at line 98 of file pg_subscription.h.

Referenced by drop_sub_conflict_log_table(), and DropSubscription().

◆ subdisableonerr

bool subdisableonerr

Definition at line 70 of file pg_subscription.h.

◆ subenabled

bool subenabled

Definition at line 59 of file pg_subscription.h.

◆ subfailover

bool subfailover

Definition at line 78 of file pg_subscription.h.

◆ submaxretention

int32 submaxretention

Definition at line 86 of file pg_subscription.h.

◆ subname

◆ subpasswordrequired

bool subpasswordrequired

Definition at line 73 of file pg_subscription.h.

◆ subretaindeadtuples

bool subretaindeadtuples

Definition at line 83 of file pg_subscription.h.

◆ subretentionactive

bool subretentionactive

Definition at line 90 of file pg_subscription.h.

◆ subrunasowner

bool subrunasowner

Definition at line 75 of file pg_subscription.h.

◆ subskiplsn

XLogRecPtr subskiplsn

Definition at line 52 of file pg_subscription.h.

◆ substream

char substream

Definition at line 65 of file pg_subscription.h.

◆ subtwophasestate

char subtwophasestate

Definition at line 68 of file pg_subscription.h.