PostgreSQL Source Code git master
|
#include "postgres.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_authid_d.h"
#include "catalog/pg_database_d.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_subscription_rel.h"
#include "catalog/pg_type.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/subscriptioncmds.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "pgstat.h"
#include "replication/logicallauncher.h"
#include "replication/logicalworker.h"
#include "replication/origin.h"
#include "replication/slot.h"
#include "replication/walreceiver.h"
#include "replication/walsender.h"
#include "replication/worker_internal.h"
#include "storage/lmgr.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_lsn.h"
#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
struct | SubOpts |
Macros | |
#define | SUBOPT_CONNECT 0x00000001 |
#define | SUBOPT_ENABLED 0x00000002 |
#define | SUBOPT_CREATE_SLOT 0x00000004 |
#define | SUBOPT_SLOT_NAME 0x00000008 |
#define | SUBOPT_COPY_DATA 0x00000010 |
#define | SUBOPT_SYNCHRONOUS_COMMIT 0x00000020 |
#define | SUBOPT_REFRESH 0x00000040 |
#define | SUBOPT_BINARY 0x00000080 |
#define | SUBOPT_STREAMING 0x00000100 |
#define | SUBOPT_TWOPHASE_COMMIT 0x00000200 |
#define | SUBOPT_DISABLE_ON_ERR 0x00000400 |
#define | SUBOPT_PASSWORD_REQUIRED 0x00000800 |
#define | SUBOPT_RUN_AS_OWNER 0x00001000 |
#define | SUBOPT_FAILOVER 0x00002000 |
#define | SUBOPT_LSN 0x00004000 |
#define | SUBOPT_ORIGIN 0x00008000 |
#define | IsSet(val, bits) (((val) & (bits)) == (bits)) |
Typedefs | |
typedef struct SubOpts | SubOpts |
Functions | |
static List * | fetch_table_list (WalReceiverConn *wrconn, List *publications) |
static void | check_publications_origin (WalReceiverConn *wrconn, List *publications, bool copydata, char *origin, Oid *subrel_local_oids, int subrel_count, char *subname) |
static void | check_duplicates_in_publist (List *publist, Datum *datums) |
static List * | merge_publications (List *oldpublist, List *newpublist, bool addpub, const char *subname) |
static void | ReportSlotConnectionError (List *rstates, Oid subid, char *slotname, char *err) |
static void | CheckAlterSubOption (Subscription *sub, const char *option, bool slot_needs_update, bool isTopLevel) |
static void | parse_subscription_options (ParseState *pstate, List *stmt_options, bits32 supported_opts, SubOpts *opts) |
static void | check_publications (WalReceiverConn *wrconn, List *publications) |
static Datum | publicationListToArray (List *publist) |
ObjectAddress | CreateSubscription (ParseState *pstate, CreateSubscriptionStmt *stmt, bool isTopLevel) |
static void | AlterSubscription_refresh (Subscription *sub, bool copy_data, List *validate_publications) |
ObjectAddress | AlterSubscription (ParseState *pstate, AlterSubscriptionStmt *stmt, bool isTopLevel) |
void | DropSubscription (DropSubscriptionStmt *stmt, bool isTopLevel) |
void | ReplicationSlotDropAtPubNode (WalReceiverConn *wrconn, char *slotname, bool missing_ok) |
static void | AlterSubscriptionOwner_internal (Relation rel, HeapTuple tup, Oid newOwnerId) |
ObjectAddress | AlterSubscriptionOwner (const char *name, Oid newOwnerId) |
void | AlterSubscriptionOwner_oid (Oid subid, Oid newOwnerId) |
char | defGetStreamingMode (DefElem *def) |
Definition at line 78 of file subscriptioncmds.c.
#define SUBOPT_BINARY 0x00000080 |
Definition at line 67 of file subscriptioncmds.c.
#define SUBOPT_CONNECT 0x00000001 |
Definition at line 60 of file subscriptioncmds.c.
#define SUBOPT_COPY_DATA 0x00000010 |
Definition at line 64 of file subscriptioncmds.c.
#define SUBOPT_CREATE_SLOT 0x00000004 |
Definition at line 62 of file subscriptioncmds.c.
#define SUBOPT_DISABLE_ON_ERR 0x00000400 |
Definition at line 70 of file subscriptioncmds.c.
#define SUBOPT_ENABLED 0x00000002 |
Definition at line 61 of file subscriptioncmds.c.
#define SUBOPT_FAILOVER 0x00002000 |
Definition at line 73 of file subscriptioncmds.c.
#define SUBOPT_LSN 0x00004000 |
Definition at line 74 of file subscriptioncmds.c.
#define SUBOPT_ORIGIN 0x00008000 |
Definition at line 75 of file subscriptioncmds.c.
#define SUBOPT_PASSWORD_REQUIRED 0x00000800 |
Definition at line 71 of file subscriptioncmds.c.
#define SUBOPT_REFRESH 0x00000040 |
Definition at line 66 of file subscriptioncmds.c.
#define SUBOPT_RUN_AS_OWNER 0x00001000 |
Definition at line 72 of file subscriptioncmds.c.
#define SUBOPT_SLOT_NAME 0x00000008 |
Definition at line 63 of file subscriptioncmds.c.
#define SUBOPT_STREAMING 0x00000100 |
Definition at line 68 of file subscriptioncmds.c.
#define SUBOPT_SYNCHRONOUS_COMMIT 0x00000020 |
Definition at line 65 of file subscriptioncmds.c.
#define SUBOPT_TWOPHASE_COMMIT 0x00000200 |
Definition at line 69 of file subscriptioncmds.c.
ObjectAddress AlterSubscription | ( | ParseState * | pstate, |
AlterSubscriptionStmt * | stmt, | ||
bool | isTopLevel | ||
) |
Definition at line 1100 of file subscriptioncmds.c.
References AccessExclusiveLock, aclcheck_error(), ACLCHECK_NOT_OWNER, ALTER_SUBSCRIPTION_ADD_PUBLICATION, ALTER_SUBSCRIPTION_CONNECTION, ALTER_SUBSCRIPTION_DROP_PUBLICATION, ALTER_SUBSCRIPTION_ENABLED, ALTER_SUBSCRIPTION_OPTIONS, ALTER_SUBSCRIPTION_REFRESH, ALTER_SUBSCRIPTION_SET_PUBLICATION, ALTER_SUBSCRIPTION_SKIP, AlterSubscription_refresh(), ApplyLauncherWakeupAtCommit(), Assert, BoolGetDatum(), CatalogTupleUpdate(), CharGetDatum(), CheckAlterSubOption(), Subscription::conninfo, CStringGetDatum(), CStringGetTextDatum, DirectFunctionCall1, elog, Subscription::enabled, ereport, err(), errcode(), errhint(), errmsg(), ERROR, GETSTRUCT, GetSubscription(), GetUserId(), heap_freetuple(), heap_modify_tuple(), HeapTupleIsValid, if(), InvalidOid, InvokeObjectPostAlterHook, IsSet, load_file(), LockSharedObject(), logicalrep_workers_find(), LogicalRepWorkersWakeupAtCommit(), LookupGXactBySubid(), LSN_FORMAT_ARGS, LSNGetDatum(), merge_publications(), MyDatabaseId, Subscription::name, NAMEDATALEN, namein(), object_ownercheck(), OBJECT_SUBSCRIPTION, ObjectAddressSet, opts, Subscription::ownersuperuser, parse_subscription_options(), Subscription::passwordrequired, PG_END_TRY, PG_FINALLY, PG_TRY, PreventInTransactionBlock(), publicationListToArray(), Subscription::publications, RelationGetDescr, ReplicationOriginNameForLogicalRep(), replorigin_by_name(), replorigin_get_progress(), RowExclusiveLock, SearchSysCacheCopy2, Subscription::slotname, stmt, SUBOPT_BINARY, SUBOPT_COPY_DATA, SUBOPT_DISABLE_ON_ERR, SUBOPT_ENABLED, SUBOPT_FAILOVER, SUBOPT_LSN, SUBOPT_ORIGIN, SUBOPT_PASSWORD_REQUIRED, SUBOPT_REFRESH, SUBOPT_RUN_AS_OWNER, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBOPT_TWOPHASE_COMMIT, superuser(), HeapTupleData::t_self, table_close(), table_open(), Subscription::twophasestate, values, walrcv_alter_slot, walrcv_check_conninfo, walrcv_connect, walrcv_disconnect, wrconn, and XLogRecPtrIsInvalid.
Referenced by ProcessUtilitySlow().
|
static |
Definition at line 820 of file subscriptioncmds.c.
References AccessExclusiveLock, AccessShareLock, AddSubscriptionRelState(), check_publications(), check_publications_origin(), CheckSubscriptionRelkind(), Subscription::conninfo, DEBUG1, ereport, err(), errcode(), errmsg(), errmsg_internal(), ERROR, fetch_table_list(), get_namespace_name(), get_rel_name(), get_rel_namespace(), get_rel_relkind(), GetSubscriptionRelations(), GetSubscriptionRelState(), InvalidXLogRecPtr, lfirst, list_length(), load_file(), logicalrep_worker_stop(), Subscription::name, NAMEDATALEN, NoLock, Subscription::oid, oid_cmp(), Subscription::origin, Subscription::ownersuperuser, palloc(), Subscription::passwordrequired, PG_END_TRY, PG_FINALLY, PG_TRY, Subscription::publications, qsort, RangeVarGetRelid, SubscriptionRelState::relid, RangeVar::relname, RemoveSubscriptionRel(), ReplicationOriginNameForLogicalRep(), ReplicationSlotDropAtPubNode(), ReplicationSlotNameForTablesync(), replorigin_drop_by_name(), RangeVar::schemaname, table_close(), table_open(), walrcv_connect, walrcv_disconnect, and wrconn.
Referenced by AlterSubscription().
ObjectAddress AlterSubscriptionOwner | ( | const char * | name, |
Oid | newOwnerId | ||
) |
Definition at line 2028 of file subscriptioncmds.c.
References AlterSubscriptionOwner_internal(), CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, GETSTRUCT, heap_freetuple(), HeapTupleIsValid, MyDatabaseId, name, ObjectAddressSet, RowExclusiveLock, SearchSysCacheCopy2, table_close(), and table_open().
Referenced by ExecAlterOwnerStmt().
Definition at line 1968 of file subscriptioncmds.c.
References ACL_CREATE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, ApplyLauncherWakeupAtCommit(), CatalogTupleUpdate(), changeDependencyOnOwner(), check_can_set_role(), ereport, errcode(), errhint(), errmsg(), ERROR, get_database_name(), GETSTRUCT, GetUserId(), InvokeObjectPostAlterHook, LogicalRepWorkersWakeupAtCommit(), MyDatabaseId, NameStr, object_aclcheck(), OBJECT_DATABASE, object_ownercheck(), OBJECT_SUBSCRIPTION, superuser(), and HeapTupleData::t_self.
Referenced by AlterSubscriptionOwner(), and AlterSubscriptionOwner_oid().
Definition at line 2064 of file subscriptioncmds.c.
References AlterSubscriptionOwner_internal(), ereport, errcode(), errmsg(), ERROR, heap_freetuple(), HeapTupleIsValid, ObjectIdGetDatum(), RowExclusiveLock, SearchSysCacheCopy1, table_close(), and table_open().
Referenced by shdepReassignOwned_Owner().
Definition at line 2357 of file subscriptioncmds.c.
References CStringGetTextDatum, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, j, lfirst, name, and strVal.
Referenced by merge_publications(), and publicationListToArray().
|
static |
Definition at line 446 of file subscriptioncmds.c.
References appendStringInfoChar(), appendStringInfoString(), Assert, StringInfoData::data, destroyStringInfo(), ereport, errcode(), errmsg(), errmsg_plural(), ERROR, ExecClearTuple(), ExecDropSingleTupleTableSlot(), GetPublicationsStr(), list_copy(), list_delete(), list_length(), MakeSingleTupleTableSlot(), makeString(), makeStringInfo(), NIL, res, slot_getattr(), TextDatumGetCString, TTSOpsMinimalTuple, tuplestore_gettupleslot(), walrcv_clear_result(), walrcv_exec, WALRCV_OK_TUPLES, WARNING, and wrconn.
Referenced by AlterSubscription_refresh(), and CreateSubscription().
|
static |
Definition at line 2100 of file subscriptioncmds.c.
References appendStringInfo(), appendStringInfoString(), Assert, StringInfoData::data, ereport, errcode(), errdetail_plural(), errhint(), errmsg(), ERROR, ExecClearTuple(), ExecDropSingleTupleTableSlot(), get_namespace_name(), get_rel_name(), get_rel_namespace(), GetPublicationsStr(), i, initStringInfo(), list_append_unique(), list_length(), MakeSingleTupleTableSlot(), makeString(), makeStringInfo(), NIL, pfree(), pg_strcasecmp(), res, slot_getattr(), subname, TextDatumGetCString, TTSOpsMinimalTuple, tuplestore_gettupleslot(), walrcv_clear_result(), walrcv_exec, WALRCV_OK_TUPLES, WARNING, and wrconn.
Referenced by AlterSubscription_refresh(), and CreateSubscription().
|
static |
Definition at line 1046 of file subscriptioncmds.c.
References appendStringInfo(), Assert, StringInfoData::data, Subscription::enabled, ereport, errcode(), errmsg(), ERROR, initStringInfo(), pfree(), PreventInTransactionBlock(), and Subscription::slotname.
Referenced by AlterSubscription().
ObjectAddress CreateSubscription | ( | ParseState * | pstate, |
CreateSubscriptionStmt * | stmt, | ||
bool | isTopLevel | ||
) |
Definition at line 539 of file subscriptioncmds.c.
References AccessShareLock, ACL_CREATE, aclcheck_error(), ACLCHECK_OK, AddSubscriptionRelState(), ApplyLauncherWakeupAtCommit(), Assert, BoolGetDatum(), CatalogTupleInsert(), CharGetDatum(), check_publications(), check_publications_origin(), CheckSubscriptionRelkind(), CRS_NOEXPORT_SNAPSHOT, CStringGetDatum(), CStringGetTextDatum, DirectFunctionCall1, elog, ereport, err(), errcode(), ERRCODE_DUPLICATE_OBJECT, errdetail(), errhint(), errmsg(), ERROR, fetch_table_list(), get_database_name(), get_rel_relkind(), GetNewOidWithIndex(), GetSysCacheOid2, GetUserId(), has_privs_of_role(), heap_form_tuple(), heap_freetuple(), InvalidOid, InvalidXLogRecPtr, InvokeObjectPostCreateHook, IsSet, lfirst, load_file(), LSNGetDatum(), MyDatabaseId, NAMEDATALEN, namein(), NIL, NOTICE, object_aclcheck(), OBJECT_DATABASE, ObjectAddressSet, ObjectIdGetDatum(), OidIsValid, opts, parse_subscription_options(), PG_END_TRY, PG_FINALLY, PG_TRY, pgstat_create_subscription(), PreventInTransactionBlock(), publicationListToArray(), RangeVarGetRelid, recordDependencyOnOwner(), RelationGetDescr, RangeVar::relname, ReplicationOriginNameForLogicalRep(), replorigin_create(), RowExclusiveLock, RangeVar::schemaname, stmt, SUBOPT_BINARY, SUBOPT_CONNECT, SUBOPT_COPY_DATA, SUBOPT_CREATE_SLOT, SUBOPT_DISABLE_ON_ERR, SUBOPT_ENABLED, SUBOPT_FAILOVER, SUBOPT_ORIGIN, SUBOPT_PASSWORD_REQUIRED, SUBOPT_RUN_AS_OWNER, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBOPT_TWOPHASE_COMMIT, superuser(), superuser_arg(), table_close(), table_open(), UpdateTwoPhaseState(), values, walrcv_check_conninfo, walrcv_connect, walrcv_create_slot, walrcv_disconnect, WARNING, and wrconn.
Referenced by ProcessUtilitySlow().
char defGetStreamingMode | ( | DefElem * | def | ) |
Definition at line 2456 of file subscriptioncmds.c.
References DefElem::arg, defGetString(), DefElem::defname, ereport, errcode(), errmsg(), ERROR, intVal, nodeTag, and pg_strcasecmp().
Referenced by parse_output_parameters(), and parse_subscription_options().
void DropSubscription | ( | DropSubscriptionStmt * | stmt, |
bool | isTopLevel | ||
) |
Definition at line 1626 of file subscriptioncmds.c.
References AccessExclusiveLock, aclcheck_error(), ACLCHECK_NOT_OWNER, ApplyLauncherForgetWorkerStartTime(), CatalogTupleDelete(), CStringGetDatum(), DatumGetName(), deleteSharedDependencyRecordsFor(), ereport, err(), errcode(), errmsg(), ERROR, EventTriggerSQLDropAddObject(), GETSTRUCT, GetSubscriptionRelations(), GetUserId(), HeapTupleIsValid, InvalidOid, InvokeObjectDropHook, lfirst, list_free(), load_file(), LockSharedObject(), logicalrep_worker_stop(), logicalrep_workers_find(), MyDatabaseId, NAMEDATALEN, NameStr, NIL, NoLock, NOTICE, object_ownercheck(), OBJECT_SUBSCRIPTION, ObjectAddressSet, OidIsValid, PG_END_TRY, PG_FINALLY, PG_TRY, pgstat_drop_subscription(), PreventInTransactionBlock(), pstrdup(), ReleaseSysCache(), SubscriptionRelState::relid, LogicalRepWorker::relid, RemoveSubscriptionRel(), ReplicationOriginNameForLogicalRep(), ReplicationSlotDropAtPubNode(), ReplicationSlotNameForTablesync(), replorigin_drop_by_name(), ReportSlotConnectionError(), SearchSysCache2(), SubscriptionRelState::state, stmt, LogicalRepWorker::subid, subname, superuser_arg(), SysCacheGetAttr(), SysCacheGetAttrNotNull(), HeapTupleData::t_self, table_close(), table_open(), TextDatumGetCString, walrcv_connect, walrcv_disconnect, and wrconn.
Referenced by ProcessUtilitySlow().
|
static |
Definition at line 2206 of file subscriptioncmds.c.
References appendStringInfo(), appendStringInfoString(), Assert, StringInfoData::data, destroyStringInfo(), ereport, errcode(), errmsg(), ERROR, ExecClearTuple(), ExecDropSingleTupleTableSlot(), GetPublicationsStr(), initStringInfo(), InvalidOid, lappend(), list_member(), makeRangeVar(), MakeSingleTupleTableSlot(), makeStringInfo(), NIL, pfree(), relname, res, server_version, slot_getattr(), TextDatumGetCString, TTSOpsMinimalTuple, tuplestore_gettupleslot(), walrcv_clear_result(), walrcv_exec, WALRCV_OK_TUPLES, walrcv_server_version, and wrconn.
Referenced by AlterSubscription_refresh(), and CreateSubscription().
|
static |
Definition at line 2397 of file subscriptioncmds.c.
References check_duplicates_in_publist(), ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, foreach_delete_current, lappend(), lfirst, list_copy(), makeString(), name, strVal, and subname.
Referenced by AlterSubscription().
|
static |
Definition at line 124 of file subscriptioncmds.c.
References Assert, CStringGetDatum(), DatumGetLSN(), defGetBoolean(), defGetStreamingMode(), defGetString(), DefElem::defname, DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, errorConflictingDefElem(), GUC_ACTION_SET, InvalidXLogRecPtr, IsSet, lfirst, opts, pfree(), pg_lsn_in(), pg_strcasecmp(), PGC_BACKEND, PGC_S_TEST, pstrdup(), ReplicationSlotValidateName(), set_config_option(), SUBOPT_BINARY, SUBOPT_CONNECT, SUBOPT_COPY_DATA, SUBOPT_CREATE_SLOT, SUBOPT_DISABLE_ON_ERR, SUBOPT_ENABLED, SUBOPT_FAILOVER, SUBOPT_LSN, SUBOPT_ORIGIN, SUBOPT_PASSWORD_REQUIRED, SUBOPT_REFRESH, SUBOPT_RUN_AS_OWNER, SUBOPT_SLOT_NAME, SUBOPT_STREAMING, SUBOPT_SYNCHRONOUS_COMMIT, SUBOPT_TWOPHASE_COMMIT, and XLogRecPtrIsInvalid.
Referenced by AlterSubscription(), and CreateSubscription().
Definition at line 509 of file subscriptioncmds.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, check_duplicates_in_publist(), construct_array_builtin(), CurrentMemoryContext, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), palloc(), and PointerGetDatum().
Referenced by AlterSubscription(), and CreateSubscription().
void ReplicationSlotDropAtPubNode | ( | WalReceiverConn * | wrconn, |
char * | slotname, | ||
bool | missing_ok | ||
) |
Definition at line 1913 of file subscriptioncmds.c.
References appendStringInfo(), Assert, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, initStringInfo(), load_file(), LOG, NOTICE, pfree(), PG_END_TRY, PG_FINALLY, PG_TRY, quote_identifier(), res, walrcv_clear_result(), WALRCV_ERROR, walrcv_exec, WALRCV_OK_COMMAND, and wrconn.
Referenced by AlterSubscription_refresh(), DropSubscription(), LogicalRepSyncTableStart(), and process_syncing_tables_for_sync().
|
static |
Definition at line 2313 of file subscriptioncmds.c.
References elog, ereport, err(), errcode(), errhint(), errmsg(), ERROR, lfirst, NAMEDATALEN, OidIsValid, SubscriptionRelState::relid, ReplicationSlotNameForTablesync(), SubscriptionRelState::state, and WARNING.
Referenced by DropSubscription().