Azure VM and Postgresql ChainlinkNode: unable to lock ORM - postgresql

To summarize, I am trying to run a Chainlink node via Docker on an Azure VM. I also created an Azure Postgresql DB and verified the VM is able to connect via psql cli.
Steps I took to get the node running (following this link):
Create Azure VM
Install docker
mkdir ~/.chainlink-rinkeby
Created .env file
Set ETH_URL via an External Provider
Create Postgres SQL Database following this link
Set Remote Database_Url config using sslmode=disable
Start the node with:
cd ~/.chainlink-rinkeby && docker run -p 6688:6688 -v ~/.chainlink-rinkeby:/chainlink -it --env-file=.env smartcontract/chainlink local n
My .env file:
"ROOT=/chainlink LOG_LEVEL=debug ETH_CHAIN_ID=4 MIN_OUTGOING_CONFIRMATIONS=2 LINK_CONTRACT_ADDRESS=0x01BE23585060835E02B77ef475b0Cc51aA1e0709 CHAINLINK_TLS_PORT=0 SECURE_COOKIES=false GAS_UPDATER_ENABLED=true ALLOW_ORIGINS=*"
"ETH_URL=wss://cl-rinkeby.fiews.io/v1/MY_API_KEY"
"DATABASE_URL=postgresql://MY_USER_NAME:MY_PASSWORD#MY_DATABASE_nAME.postgres.database.azure.com:5432/postgres?sslmode=disable"
Error:
[ERROR] unable to lock ORM: dial tcp 127.0.0.1:5432: connect: connection refused logger/default.go:139 stacktrace=github.com/smartcontractkit/chainlink/core/logger.Error
I've also tried giving a version of 0.10.8 in the chainlink startup command but the error I get for that is:
[ERROR] failed to initialize database, got error failed to connect to `host=/tmp user=root database=`: dial error

You are trying to connect your Chainlink node to a remote PostgreSQL database. This database is managed by AZUR's cloud service and hosted and administered there internally. The issue with the connection is that the Chainlink node wants to establish a connection to 127.0.0.1 and is therefore convinced that the Postgres is located locally in your Chainlink docker container.
A docker container is an own environment and represent an own host, so 127.0.0.1 will loopback into the container itself. I recommend you to have a look here on the official network documentation of docker: https://docs.docker.com/config/containers/container-networking/
With the version 0.10.8 you established a connection. The issue here is now related to the USER and the DATABASE. Please ensure that you create a database and an own USER for it and not use the admin credentials (root) like the superuser.
You can enter the postgres via the azur cli and type in the following lines:
CREATE DATABASE <yourdbname>;
CREATE USER <youruser> WITH ENCRYPTED PASSWORD '<yourpass>';
In addition you can have a look at this post related to the connection to your postgres database:
https://stackoverflow.com/a/67992586/15859805

Related

docker: failed to initialize database, got error failed to connect server error (FATAL: no pg_hba.conf entry for host

setting up a default chainlink node with docker containers. I decided to spin up my postgresql on another docker container and I am trying to use it as my default db for the node, currently I'm trying to figure out why my postgresql db seems to be refusing my connections I'm getting this error below, I've confirmed that my postgresql container is running correctly on localhost 5432 but the error seems to want me to edit some config file somewhere to allow access to make the connection but I'm not sure where that is or if that's the case? sorry I'm new to docker at the moment
[ERROR] failed to initialize database, got error failed to
connect to `host=192.168.1.198 user=postgres database=postgres`:
server error (FATAL: no pg_hba.conf entry for host "192.168.1.198",
user "postgres", database "postgres", SSL off (SQLSTATE 28000))
here is my docker run command which I'm following per -> https://docs.chain.link/docs/running-a-chainlink-node/
docker run -p 6688:6688 -v -it --env-file=.env smartcontract/chainlink:0.10.11 local n
here is my actual .env file being accessed when the nodes container is being created by the above command, for reference I am running the command from the same directory as the .env file
ROOT=/chainlink
LOG_LEVEL=debug
MIN_OUTGOING_CONFIRMATIONS=2
ETH_CHAIN_ID=4
LINK_CONTRACT_ADDRESS=xxxxxxxxxxxxxxxxxxxxxxx
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
GAS_UPDATER_ENABLED=true
FEATURE_FLUX_MONITOR=true
ALLOW_ORIGINS=*
DATABASE_URL=postgresql://postgres:somePassword#192.168.1.198:5432/postgres?sslmode=disable
ETH_URL=wss://ropsten.infura.io/ws/v3/xxxxxxxxxxxxxxxxxxxxxxx
DATABASE_TIMEOUT=0
the error seems to want me to edit some config file somewhere to allow access to make the connection but I'm not sure where that is or if that's the case
Yes pg_hba.conf is a file that postgres use for controlling client authentication. You must edit it for allowing remote clients to talk to it.
For a dev environment you must be good allowing all.
Although, I will try first to run both containers in the same docker network keeping pg_hba.conf as is. My guess is that the official postgres image allow traffic originating from the same network.
More resources here and here (see POSTGRES_HOST_AUTH_METHOD)

Cannot connect to Cloud SQL Proxy

I'm trying to use Cloud SQL Proxy for my Kubernetes project.
I follow the guide of Elixir and Phoenix. Under Connect to your Cloud SQL instance, that guide says that running cloud_sql_proxy -dir=/tmp/cloudsql and psql -h /tmp/cloudsql/[CONNECTION-NAME] -U postgres will open the proxy.
So I tried to make a new directory with these commands below.
mkdir -p /tmp/cloudsql
chmod +x /tmp/cloudsql
and then I tried to connect to Cloud SQL Proxy.
cloud_sql_proxy -dir=/tmp/cloudsql/ 16:47
2020/10/30 16:47:50 Rlimits for file descriptors set to {&{xxxx xxxxxxxxxxxxxxxxxxx}}
2020/10/30 16:47:51 Using gcloud's active project: [instance-id]
2020/10/30 16:47:54 Listening on /tmp/cloudsql/instance-id:region:instance-name for instance-id:region:instance-name
2020/10/30 16:47:54 Ready for new connections
To connect the proxy, I opened another terminal and entered this psql command but failed.
psql -U postgres -h /tmp/cloudsql/instance-id:region:instance-name
psql: error: could not connect to server: could not connect to server: Not a directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/cloudsql/instance-id:region:instance-name/.s.PGSQL.5432"?
What should I do additionally for connecting to the proxy?
from what I see you are passing a wrong connection name
wrong --> instance-id:region:instance-name
correct --> PROJECT_ID:region:instance-name
You can find the connection name from the
console --> Cloud SQL --> INSTANCE --> Connect to this instance --> Connection name

CHAINLINK NODE: How might I approach fixing "unable to lock ORM" errors?

I am not overly familiar with the process of setting up a chainlink node. I have done so today, but am running into an issue. On the very last step, when attempting to start the chainlink node I put the following into the command line:
cd ~/.chainlink-kovan && docker run -p 6688:6688 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink local n
When this runs the pulls all say "pull complete"
I am getting the following ORM errors:
2020-10-15T22:07:30Z [ERROR] unable to lock ORM: dial tcp
127.0.0.1:5432: connec t: connection refused logger/default.go:139
stacktrace=github.com/smartcontrac
tkit/chainlink/core/logger.Error
/usr/local/go/src/runtime/proc.go:203 2020-10-15T22:07:30Z [FATAL]
Unable to initialize ORM: dial tcp 127.0.0.1:5432:
connect: connection refused unable to open for gorm DB
I am not sure what might be the issue. Could someone point me in the direction I might start in the debug this issue?
[ERROR] unable to lock ORM is the default message given when the data is not able to be reached, and it also don't see another user with a lock. You can see the reason it can't connect to the ORM is because: dial tcp 127.0.0.1:5432: connec t: connection refused To fix, you can try a number of different things:
1. Try to access the postgress database using the parameters of the DATABASE_URL
If you can't get into the DB with the parameters of the DATABASE_URL there might be something wrong with that. You can see if you can connect by downloading the psql client. If on ubuntu you can use:
sudo apt-get update
sudo apt-get install postgresql-client
and then running something like psql -h IP_HERE -U USER_HERE and then entering your password
2. Add --network host for local databases
If you are running your node/database locally you'll have to add --network host to your chainlink docker command.
3. Try localhost, 172.17.0.1, or use a cloud DB if you're using a mac.
Docker is a little tricky when it comes to IPs. If you are running a local DB and you are trying to use 127.0.0.1, you may want to try localhost. On a mac, you'll run into issues since the docker gateway doesn't play nicely with macos, and easy work around is to get a database URL from a cloud database like on heroku, GCP, or AWS.
If none of these work for you, please add a comment and we can update this answer.
After reviewing Patrick's video, I noticed that that I was copying the Public IP, when in fact, the private IP from GCP is what you need you use in you command to run docker

Docker: Unable to connect to a remote Postgres server from a Docker Container

I installed the Metabase application, created a Docker container (on one Linux host) and I want to connect to a remote Postgres database (on a second Linux host) from the Docker container. The setup of Metabase allows entry of connection parameters to the Postgres database. Each time I enter the proper connection parameters in Metabase I get a database connection error. I can connect to the Postgres database from the host running the container using PSQL with no problem. My question is, is there something within Docker or the remote Postgres server that I must setup in order to allow a connection between a Docker container and a remote database? I realize this is normally caused by incorrect host/port information, problems with DNS, firewall blocking or other network problems. I am new to Docker and I do not know where to look or what to setup to make this work. Does anyone have suggestions about how to make this connection work? Thank you!

pgAdmin4: Unable to connect to Amazon EC2 via SSH Tunnel

I have Amazon EC2 instance running Ubuntu. I have installed and configured PostgreSQL.
Contents of the file /etc/postgresql/9.3/main/pg_hba.conf:
local all all md5
host all all 0.0.0.0/0 md5
Also in postgresql.conf
I have set listen_addresses='*'.
The test command below is successfully starting psql console.
psql -U postgres testdb
Now I am trying to connect pgAdmin4 from MacOS.
I have created a SSH tunnel with following command:
ssh -i ~/.ssh/test.pem -fN -L 5433:localhost:5432 ubuntu#mytestdomain.com
Now I have following details in pgAdmin:
When I save, I get this output:
Unable to connect to server: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request.
What am I doing wrong ?
Here is the solution,
install pgadmin 4 into your system. and configure the below-added configurations. if the below configurations do not work then please check that DB user permissions on AWS. because of the restriction on IP level so it may not be able to access.