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

Commita2141c4

Browse files
committed
Tweak publication fetching in psql
Viewing a table with \d in psql also shows the publications at table isin. If a publication is concurrently dropped, this shows an error,because the view pg_publication_tables internally usespg_get_publication_tables(), which uses a catalog snapshot. This can beparticularly annoying if a for-all-tables publication is concurrentlydropped.To avoid that, write the query in psql differently. Expose the functionpg_relation_is_publishable() to SQL and write the query using that.That still has a risk of being affected by concurrent catalog changes,but in this case it would be a table drop that causes problems, and thenthe psql \d command wouldn't be interesting anymore anyway.Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
1 parent20d7d68 commita2141c4

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

‎src/backend/catalog/pg_publication.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ is_publishable_class(Oid relid, Form_pg_class reltuple)
105105
relid >=FirstNormalObjectId;
106106
}
107107

108+
109+
/*
110+
* SQL-callable variant of the above
111+
*
112+
* This returns null when the relation does not exist. This is intended to be
113+
* used for example in psql to avoid gratuitous errors when there are
114+
* concurrent catalog changes.
115+
*/
116+
Datum
117+
pg_relation_is_publishable(PG_FUNCTION_ARGS)
118+
{
119+
Oidrelid=PG_GETARG_OID(0);
120+
HeapTupletuple;
121+
boolresult;
122+
123+
tuple=SearchSysCache1(RELOID,ObjectIdGetDatum(relid));
124+
if (!tuple)
125+
PG_RETURN_NULL();
126+
result=is_publishable_class(relid, (Form_pg_class)GETSTRUCT(tuple));
127+
ReleaseSysCache(tuple);
128+
PG_RETURN_BOOL(result);
129+
}
130+
131+
108132
/*
109133
* Insert new publication / relation mapping.
110134
*/

‎src/bin/psql/describe.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,12 +2536,16 @@ describeOneTableDetails(const char *schemaname,
25362536
if (pset.sversion >=100000)
25372537
{
25382538
printfPQExpBuffer(&buf,
2539-
"SELECT pub.pubname\n"
2540-
" FROM pg_catalog.pg_publication pub,\n"
2541-
" pg_catalog.pg_get_publication_tables(pub.pubname)\n"
2542-
"WHERE relid = '%s'\n"
2539+
"SELECT pubname\n"
2540+
"FROM pg_catalog.pg_publication p\n"
2541+
"JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
2542+
"WHERE pr.prrelid = '%s'\n"
2543+
"UNION ALL\n"
2544+
"SELECT pubname\n"
2545+
"FROM pg_catalog.pg_publication p\n"
2546+
"WHERE p.puballtables AND pg_relation_is_publishable('%s')\n"
25432547
"ORDER BY 1;",
2544-
oid);
2548+
oid,oid);
25452549

25462550
result=PSQLexec(buf.data);
25472551
if (!result)

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201706201
56+
#defineCATALOG_VERSION_NO201706202
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5436,6 +5436,8 @@ DESCR("get progress for all replication origins");
54365436
/* publications */
54375437
DATA(insert OID = 6119 ( pg_get_publication_tablesPGNSP PGUID 12 1 1000 0 0 f f f f t t s s 1 0 26 "25" "{25,26}" "{i,o}" "{pubname,relid}" _null_ _null_ pg_get_publication_tables _null_ _null_ _null_ ));
54385438
DESCR("get OIDs of tables in a publication");
5439+
DATA(insert OID = 6121 ( pg_relation_is_publishablePGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 16 "2205" _null_ _null_ _null_ _null_ _null_ pg_relation_is_publishable _null_ _null_ _null_ ));
5440+
DESCR("returns whether a relation can be part of a publication");
54395441

54405442
/* rls */
54415443
DATA(insert OID = 3298 ( row_security_active PGNSP PGUID 12 1 0 0 0 f f f f t f s s 1 0 16 "26" _null_ _null_ _null_ _null_ _null_row_security_active _null_ _null_ _null_ ));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp