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

Commitf077070

Browse files
author
Amit Kapila
committed
Display the names of missing columns in error during logical replication.
In logical replication when a subscriber is missing some columns, itcurrently emits an error message that says "some" columns are missing, butit doesn't specify the missing column names. Change that to displaymissing column names which makes an error to be more informative to theuser.We have decided not to backpatch this commit as this is a minor usabilityimprovement and no user has reported this.Reported-by: Bharath RupireddyAuthor: Bharath RupireddyReviewed-by: Kyotaro Horiguchi and Amit KapilaDiscussion:https://postgr.es/m/CALj2ACVkW-EXH_4pmBK8tNeHRz5ksUC4WddGactuCjPiBch-cg@mail.gmail.com
1 parent0691797 commitf077070

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

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

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,43 @@ logicalrep_rel_att_by_name(LogicalRepRelation *remoterel, const char *attname)
228228
return-1;
229229
}
230230

231+
/*
232+
* Report error with names of the missing local relation column(s), if any.
233+
*/
234+
staticvoid
235+
logicalrep_report_missing_attrs(LogicalRepRelation*remoterel,
236+
Bitmapset*missingatts)
237+
{
238+
if (!bms_is_empty(missingatts))
239+
{
240+
StringInfoDatamissingattsbuf;
241+
intmissingattcnt=0;
242+
inti;
243+
244+
initStringInfo(&missingattsbuf);
245+
246+
while ((i=bms_first_member(missingatts)) >=0)
247+
{
248+
missingattcnt++;
249+
if (missingattcnt==1)
250+
appendStringInfo(&missingattsbuf,_("\"%s\""),
251+
remoterel->attnames[i]);
252+
else
253+
appendStringInfo(&missingattsbuf,_(", \"%s\""),
254+
remoterel->attnames[i]);
255+
}
256+
257+
ereport(ERROR,
258+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
259+
errmsg_plural("logical replication target relation \"%s.%s\" is missing replicated column: %s",
260+
"logical replication target relation \"%s.%s\" is missing replicated columns: %s",
261+
missingattcnt,
262+
remoterel->nspname,
263+
remoterel->relname,
264+
missingattsbuf.data)));
265+
}
266+
}
267+
231268
/*
232269
* Open the local relation associated with the remote one.
233270
*
@@ -286,11 +323,11 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
286323
if (!entry->localrelvalid)
287324
{
288325
Oidrelid;
289-
intfound;
290326
Bitmapset*idkey;
291327
TupleDescdesc;
292328
MemoryContextoldctx;
293329
inti;
330+
Bitmapset*missingatts;
294331

295332
/* Try to find and lock the relation by name. */
296333
relid=RangeVarGetRelid(makeRangeVar(remoterel->nspname,
@@ -318,7 +355,8 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
318355
entry->attrmap=make_attrmap(desc->natts);
319356
MemoryContextSwitchTo(oldctx);
320357

321-
found=0;
358+
/* check and report missing attrs, if any */
359+
missingatts=bms_add_range(NULL,0,remoterel->natts-1);
322360
for (i=0;i<desc->natts;i++)
323361
{
324362
intattnum;
@@ -335,16 +373,13 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
335373

336374
entry->attrmap->attnums[i]=attnum;
337375
if (attnum >=0)
338-
found++;
376+
missingatts=bms_del_member(missingatts,attnum);
339377
}
340378

341-
/* TODO, detail message with names of missing columns */
342-
if (found<remoterel->natts)
343-
ereport(ERROR,
344-
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
345-
errmsg("logical replication target relation \"%s.%s\" is missing "
346-
"some replicated columns",
347-
remoterel->nspname,remoterel->relname)));
379+
logicalrep_report_missing_attrs(remoterel,missingatts);
380+
381+
/* be tidy */
382+
bms_free(missingatts);
348383

349384
/*
350385
* Check that replica identity matches. We allow for stricter replica

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp