SSL connections for Postgrex in Livebook

I am trying to query a Postgres database that requires SSL connections from a Livebook session.

opts = [
  hostname: "database.url.com",
  port: 5432,
  username: "username",
  password: "password",
  database: "my_db",
  ssl: true
]

{:ok, conn} = Postgrex.start_link(opts)

The result of evaluating this cell is:

** (RuntimeError) SSL connection can not be established because `:ssl` application is not started,
you can add it to `extra_applications` in your `mix.exs`:

  def application do
    [extra_applications: [:ssl]]
  end

    (postgrex 0.16.3) lib/postgrex.ex:652: Postgrex.ensure_deps_started!/1
    (postgrex 0.16.3) lib/postgrex.ex:267: Postgrex.start_link/1

The livebook is running inside the livebook/livebook Docker container per the instructions on the readme.

How can I start the SSL application for my Livebook session?

1 Like

Hey @msharp welcome! You can simply do :ssl.start()

3 Likes

Thankyou @benwilson512

nice! I’m tried Application.start :ssl without success… any reason to this does not works?

Hi @NetonD if you’re having an issue please show the code you are running and the error you get.

When I do Application.start :ssl I get this error tuple: {:error, {:not_started, :crypto}}. But, when I do just the :ssl.start() works fine.

Edit: Just adding that there is no logs, just error tuple is returned and I’m executing in iex environment