Skip to content

Commit d1ecd53

Browse files
committed
Add a SHOW command to the replication command language.
This is useful infrastructure for an upcoming proposed patch to allow the WAL segment size to be changed at initdb time; tools like pg_basebackup need the ability to interrogate the server setting. But it also doesn't seem like a bad thing to have independently of that; it may find other uses in the future. Robert Haas and Beena Emerson. (The original patch here was by Beena, but I rewrote it to such a degree that most of the code being committed here is mine.) Discussion: http://postgr.es/m/CA+TgmobNo4qz06wHEmy9DszAre3dYx-WNhHSCbU9SAwf+9Ft6g@mail.gmail.com
1 parent a84069d commit d1ecd53

File tree

7 files changed

+151
-10
lines changed

7 files changed

+151
-10
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,30 @@ The commands accepted in walsender mode are:
13931393
</listitem>
13941394
</varlistentry>
13951395

1396+
<varlistentry>
1397+
<term><literal>SHOW</literal> <replaceable class="parameter">name</replaceable>
1398+
<indexterm><primary>SHOW</primary></indexterm>
1399+
</term>
1400+
<listitem>
1401+
<para>
1402+
Requests the server to send the current setting of a run-time parameter.
1403+
This is similar to the SQL command <xref linkend="sql-show">.
1404+
</para>
1405+
1406+
<variablelist>
1407+
<varlistentry>
1408+
<term><replaceable class="parameter">name</></term>
1409+
<listitem>
1410+
<para>
1411+
The name of a run-time parameter. Available parameters are documented
1412+
in <xref linkend="runtime-config">.
1413+
</para>
1414+
</listitem>
1415+
</varlistentry>
1416+
</variablelist>
1417+
</listitem>
1418+
</varlistentry>
1419+
13961420
<varlistentry>
13971421
<term><literal>TIMELINE_HISTORY</literal> <replaceable class="parameter">tli</replaceable>
13981422
<indexterm><primary>TIMELINE_HISTORY</primary></indexterm>

src/backend/access/common/tupdesc.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "postgres.h"
2121

2222
#include "access/htup_details.h"
23+
#include "catalog/pg_collation.h"
2324
#include "catalog/pg_type.h"
2425
#include "miscadmin.h"
2526
#include "parser/parse_type.h"
@@ -553,6 +554,84 @@ TupleDescInitEntry(TupleDesc desc,
553554
ReleaseSysCache(tuple);
554555
}
555556

557+
/*
558+
* TupleDescInitBuiltinEntry
559+
* Initialize a tuple descriptor without catalog access. Only
560+
* a limited range of builtin types are supported.
561+
*/
562+
void
563+
TupleDescInitBuiltinEntry(TupleDesc desc,
564+
AttrNumber attributeNumber,
565+
const char *attributeName,
566+
Oid oidtypeid,
567+
int32 typmod,
568+
int attdim)
569+
{
570+
Form_pg_attribute att;
571+
572+
/* sanity checks */
573+
AssertArg(PointerIsValid(desc));
574+
AssertArg(attributeNumber >= 1);
575+
AssertArg(attributeNumber <= desc->natts);
576+
577+
/* initialize the attribute fields */
578+
att = desc->attrs[attributeNumber - 1];
579+
att->attrelid = 0; /* dummy value */
580+
581+
/* unlike TupleDescInitEntry, we require an attribute name */
582+
Assert(attributeName != NULL);
583+
namestrcpy(&(att->attname), attributeName);
584+
585+
att->attstattarget = -1;
586+
att->attcacheoff = -1;
587+
att->atttypmod = typmod;
588+
589+
att->attnum = attributeNumber;
590+
att->attndims = attdim;
591+
592+
att->attnotnull = false;
593+
att->atthasdef = false;
594+
att->attisdropped = false;
595+
att->attislocal = true;
596+
att->attinhcount = 0;
597+
/* attacl, attoptions and attfdwoptions are not present in tupledescs */
598+
599+
att->atttypid = oidtypeid;
600+
601+
/*
602+
* Our goal here is to support just enough types to let basic builtin
603+
* commands work without catalog access - e.g. so that we can do certain
604+
* things even in processes that are not connected to a database.
605+
*/
606+
switch (oidtypeid)
607+
{
608+
case TEXTOID:
609+
case TEXTARRAYOID:
610+
att->attlen = -1;
611+
att->attbyval = false;
612+
att->attalign = 'i';
613+
att->attstorage = 'x';
614+
att->attcollation = DEFAULT_COLLATION_OID;
615+
break;
616+
617+
case BOOLOID:
618+
att->attlen = 1;
619+
att->attbyval = true;
620+
att->attalign = 'c';
621+
att->attstorage = 'p';
622+
att->attcollation = InvalidOid;
623+
break;
624+
625+
case INT4OID:
626+
att->attlen = 4;
627+
att->attbyval = true;
628+
att->attalign = 'i';
629+
att->attstorage = 'p';
630+
att->attcollation = InvalidOid;
631+
break;
632+
}
633+
}
634+
556635
/*
557636
* TupleDescInitEntryCollation
558637
*

src/backend/replication/repl_gram.y

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Node *replication_parse_result;
6161
/* Keyword tokens. */
6262
%token K_BASE_BACKUP
6363
%token K_IDENTIFY_SYSTEM
64+
%token K_SHOW
6465
%token K_START_REPLICATION
6566
%token K_CREATE_REPLICATION_SLOT
6667
%token K_DROP_REPLICATION_SLOT
@@ -82,14 +83,14 @@ Node *replication_parse_result;
8283
%type <node> command
8384
%type <node> base_backup start_replication start_logical_replication
8485
create_replication_slot drop_replication_slot identify_system
85-
timeline_history
86+
timeline_history show
8687
%type <list> base_backup_opt_list
8788
%type <defelt> base_backup_opt
8889
%type <uintval> opt_timeline
8990
%type <list> plugin_options plugin_opt_list
9091
%type <defelt> plugin_opt_elem
9192
%type <node> plugin_opt_arg
92-
%type <str> opt_slot
93+
%type <str> opt_slot var_name
9394
%type <boolval> opt_reserve_wal opt_temporary
9495

9596
%%
@@ -112,6 +113,7 @@ command:
112113
| create_replication_slot
113114
| drop_replication_slot
114115
| timeline_history
116+
| show
115117
;
116118

117119
/*
@@ -124,6 +126,22 @@ identify_system:
124126
}
125127
;
126128

129+
/*
130+
* SHOW setting
131+
*/
132+
show:
133+
K_SHOW var_name
134+
{
135+
VariableShowStmt *n = makeNode(VariableShowStmt);
136+
n->name = $2;
137+
$$ = (Node *) n;
138+
}
139+
140+
var_name: IDENT { $$ = $1; }
141+
| var_name '.' IDENT
142+
{ $$ = psprintf("%s.%s", $1, $3); }
143+
;
144+
127145
/*
128146
* BASE_BACKUP [LABEL '<label>'] [PROGRESS] [FAST] [WAL] [NOWAIT]
129147
* [MAX_RATE %d] [TABLESPACE_MAP]

src/backend/replication/repl_scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ identifier {ident_start}{ident_cont}*
8383
BASE_BACKUP { return K_BASE_BACKUP; }
8484
FAST { return K_FAST; }
8585
IDENTIFY_SYSTEM { return K_IDENTIFY_SYSTEM; }
86+
SHOW { return K_SHOW; }
8687
LABEL { return K_LABEL; }
8788
NOWAIT { return K_NOWAIT; }
8889
PROGRESS { return K_PROGRESS; }

src/backend/replication/walsender.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <signal.h>
4444
#include <unistd.h>
4545

46+
#include "access/printtup.h"
4647
#include "access/timeline.h"
4748
#include "access/transam.h"
4849
#include "access/xact.h"
@@ -72,11 +73,13 @@
7273
#include "storage/pmsignal.h"
7374
#include "storage/proc.h"
7475
#include "storage/procarray.h"
76+
#include "tcop/dest.h"
7577
#include "tcop/tcopprot.h"
7678
#include "utils/builtins.h"
7779
#include "utils/guc.h"
7880
#include "utils/memutils.h"
7981
#include "utils/pg_lsn.h"
82+
#include "utils/portal.h"
8083
#include "utils/ps_status.h"
8184
#include "utils/resowner.h"
8285
#include "utils/timeout.h"
@@ -1365,6 +1368,15 @@ exec_replication_command(const char *cmd_string)
13651368
SendTimeLineHistory((TimeLineHistoryCmd *) cmd_node);
13661369
break;
13671370

1371+
case T_VariableShowStmt:
1372+
{
1373+
DestReceiver *dest = CreateDestReceiver(DestRemoteSimple);
1374+
VariableShowStmt *n = (VariableShowStmt *) cmd_node;
1375+
1376+
GetPGVariable(n->name, dest);
1377+
}
1378+
break;
1379+
13681380
default:
13691381
elog(ERROR, "unrecognized replication command node tag: %u",
13701382
cmd_node->type);

src/backend/utils/misc/guc.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7878,8 +7878,8 @@ ShowGUCConfigOption(const char *name, DestReceiver *dest)
78787878

78797879
/* need a tuple descriptor representing a single TEXT column */
78807880
tupdesc = CreateTemplateTupleDesc(1, false);
7881-
TupleDescInitEntry(tupdesc, (AttrNumber) 1, varname,
7882-
TEXTOID, -1, 0);
7881+
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 1, varname,
7882+
TEXTOID, -1, 0);
78837883

78847884
/* prepare for projection of tuples */
78857885
tstate = begin_tup_output_tupdesc(dest, tupdesc);
@@ -7905,12 +7905,12 @@ ShowAllGUCConfig(DestReceiver *dest)
79057905

79067906
/* need a tuple descriptor representing three TEXT columns */
79077907
tupdesc = CreateTemplateTupleDesc(3, false);
7908-
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "name",
7909-
TEXTOID, -1, 0);
7910-
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "setting",
7911-
TEXTOID, -1, 0);
7912-
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
7913-
TEXTOID, -1, 0);
7908+
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 1, "name",
7909+
TEXTOID, -1, 0);
7910+
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 2, "setting",
7911+
TEXTOID, -1, 0);
7912+
TupleDescInitBuiltinEntry(tupdesc, (AttrNumber) 3, "description",
7913+
TEXTOID, -1, 0);
79147914

79157915
/* prepare for projection of tuples */
79167916
tstate = begin_tup_output_tupdesc(dest, tupdesc);

src/include/access/tupdesc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ extern void TupleDescInitEntry(TupleDesc desc,
119119
int32 typmod,
120120
int attdim);
121121

122+
extern void TupleDescInitBuiltinEntry(TupleDesc desc,
123+
AttrNumber attributeNumber,
124+
const char *attributeName,
125+
Oid oidtypeid,
126+
int32 typmod,
127+
int attdim);
128+
122129
extern void TupleDescInitEntryCollation(TupleDesc desc,
123130
AttrNumber attributeNumber,
124131
Oid collationid);

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