Skip to content

Commit 1a97fa4

Browse files
committed
Add option to use simple or extended query wire protocols.
1 parent 7883ce2 commit 1a97fa4

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

cmd/pgmetrics/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Collection options:
6161
queries (default: 500)
6262
--statements-limit=LIMIT collect only utmost LIMIT number of row from
6363
pg_stat_statements (default: 100)
64+
--query-proto=PROTO which query wire protocol to use; "simple" or
65+
"extended" (default: "simple")
6466
--only-listed collect info only from the databases listed as
6567
command-line args (use with Heroku)
6668
--all-dbs collect info from all user databases
@@ -151,7 +153,8 @@ type options struct {
151153
tooLongSec uint
152154
nopager bool
153155
// connection
154-
passNone bool
156+
passNone bool
157+
queryProto string
155158
}
156159

157160
func (o *options) defaults() {
@@ -169,6 +172,7 @@ func (o *options) defaults() {
169172
o.nopager = false
170173
// connection
171174
o.passNone = false
175+
o.queryProto = "simple"
172176
}
173177

174178
func (o *options) usage(code int) {
@@ -234,6 +238,7 @@ func (o *options) parse() (args []string) {
234238
s.StringVarLong(&o.CollectConfig.User, "username", 'U', "")
235239
s.BoolVarLong(&o.passNone, "no-password", 'w', "")
236240
s.StringVarLong(&o.CollectConfig.Role, "role", 0, "")
241+
s.StringVarLong(&o.queryProto, "query-proto", 0, "")
237242

238243
// parse
239244
s.Parse(os.Args)
@@ -296,6 +301,13 @@ func (o *options) parse() (args []string) {
296301
os.Exit(2)
297302
}
298303
}
304+
if o.queryProto != "simple" && o.queryProto != "extended" {
305+
fmt.Fprintln(os.Stderr, `option --query-proto must be "simple" or "extended"`)
306+
printTry()
307+
os.Exit(2)
308+
} else {
309+
o.CollectConfig.UseExtendedQP = o.queryProto == "extended"
310+
}
299311

300312
// help action
301313
if o.helpShort || o.help == "short" || o.help == "variables" {

collector/collect.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type CollectConfig struct {
9999
AllDBs bool
100100
AzureResourceID string
101101
Pgpool bool // collect only pgpool information
102+
UseExtendedQP bool // use extended query protocol instead of simple
102103

103104
// connection
104105
Host string
@@ -115,21 +116,13 @@ func DefaultCollectConfig() CollectConfig {
115116
// ------------------ general
116117
TimeoutSec: 5,
117118
LockTimeoutMillisec: 50,
118-
//NoSizes: false,
119119

120120
// ------------------ collection
121-
//Schema: "",
122-
//ExclSchema: "",
123-
//Table: "",
124-
//ExclTable: "",
125-
//Omit: nil,
126-
//OnlyListedDBs: false,
127121
SQLLength: 500,
128122
StmtsLimit: 100,
129123
LogSpan: 5,
130124

131125
// ------------------ connection
132-
//Password: "",
133126
}
134127

135128
// connection: host
@@ -231,8 +224,13 @@ func Collect(o CollectConfig, dbnames []string) *pgmetrics.Model {
231224
// set application name
232225
connstr += makeKV("application_name", "pgmetrics")
233226

234-
// use simple protocol for maximum compatibility (pgx-specific keyword)
235-
connstr += makeKV("default_query_exec_mode", "simple_protocol")
227+
// Using simple protocol for maximum compatibility is the default for
228+
// pgmetrics. This is selected by adding default_query_exec_mode=simple_protocol
229+
// to the connection string. To use extended query protocol, nothing needs
230+
// to be added.
231+
if !o.UseExtendedQP {
232+
connstr += makeKV("default_query_exec_mode", "simple_protocol")
233+
}
236234

237235
// if "all DBs" was specified, collect the names of databases first
238236
if o.AllDBs {

0 commit comments

Comments
 (0)