Hi,
I started using Livebook recently. Wanted to learn Ecto and its internals using Postgres DB. While setting it up I ran in to few issues.
Live book Setup
- Linux Ubuntu 22.04
- Docker image is used to run the live book with local storage options.
Postgres Setup
- Postgres version 14.
Here are some cofigurations I need to modify for the Docker Image to access my local postgres
# Enable postgress to be accessible from any client.
sudo nano /etc/postgresql/14/main/postgresql.conf
# Modified this line
listen_addresses = '*'
# give access to the docker
sudo nano /etc/postgresql/*/main/pg_hba.conf
# Add this line at the bottom of the file.
host all all 172.17.0.0/16 md5
Save and exit the files and restart the postgres sudo systemctl restart postgresql
Command used to start the Livebook docker image
sudo docker run -p 8080:8080 -p 8081:8081 --pull always --add-host=host.docker.internal:host-gateway -u $(id -u):$(id -g) -v $(pwd):/data ghcr.io/livebook-dev/livebook
Notice the additional --add-host=host.docker.internal:host-gateway
option in the command.
With this changes I added the required dependeices in the Livebook and in the Elixir cell I have the following code.
# Create a named connection
opts = [
hostname: "host.docker.internal",
username: "your_user_name",
database: "ecto_db_new",
password: "your_password",
port: 5432,
name: {:global, :my_db_conn} # Give our connection a name
]
{:ok, conn} = Postgrex.start_link(opts)
# Test it with a more complex query
Postgrex.query!(conn, "SELECT current_database(), current_user", [])
I see that database connection is made and but my logs are filled with database connection errors. Not sure why even after the successful connections we see the error messages?
Here is the snapshot of the issue
Can some one explain what is happening? is this a bug?
Best,