Postgres connection timed out

I am facing the following problem:
I am opening a Postgres connection without any error (my GO app and Postgres DDBB live within a container)

	//Connect to Postgres DDBB
	db, err := sql.Open("postgres", *databaseURL)

	if err != nil {
		panic(fmt.Sprintf("Got error when connect database, the error is '%v'", err))

So, no errors display when executing this code, but when I do

	err := db.QueryRow("select id from ir_attachment where NAME='$1'", pdfFile).Scan(&pi_id)

	if err == sql.ErrNoRows {
		pi_id = 0
		fmt.Printf("Error no rows")
	} else if err != nil {
		fmt.Printf("Error fatal!")

I only get a time out…none of the above errors are shown either…

2017/01/11 11:32:55 dial tcp getsockopt: connection timed out

Any help would be appreciated.


sql.Open only creates a connection pool, checks that the driver is registered. The firt use creates the first connection - so use db.Ping to check the db connection parameters!

Thanks, the db.Ping also times out indeed.
I don’t really know what you mean by having the driver registered. Can you explain that to me please?

import (

	_ ""

Here is my import, and as far as I know I don’t have to register the driver anywhere, except this post that I’ve found:

Thanks has an init function that registers the driver with database/sql. You don’t have to do anything more than import the package.

All the database drivers that work with database/sql work in a similar manner.

The problem is solved, I think it was an issue with the parameters, to debug this I did from command line:

root@7d5797398768:/# psql "host=postgres port=5432 user=odoo password=odoo dbname=mydb sslmode=disable"

Thanks a lot

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.