[[inputs.postgresql]]
address = ""
36193aea10.5-0ubuntu0.18.04address in telegraf.conf for that DBlocalhost and disables SSLThis issue is a fairly low priority, but it got me stumped when playing around with telegraf. On my development box I don't need TCP connections to PostgreSQL and never enabled it. All my apps run locally using a unix-domain socket. This is the default config of PostgreSQL. All other PG clients I know of (including psql) will connect using the Unix domain socket when no DSN is specified.
I would expect telegraf to behave like any other PG client in it's default config.
Right now the DSN is hardcoded to localhost if an empty address is specified.
We should probably do what psql does, but the default would only change in Telegraf 2.0. In the meantime I think we should improve the comment for this option to show how to set it up for unix socket connections.
We also need to check how psql determines where to connect, it may be reading a config file on your host.
@danielnelson suggested
show how to set it up for unix socket connections
I would be very keen to see how you manage configuration to allow unix socket connection - i've been trying over and over again with no luck :)
Following up: @danielnelson - sorry to be a pain in rear - the way i'm reading your comment above is that it is possible to set telegraf to allow it to query postgres using sockets - if that is possible I am very interested because i'd like to avoid hitting the tcpip stack with frequency (im deploying to 200+ servers). If I have read that wrong I'm even willing to fork and fix (temporarily until 2.0 drops) - please advise :)
A little bit more followup: it looks like you're importing a postgres go library from jackc - a bit of digging and i see that host may also be a path to a socket: https://github.com/jackc/pgx/blob/4618730e71353189c1ae1632cb7d166613a882eb/conn.go#L66
Perhaps if i send the default postgres socket path via the host variable i will be able to get it rolling - I'll follow again with my results...
@ReinsBrain @danielnelson As I can see using unix sockets is not possible at the moment (url.Parse is used https://github.com/influxdata/telegraf/blob/master/plugins/inputs/postgresql/service.go#L42). We might:
local to translate it to path (static path).user@anyhost:port/path/to/socket/dir/databasehost=/path/to/socket/dir DSN parameter (like sslmode). Add possibility to override any parameter?address or another parameter which overrides address (what is the purpose of url formatting at all?)I thinks the last option is the best, since it would not break existing configurations, but adds full pg flexibility.
The same for pgbouncer plugin. What do you think?
After writing comment, I've realized that I didn't try to use native pg connection string in address, which is working, actually ( https://github.com/influxdata/telegraf/blob/master/plugins/inputs/postgresql/service.go#L19-L21 ). So disregard my previous comment, but we should really mention this in the docs!
Most helpful comment
@danielnelson suggested
I would be very keen to see how you manage configuration to allow unix socket connection - i've been trying over and over again with no luck :)
Following up: @danielnelson - sorry to be a pain in rear - the way i'm reading your comment above is that it is possible to set telegraf to allow it to query postgres using sockets - if that is possible I am very interested because i'd like to avoid hitting the tcpip stack with frequency (im deploying to 200+ servers). If I have read that wrong I'm even willing to fork and fix (temporarily until 2.0 drops) - please advise :)
A little bit more followup: it looks like you're importing a postgres go library from jackc - a bit of digging and i see that host may also be a path to a socket: https://github.com/jackc/pgx/blob/4618730e71353189c1ae1632cb7d166613a882eb/conn.go#L66
Perhaps if i send the default postgres socket path via the host variable i will be able to get it rolling - I'll follow again with my results...