'creating application: failed to initialize ORM

I always get this error when I start node. please reply to me where I am going wrong.

Error : creating application: failed to initialize ORM: initializeORM#NewORM: unable to init DB: unable to open ?application_name=Chainlink+0.10.7+%7C+ORM+%7C+98d78e80-6fa0-4e2f-a9a4-c51199bf9d2a for gorm DB conn &{0 0xc0004a93e0 0 {0 0} [] map[] 0 0 0xc0005e29c0 false map[] map[] 0 0 0 0 0 0 0 0 0x59b0a0}: failed to connect to host=/var/run/postgresql user=root database=: server error (FATAL: unrecognized configuration parameter "?application_name" (SQLSTATE 42704))

config :

LOG_LEVEL=debug
ETH_CHAIN_ID=42
MIN_OUTGOING_CONFIRMATIONS=2
LINK_CONTRACT_ADDRESS=0xa36085F69e2889c224210F603D836748e7dC0088
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
FEATURE_EXTERNAL_INITIATORS=true
ALLOW_ORIGINS=*
ETH_URL=wss://kovan.infura.io/ws/v3/8e32345678ghjk456789cvbn4yu
DATABASE_URL=postgresql://localhost:5432/kovan_demo?sslmode=disable
DATABASE_TIMEOUT=0
FEATURE_FLUX_MONITOR=true
MINIMUM_CONTRACT_PAYMENT=100000000000000000
CHAINLINK_DEV=true


Solution 1:[1]

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.

  1. edit postgresql.conf to listen_addresses = '*'
  2. 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.

Solution 2:[2]

Make sure that these environment variables are also saved in your .zprofile or .bash_profile depending on what shell you are running.

You can check if these files are present with this command in your home directory: ls -al

If the there is no such file you can create one: touch ~/.zprofile

Then write all the variables from your .env file prefixed with export After saving the variables, run the following command to enable the changes to take effect in the current terminal session: source .zprofile or source .bash_profile if you are running a bash shell.

This will ensure that your chainlink node knows where to find the environment variable when booting the node: chainlink node start

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
Solution 2 Daniel Adebimpe