Skip to content

Commit 6f236e1

Browse files
committed
psql: Add tab completion for logical replication
Add tab completion for publications and subscriptions. Also, to be able to get a list of subscriptions, make pg_subscription world-readable but revoke access to subconninfo using column privileges. From: Michael Paquier <michael.paquier@gmail.com>
1 parent 6da9759 commit 6f236e1

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6324,9 +6324,8 @@
63246324
</para>
63256325

63266326
<para>
6327-
Access to this catalog is restricted from normal users. Normal users can
6328-
use the view <xref linkend="pg-stat-subscription"> to get some information
6329-
about subscriptions.
6327+
Access to the column <structfield>subconninfo</structfield> is revoked from
6328+
normal users, because it could contain plain-text passwords.
63306329
</para>
63316330

63326331
<table>

src/backend/catalog/system_views.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,11 @@ CREATE VIEW pg_replication_origin_status AS
900900

901901
REVOKE ALL ON pg_replication_origin_status FROM public;
902902

903+
-- All columns of pg_subscription except subconninfo are readable.
903904
REVOKE ALL ON pg_subscription FROM public;
905+
GRANT SELECT (subdbid, subname, subowner, subenabled, subslotname, subpublications)
906+
ON pg_subscription TO public;
907+
904908

905909
--
906910
-- We have a few function definitions in here, too.

src/bin/psql/tab-complete.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,18 @@ static const SchemaQuery Query_for_list_of_matviews = {
845845
" FROM pg_catalog.pg_am "\
846846
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s'"
847847

848+
#define Query_for_list_of_publications \
849+
" SELECT pg_catalog.quote_ident(pubname) "\
850+
" FROM pg_catalog.pg_publication "\
851+
" WHERE substring(pg_catalog.quote_ident(pubname),1,%d)='%s'"
852+
853+
#define Query_for_list_of_subscriptions \
854+
" SELECT pg_catalog.quote_ident(s.subname) "\
855+
" FROM pg_catalog.pg_subscription s, pg_catalog.pg_database d "\
856+
" WHERE substring(pg_catalog.quote_ident(s.subname),1,%d)='%s' "\
857+
" AND d.datname = pg_catalog.current_database() "\
858+
" AND s.subdbid = d.oid"
859+
848860
/* the silly-looking length condition is just to eat up the current word */
849861
#define Query_for_list_of_arguments \
850862
"SELECT pg_catalog.oidvectortypes(proargtypes)||')' "\
@@ -985,13 +997,13 @@ static const pgsql_thing_t words_after_create[] = {
985997
{"OWNED", NULL, NULL, THING_NO_CREATE}, /* for DROP OWNED BY ... */
986998
{"PARSER", Query_for_list_of_ts_parsers, NULL, THING_NO_SHOW},
987999
{"POLICY", NULL, NULL},
988-
{"PUBLICATION", NULL, NULL},
1000+
{"PUBLICATION", Query_for_list_of_publications},
9891001
{"ROLE", Query_for_list_of_roles},
9901002
{"RULE", "SELECT pg_catalog.quote_ident(rulename) FROM pg_catalog.pg_rules WHERE substring(pg_catalog.quote_ident(rulename),1,%d)='%s'"},
9911003
{"SCHEMA", Query_for_list_of_schemas},
9921004
{"SEQUENCE", NULL, &Query_for_list_of_sequences},
9931005
{"SERVER", Query_for_list_of_servers},
994-
{"SUBSCRIPTION", NULL, NULL},
1006+
{"SUBSCRIPTION", Query_for_list_of_subscriptions},
9951007
{"TABLE", NULL, &Query_for_list_of_tables},
9961008
{"TABLESPACE", Query_for_list_of_tablespaces},
9971009
{"TEMP", NULL, NULL, THING_NO_DROP}, /* for CREATE TEMP TABLE ... */
@@ -2374,8 +2386,13 @@ psql_completion(const char *text, int start, int end)
23742386
/* CREATE SUBSCRIPTION */
23752387
else if (Matches3("CREATE", "SUBSCRIPTION", MatchAny))
23762388
COMPLETE_WITH_CONST("CONNECTION");
2377-
else if (Matches5("CREATE", "SUBSCRIPTION", MatchAny, "CONNECTION",MatchAny))
2389+
else if (Matches5("CREATE", "SUBSCRIPTION", MatchAny, "CONNECTION", MatchAny))
23782390
COMPLETE_WITH_CONST("PUBLICATION");
2391+
else if (Matches6("CREATE", "SUBSCRIPTION", MatchAny, "CONNECTION",
2392+
MatchAny, "PUBLICATION"))
2393+
{
2394+
/* complete with nothing here as this refers to remote publications */
2395+
}
23792396
/* Complete "CREATE SUBSCRIPTION <name> ... WITH ( <opt>" */
23802397
else if (HeadMatches2("CREATE", "SUBSCRIPTION") && TailMatches2("WITH", "("))
23812398
COMPLETE_WITH_LIST5("ENABLED", "DISABLED", "CREATE SLOT",

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-
#define CATALOG_VERSION_NO 201703031
56+
#define CATALOG_VERSION_NO 201703032
5757

5858
#endif

src/include/catalog/pg_subscription.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* seems weird, but the replication launcher process needs to access all of
2828
* them to be able to start the workers, so we have to put them in a shared,
2929
* nailed catalog.
30+
*
31+
* NOTE: When adding a column, also update system_views.sql.
3032
*/
3133
CATALOG(pg_subscription,6100) BKI_SHARED_RELATION BKI_ROWTYPE_OID(6101) BKI_SCHEMA_MACRO
3234
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy