Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql_extensible.query cannot connect to pgbouncer #3253

Closed
mced opened this issue Sep 20, 2017 · 19 comments · Fixed by #3918
Closed

postgresql_extensible.query cannot connect to pgbouncer #3253

mced opened this issue Sep 20, 2017 · 19 comments · Fixed by #3918
Labels
area/postgresql bug unexpected problem or unintended behavior upstream bug or issues that rely on dependency fixes

Comments

@mced
Copy link
Contributor

mced commented Sep 20, 2017

Bug report

With last version 1.4, many of us thought that telegraf was compatible with pgbouncer through postgresql_extensible.query input plugin.

It is not the case.

Relevant telegraf.conf:

[[inputs.postgresql_extensible]]
  address = "host=localhost user=telegraf dbname=pgbouncer"

[[inputs.postgresql_extensible.query]]
  sqlquery="SHOW STATS"
  measurement="pgbouncer"
  withdbname=false
  version=0

System info:

Telegraf v1.4.0 (git: release-1.4 34b7a4c)
Ubuntu 14.04
pgbouncer 1.5.4

Steps to reproduce:

Add telegraf user in pgbouncer config file as admin_users.
Then run telegraf.

Expected behavior:

$ telegraf --config /etc/telegraf/telegraf.conf --debug --test
pgbouncer,name=pgbouncer,host=hostname,...

Actual behavior:

$ telegraf --config /etc/telegraf/telegraf.conf --debug --test
* Plugin: inputs.postgresql_extensible, Collection 1
2017-09-20T10:29:17Z E! Error in plugin [inputs.postgresql_extensible]: ERROR: not allowed (SQLSTATE 08P01)
@danielnelson
Copy link
Contributor

@james-lawrence
Copy link
Contributor

james-lawrence commented Sep 21, 2017

did we actually confirm it worked? the pgbouncer PR had mixed statements from others on it working? I don't remember the failures being understood and addressed.

the error mentioned here is a protocol violation.

Also looking at your configuration: its going to default to port 5432.... is pgbouncer running on that port? Also what is your pgbouncer configuration?

@danielnelson danielnelson added the bug unexpected problem or unintended behavior label Sep 21, 2017
@danielnelson danielnelson changed the title Bug report: postgresql_extensible.query and pgbouncer postgresql_extensible.query cannot connect to pgbouncer Sep 21, 2017
@mced
Copy link
Contributor Author

mced commented Sep 22, 2017

@danielnelson I can't say

@james-lawrence nope nobody confirmed, and you're right according to #2573 (comment), it was not working.

pgbouncer is listening on 5432 port and pooling connections from localhost application to a remote database

pgbouncer is listening on 5432 port

$ psql -h localhost -d pgbouncer -U telegraf -p 5432
Password for user telegraf: 
psql (9.3.16, server 1.5.4/bouncer)
Type "help" for help.

pgbouncer=# 

Here is my pgbouncer config

[databases]
remote_db= host=<remote.tld> port=5432 dbname=<dbname> user=<user> password=<password>

[pgbouncer]
logfile = /var/log/postgresql/pgbouncer.log
pidfile = /var/run/postgresql/pgbouncer.pid

listen_addr = 127.0.0.1
listen_port = 5432

unix_socket_dir = /var/run/postgresql

auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt

pool_mode = session

server_reset_query = DISCARD ALL

server_check_query = select 1

max_client_conn = 200
default_pool_size = 15
ignore_startup_parameters = extra_float_digits

admin_users = telegraf

@james-lawrence
Copy link
Contributor

k, I might have a chance to look into this. but will depend on my mood. =)

@james-lawrence
Copy link
Contributor

james-lawrence commented Sep 24, 2017

@mced, alright did some investigation, SQLSTATE 08P01 is pretty much a catchall error. while exploring I received it multiple times:

  • ERROR: No such user: james (SQLSTATE 08P01) - missing user from pgbouncer userlist.
  • ERROR: not allowed (SQLSTATE 08P01) - missing user from admin_users or stats_users in pgbouncer.ini. this looks like your issue, I am using a more recent version of pgbouncer than you are though.
  • ERROR: unsupported pkt type: 80 (SQLSTATE 08P01) - this looks like an actual problem that would stop the postgresql plugin from working. I'm making an assumption here that pkt type = packet type, and 80 corresponds to the ascii, therefor character 'P'. documentation on these can be found here. all that being said, I'll have to look into what pgx is doing, one of my gripes with the driver is that it creates prepared statements implicitly and is likely the cause of this problem. I also believe that there might be a switch to turn it off.

@mced
Copy link
Contributor Author

mced commented Sep 25, 2017

Tank you for your feedback.

@rsaffi
Copy link

rsaffi commented Sep 26, 2017

99-pgbouncer.conf.zip
pgbouncer.ini.zip

@james-lawrence On my scenario it's the last one: ERROR: unsupported pkt type: 80 (SQLSTATE 08P01).

root@pg01 ~ # pgbouncer --version
pgbouncer version 1.7.2

root@pg01 ~ # telegraf --version
Telegraf v1.4.0 (git: release-1.4 34b7a4c)

Both telegraf input plugin and pgbouncer config files are attached. IPs and passwords have obviously been redacted.

root@pg01 /etc/telegraf/telegraf.d # telegraf --config /etc/telegraf/telegraf.d/99-pgbouncer.conf --debug --test

  • Plugin: inputs.postgresql_extensible, Collection 1
  • Internal: 1m0s
    2017-09-26T08:16:18Z E! Error in plugin [inputs.postgresql_extensible]: ERROR: unsupported pkt type: 80 (SQLSTATE 08P01)

@james-lawrence
Copy link
Contributor

@rsaffi thanks for the information. I got buyin from the pgx maintainer to make the implicit prepared queries optional. so fixing the issue will be pretty straight forward just need to find the time to do it.

@leehambley
Copy link

leehambley commented Oct 4, 2017

I just ran into this issue today, is there a workaround for collecting SHOW POOLS metrics with Telegraf pending a fix? I have:

[[inputs.postgresql_extensible]]
  address = "host=/var/run/postgresql user=••••• password=••••• sslmode=disable dbname=pgbouncer port=6432"
  databases = ["pgbouncer"]

[[inputs.postgresql_extensible.query]]
    sqlquery="show pools"
    withdbname = false
    measurement="postgresql_pgbouncer_6432_pools"

Thanks, and sorry for highlighting the issue without a constructive contribution.

@rsaffi
Copy link

rsaffi commented Oct 4, 2017

@leehambley Well, I ended up making a python script that does the trick. I am using it with the "exec" plugin from Telegraf to send metrics to InfluxDB and it has been working great so far.
In case you can't wait for the fix (like I couldn't), feel free to try it out meanwhile:

https://github.com/CrossEngage/telebouncer

PS: In case it's not allowed to crosspost to another project like I did, please accept my appologies and feel free to remove this comment!

@james-lawrence
Copy link
Contributor

@leehambley there isn't currently a work around. its just straight up work that needs to be done in the driver we're using.

@leehambley
Copy link

Thanks, actually took the chance to remove PGbouncer from the stack, a 🎉 🎈 followed :) 👍

@danielnelson danielnelson added area/postgresql upstream bug or issues that rely on dependency fixes labels Dec 6, 2017
@huyujie
Copy link

huyujie commented Dec 7, 2017

@james-lawrence if use pgpool not pgbouncer,your pr seems can't resolve the "show ..." query return err. #

@james-lawrence
Copy link
Contributor

@huyujie shame, docs say your error is an undefined object. so not sure exactly what is going on without digging further.

@james-lawrence
Copy link
Contributor

james-lawrence commented Jan 14, 2018

driver can now support SHOW STATS, havent tried the other commands. but anything additional should only require invoking RegisterDataType with the correct information.

will need a separate plugin that overrides the DB creation and use the below for the driver:

	d := &stdlib.DriverConfig{
		ConnConfig: pgx.ConnConfig{
			PreferSimpleProtocol: true,
			RuntimeParams: map[string]string{
				"client_encoding": "UTF8",
			},
			CustomConnInfo: func(c *pgx.Conn) (*pgtype.ConnInfo, error) {
				info := c.ConnInfo.DeepCopy()
				info.RegisterDataType(pgtype.DataType{
					Value: &pgtype.OIDValue{},
					Name:  "int8OID",
					OID:   pgtype.Int8OID,
				})

				return info, nil
			},
		},
	}
	stdlib.RegisterDriverConfig(d)

	db, err := sql.Open("pgx", d.ConnectionString("postgres://localhost:6432/pgbouncer"))

so if someone wants to pick up the work its doable now.

@kramarz
Copy link

kramarz commented Aug 2, 2018 via email

@urusha
Copy link
Contributor

urusha commented Feb 19, 2019

I've got this with pgbouncer input after upgrading to Telegraf 1.9.4

E! [inputs.pgbouncer]: Error in plugin: ERROR: unsupported pkt type: 80 (SQLSTATE 08P01)
E! [inputs.pgbouncer]: Error in plugin: EOF

On 1.9.0 there were no errors. Config is the same.

@danielnelson
Copy link
Contributor

@urusha I don't believe anything has changed in this plugin, can you try to isolate the first Telegraf version where this error occurs and then open a new issue?

@urusha
Copy link
Contributor

urusha commented Feb 20, 2019

@danielnelson The version is 1.9.1. Please, see #5455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/postgresql bug unexpected problem or unintended behavior upstream bug or issues that rely on dependency fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants