The problem lies in the syntax of your configuration variable DATABASE_URL
To connect to the database you need a specially created USER with a PASSWORD, which then locks this database by starting the chainlink node. The default postgres user will not work because it is used for administrative purposes.
These credentials are then added to the environmental variable with this syntax: DATABASE_URL=postgresql://$USERNAME:$PASSWORD@$SERVER:5432/$DATABASE
Because you have set "localhost" for the postgresql server IP in your environmental, I assume that your postgres is running on the same host as the Chainlink node. There are 2 different ways of establishing a connection:
1) You have both, the Chainlink node and the postgresql server inside of a docker container:
You need to point to the container ID or the container name of your postgresql server and create both containers in the same network. Here you can find the official documentation of docker: https://docs.docker.com/network/bridge/
This means you have to bridge the containers in order to be able to communicate with each other, by creating a network with:
docker network create $NAME
Then you add the network flag to your Chainlink node container and the run command of your postgres-server container:
--network $NAME
After reinitialise all these containers, you are able to point to the container name instead of an IP. The syntax of your DATABASE_URL in your environmental looks now like this:
DATABASE_URL=postgresql://$USERNAME:$PASSWORD@$CONTAINER_NAME:$5432/$DATABASE
Instead of reinitialising the containers, you can also connect a running docker container to a network/ user-defined bridge with: docker network connect $NETWORK_NAME $CONTAINER_NAME
2) The postgresql server is as an application on your host and the chainlink node inside of a docker container:
To realise this you need to configure the chainlink node and the database in order to allow communication.
postgresql server: you need to change the configuration file to allow communication of a specific Ip-range (by default the postgres Ip-range is just set for localhost ). Usually you find the config files in /etc/postgresql/<version>/main directory.
- edit postgresql.conf to
listen_addresses = '*'
- edit pg_hba.conf to
host all all 172.17.0.1/16 md5
This range of addresses belongs to Docker and includes the assigned IP of your chainlink container.
Chainlink node: you need to add --add-host=host:127.0.0.1 to your run command to enable the connection to the database and services on your host.
Please ensure also that you disable ssl for testing purposes by adding ?ssl=disbable to your ETH_URL configuration, because the Chainlink node will return an [ERROR] log if SSL is not configured on your Server (You are able to configure SSL later on your server, because this is an own topic you have to read about in the official documentation)
In production SSL (also when "just" encrypt your traffic internally) is highly recommended, because it simply secures all your database communication and keeps the information inside of this database safe.