Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit944dc0f

Browse files
committed
Check relkind of tables in CREATE/ALTER SUBSCRIPTION
We used to only check for a supported relkind on the subscriber duringreplication, which is needed to ensure that the setup is valid and wedon't crash. But it's also useful to tell the user immediately whenCREATE or ALTER SUBSCRIPTION is executed that the relation being addedto the subscription is not of a supported relkind.Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>Reported-by: tushar <tushar.ahuja@enterprisedb.com>
1 parent0fbfb65 commit944dc0f

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

‎src/backend/commands/subscriptioncmds.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include"commands/event_trigger.h"
3434
#include"commands/subscriptioncmds.h"
3535

36+
#include"executor/executor.h"
37+
3638
#include"nodes/makefuncs.h"
3739

3840
#include"replication/logicallauncher.h"
@@ -417,6 +419,10 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
417419

418420
relid=RangeVarGetRelid(rv,AccessShareLock, false);
419421

422+
/* Check for supported relkind. */
423+
CheckSubscriptionRelkind(get_rel_relkind(relid),
424+
rv->schemaname,rv->relname);
425+
420426
SetSubscriptionRelState(subid,relid,table_state,
421427
InvalidXLogRecPtr);
422428
}
@@ -529,6 +535,11 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data)
529535
Oidrelid;
530536

531537
relid=RangeVarGetRelid(rv,AccessShareLock, false);
538+
539+
/* Check for supported relkind. */
540+
CheckSubscriptionRelkind(get_rel_relkind(relid),
541+
rv->schemaname,rv->relname);
542+
532543
pubrel_local_oids[off++]=relid;
533544

534545
if (!bsearch(&relid,subrel_local_oids,

‎src/backend/executor/execReplication.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,23 @@ CheckCmdReplicaIdentity(Relation rel, CmdType cmd)
551551
RelationGetRelationName(rel)),
552552
errhint("To enable deleting from the table, set REPLICA IDENTITY using ALTER TABLE.")));
553553
}
554+
555+
556+
/*
557+
* Check if we support writing into specific relkind.
558+
*
559+
* The nspname and relname are only needed for error reporting.
560+
*/
561+
void
562+
CheckSubscriptionRelkind(charrelkind,constchar*nspname,
563+
constchar*relname)
564+
{
565+
/*
566+
* We currently only support writing to regular tables.
567+
*/
568+
if (relkind!=RELKIND_RELATION)
569+
ereport(ERROR,
570+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
571+
errmsg("logical replication target relation \"%s.%s\" is not a table",
572+
nspname,relname)));
573+
}

‎src/backend/replication/logical/relation.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include"access/sysattr.h"
2121
#include"catalog/namespace.h"
2222
#include"catalog/pg_subscription_rel.h"
23+
#include"executor/executor.h"
2324
#include"nodes/makefuncs.h"
2425
#include"replication/logicalrelation.h"
2526
#include"replication/worker_internal.h"
@@ -258,15 +259,9 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
258259
remoterel->nspname,remoterel->relname)));
259260
entry->localrel=heap_open(relid,NoLock);
260261

261-
/*
262-
* We currently only support writing to regular and partitioned
263-
* tables.
264-
*/
265-
if (entry->localrel->rd_rel->relkind!=RELKIND_RELATION)
266-
ereport(ERROR,
267-
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
268-
errmsg("logical replication target relation \"%s.%s\" is not a table",
269-
remoterel->nspname,remoterel->relname)));
262+
/* Check for supported relkind. */
263+
CheckSubscriptionRelkind(entry->localrel->rd_rel->relkind,
264+
remoterel->nspname,remoterel->relname);
270265

271266
/*
272267
* Build the mapping of local attribute numbers to remote attribute

‎src/include/executor/executor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,5 +535,7 @@ extern void ExecSimpleRelationDelete(EState *estate, EPQState *epqstate,
535535
TupleTableSlot*searchslot);
536536
externvoidCheckCmdReplicaIdentity(Relationrel,CmdTypecmd);
537537

538+
externvoidCheckSubscriptionRelkind(charrelkind,constchar*nspname,
539+
constchar*relname);
538540

539541
#endif/* EXECUTOR_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp