'docker chainlink container not connecting to postgres database

I want to run chainlink node on my local ubuntu machine. I used the following commands to install postgresql:

sudo apt install postgresql

adjusting firewall settings:

sudo ufw allow from any to any port 5432 proto tcp

accessing postgresql.conf file:

sudo gedit /etc/postgresql/12/main/postgresql.conf

alter file to

listen_addresses = ‘*’

sudo gedit /etc/postgresql/14/main/pg_hba.conf

alter file to

host all all 172.17.0.0/16     md5

created user and databases see the image below: [![this image shows my databases and users in postgresql][1]][1]

configuration of my .env file is:

ROOT=/chainlink
LOG_LEVEL=debug
ETH_CHAIN_ID=42
MIN_OUTGOING_CONFIRMATIONS=2
LINK_CONTRACT_ADDRESS=0xa36085F69e2889c224210F603D836748e7dC0088
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
GAS_UPDATER_ENABLED=true
ALLOW_ORIGINS=*
ETH_URL=wss://kovan.infura.io/ws/v3/f0d1d3d2fbb649e29922ec37d4ff0b45
DATABASE_URL=postgresql://chainlink:password#[email protected]:5432/chainlink?ssl=disable
DATABASE_TIMEOUT=0

I run the following command in the terminal with an image version of 0.10.14.

cd ~/.chainlink-kovan && docker run -p 6688:6688 --name chainlink-node --add- 
host=host:127.0.0.1 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env 
smartcontract/chainlink:0.10.14 local n

it is not connecting to postgresql database. sometime it shows the error that DATABASE_URL line is wrong in .env file. current error log is:

    {"level":"warn","ts":1634243680.5286717,"caller":"logger/default.go:134","msg":"GAS_UPDATER_ENABLED has been deprecated, to enable the block history estimator, please use GAS_ESTIMATOR_MODE=BlockHistory instead"}
2021-10-14T20:34:40Z [INFO]  Starting Chainlink Node 0.10.14 at commit 8160d7726d778b5c425e4b56af30b76cbc6d222d cmd/local_client.go:63  InstanceUUID=c6169db0-8d75-4902-becc-643bb0672861 SHA=8160d7726d778b5c425e4b56af30b76cbc6d222d Version=0.10.14 id=boot 
2021-10-14T20:34:40Z [ERROR] invalid database url %spostgresql://chainlink:Kashif#[email protected]:5939/chainlink?ssl=disable config/config.go:372    stacktrace=github.com/smartcontractkit/chainlink/core/store/config.Config.DatabaseURL
    /chainlink/core/store/config/config.go:372
github.com/smartcontractkit/chainlink/core/cmd.ChainlinkAppFactory.NewApplication
    /chainlink/core/cmd/client.go:86
github.com/smartcontractkit/chainlink/core/cmd.(*Client).RunNode
    /chainlink/core/cmd/local_client.go:76
github.com/urfave/cli.HandleAction
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:524
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:173
github.com/urfave/cli.(*App).RunAsSubcommand
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:405
github.com/urfave/cli.Command.startApp
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:372
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:102
github.com/urfave/cli.(*App).Run
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:277
main.Run
    /chainlink/core/main.go:20
main.main
    /chainlink/core/main.go:14
runtime.main
    /usr/local/go/src/runtime/proc.go:225 
2021-10-14T20:34:40Z [ERROR] invalid database url %spostgresql://chainlink:Kashif#[email protected]:5939/chainlink?ssl=disable config/config.go:372    stacktrace=github.com/smartcontractkit/chainlink/core/store/config.Config.DatabaseURL
    /chainlink/core/store/config/config.go:372
github.com/smartcontractkit/chainlink/core/store.initializeORM
    /chainlink/core/store/store.go:167
github.com/smartcontractkit/chainlink/core/store.newStore
    /chainlink/core/store/store.go:69
github.com/smartcontractkit/chainlink/core/store.NewStore
    /chainlink/core/store/store.go:47
github.com/smartcontractkit/chainlink/core/services/chainlink.NewApplication
    /chainlink/core/services/chainlink/application.go:152
github.com/smartcontractkit/chainlink/core/cmd.ChainlinkAppFactory.NewApplication
    /chainlink/core/cmd/client.go:87
github.com/smartcontractkit/chainlink/core/cmd.(*Client).RunNode
    /chainlink/core/cmd/local_client.go:76
github.com/urfave/cli.HandleAction
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:524
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:173
github.com/urfave/cli.(*App).RunAsSubcommand
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:405
github.com/urfave/cli.Command.startApp
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:372
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:102
github.com/urfave/cli.(*App).Run
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:277
main.Run
    /chainlink/core/main.go:20
main.main
    /chainlink/core/main.go:14
runtime.main
    /usr/local/go/src/runtime/proc.go:225 
2021-10-14T20:34:40Z [ERROR] failed to initialize database, got error failed to connect to `host=/tmp user=root database=`: dial error (dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory) orm/orm.go:87           stacktrace=github.com/smartcontractkit/chainlink/core/store/orm.NewORM
    /chainlink/core/store/orm/orm.go:87
github.com/smartcontractkit/chainlink/core/store.initializeORM
    /chainlink/core/store/store.go:168
github.com/smartcontractkit/chainlink/core/store.newStore
    /chainlink/core/store/store.go:69
github.com/smartcontractkit/chainlink/core/store.NewStore
    /chainlink/core/store/store.go:47
github.com/smartcontractkit/chainlink/core/services/chainlink.NewApplication
    /chainlink/core/services/chainlink/application.go:152
github.com/smartcontractkit/chainlink/core/cmd.ChainlinkAppFactory.NewApplication
    /chainlink/core/cmd/client.go:87
github.com/smartcontractkit/chainlink/core/cmd.(*Client).RunNode
    /chainlink/core/cmd/local_client.go:76
github.com/urfave/cli.HandleAction
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:524
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:173
github.com/urfave/cli.(*App).RunAsSubcommand
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:405
github.com/urfave/cli.Command.startApp
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:372
github.com/urfave/cli.Command.Run
    /go/pkg/mod/github.com/urfave/[email protected]/command.go:102
github.com/urfave/cli.(*App).Run
    /go/pkg/mod/github.com/urfave/[email protected]/app.go:277
main.Run
    /chainlink/core/main.go:20
main.main
    /chainlink/core/main.go:14
runtime.main
    /usr/local/go/src/runtime/proc.go:225 
creating application: failed to initialize ORM: initializeORM#NewORM: unable to init DB: unable to open ?application_name=Chainlink+0.10.14+%7C+ORM+%7C+c6169db0-8d75-4902-becc-643bb0672861 for gorm DB conn &{0 0xc000b46108 0 {0 0} [] map[] 0 0 0xc00045a5a0 false map[] map[] 0 0 0 0 <nil> 0 0 0 0 0x5970a0}: failed to connect to `host=/tmp user=root database=`: dial error (dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory)

For two days I have been stuck in this problem and not able to make any progress. Thank you for your time and effor in anticipation. don't report this question I have tried all other possible ways watched and read all the help availabe online. [1]: https://i.stack.imgur.com/rrT8u.png



Solution 1:[1]

problem was in DATABASE_URL variable. I was using # character in my database password. I removed the # and now problem is solved.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kashif Ghafoor