Postgres datasource plugin

Hello installed grafana 4.6 stable today and tryed to configure a connection to a postgres database wich i have access in the host that grafana is working but when saving and testing connection it faula giving me a internal error. Ive tryed also adding a mysql connection and it works perfectly. Is it something wrong with the new plugin or am i missing something?

Thank you

Which source did you use for the package? Is there anything in the grafana error log?

Hello, thank you for the reply,

I’m using the 4.6.0 Stable Grafana (in windows 10).

In the log file \var log\grafana\grafana.log I get the following 3 lines:


t=2017-10-27T08:59:37+0100 lvl=dbug msg=getEngine logger=tsdb.postgres connection=“postgres://the_user:the_password@the.remote.ip.address:5432/mydatabase?sslmode=disable”



t=2017-10-27T08:59:37+0100 lvl=eror msg=“Request error” logger=context userId=1 orgId=1 uname=admin error=“runtime error: invalid memory address or nil pointer dereference” stack=“C:/go/src/runtime/panic.go:491 (0x42f4e0)\nC:/go/src/runtime/panic.go:63 (0x42e364)\nC:/go/src/runtime/signal_windows.go:161 (0x445212)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-xorm/xorm/engine.go:191 (0x8c30f9)\nc:/gopath/src/github.com/grafana/grafana/pkg/tsdb/sql_engine.go:60 (0xbc78ce)\nc:/gopath/src/github.com/grafana/grafana/pkg/tsdb/postgres/postgres.go:38 (0xd67978)\nc:/gopath/src/github.com/grafana/grafana/pkg/tsdb/query_endpoint.go:24 (0xbc75bd)\nc:/gopath/src/github.com/grafana/grafana/pkg/tsdb/request.go:12 (0xbc7705)\nc:/gopath/src/github.com/grafana/grafana/pkg/api/metrics.go:46 (0xe09cb5)\nC:/go/src/runtime/asm_amd64.s:511 (0x45c948)\nC:/go/src/reflect/value.go:434 (0x4d563c)\nC:/go/src/reflect/value.go:302 (0x4d4bfa)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:177 (0x7e03ef)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:137 (0x7dfce0)\nc:/gopath/src/github.com/grafana/grafana/pkg/api/common.go:37 (0xe25e42)\nC:/go/src/runtime/asm_amd64.s:509 (0x45c811)\nC:/go/src/reflect/value.go:434 (0x4d563c)\nC:/go/src/reflect/value.go:302 (0x4d4bfa)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:177 (0x7e03ef)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:137 (0x7dfce0)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:121 (0x7fd794)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:112 (0x7fd6bc)\nc:/gopath/src/github.com/grafana/grafana/pkg/middleware/request_tracing.go:25 (0xbaf6ca)\nC:/go/src/runtime/asm_amd64.s:509 (0x45c811)\nC:/go/src/reflect/value.go:434 (0x4d563c)\nC:/go/src/reflect/value.go:302 (0x4d4bfa)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:177 (0x7e03ef)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:137 (0x7dfce0)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:121 (0x7fd794)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:112 (0x7fd6bc)\nc:/gopath/src/github.com/grafana/grafana/pkg/middleware/request_metrics.go:17 (0xbaef4b)\nC:/go/src/runtime/asm_amd64.s:509 (0x45c811)\nC:/go/src/reflect/value.go:434 (0x4d563c)\nC:/go/src/reflect/value.go:302 (0x4d4bfa)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:177 (0x7e03ef)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:137 (0x7dfce0)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:121 (0x7fd794)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:112 (0x7fd6bc)\nc:/gopath/src/github.com/grafana/grafana/pkg/middleware/session.go:79 (0xbafa61)\nC:/go/src/runtime/asm_amd64.s:509 (0x45c811)\nC:/go/src/reflect/value.go:434 (0x4d563c)\nC:/go/src/reflect/value.go:302 (0x4d4bfa)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:177 (0x7e03ef)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:137 (0x7dfce0)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:121 (0x7fd794)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:112 (0x7fd6bc)\nc:/gopath/src/github.com/grafana/grafana/pkg/middleware/recovery.go:146 (0xbaee67)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:79 (0x7fd567)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:157 (0x7e00aa)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:135 (0x7dfdd1)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:121 (0x7fd794)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:112 (0x7fd6bc)\nc:/gopath/src/github.com/grafana/grafana/pkg/middleware/logger.go:33 (0xbac9c8)\nC:/go/src/runtime/asm_amd64.s:509 (0x45c811)\nC:/go/src/reflect/value.go:434 (0x4d563c)\nC:/go/src/reflect/value.go:302 (0x4d4bfa)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:177 (0x7e03ef)\nc:/gopath/src/github.com/grafana/grafana/vendor/github.com/go-macaron/inject/inject.go:137 (0x7dfce0)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/context.go:121 (0x7fd794)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/router.go:187 (0x80f4b9)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/router.go:296 (0x809942)\nc:/gopath/src/github.com/grafana/grafana/vendor/gopkg.in/macaron.v1/macaron.go:220 (0x80209e)\nC:/go/src/net/http/server.go:2619 (0x698dba)\nC:/go/src/net/http/server.go:1801 (0x694f73)\nC:/go/src/runtime/asm_amd64.s:2337 (0x45f120)\n”



t=2017-10-27T08:59:37+0100 lvl=eror msg=“Request Completed” logger=context userId=1 orgId=1 uname=admin method=POST path=/api/tsdb/query status=500 remote_addr=[::1] time_ms=43 size=1166 referer=http://localhost:8080/datasources/edit/9


I performed the test of intentionally inserting the wrong password and generated another message in the frontend
“pq: password authentication failed for user “x””

In the log it only shows this 2 lines:
t=2017-10-27T09:01:12+0100 lvl=dbug msg=getEngine logger=tsdb.postgres connection=“postgres://myuser:sdfsfsdfsf@my.remote.ip.address:5432/mydatabase?sslmode=disable”
t=2017-10-27T09:01:12+0100 lvl=eror msg=“Request Completed” logger=context userId=1 orgId=1 uname=admin method=POST path=/api/tsdb/query status=500 remote_addr=[::1] time_ms=46 size=221 referer=http://localhost:8080/datasources/edit/9


Thank you

Hmm i could not reproduce your issue. I downloaded the windows build and could connect fine to a postgres instance. The postgres driver seems to be initialized correctly too as you get proper error messages from the driver when you tried with wrong password. Do you see anything in the postgres error log?

Hello,

I figured it out what the problem was.

I was using a user that has more then Select permissions in tha postgres database.

I changed a username permissions to SELECT on all tables in the schema and now the connection establishes.

I checked the grafana documentation in the postgres datasource Database User Permissions :

“The database user you specify when you add the data source should only be granted SELECT permissions on the specified database & tables you want to query. (…)”

but I tought this was not mandatory.

now supose it is?

Thank you

It is not mandatory its just for your own protection and grafana does not enforce or check this at all