Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure phoenix to use sockets with postgresql

PostgreSQL supports using unix sockets rather than TCP sockets. How do I configure the following block to use unix sockets.

# Configure your database
config :my_app, Sample.Repo,
  adapter: Ecto.Adapters.Postgres,
  database: "ecto_simple",
  username: "postgres",
  password: "postgres"
like image 295
steakunderscore Avatar asked Sep 03 '25 09:09

steakunderscore


1 Answers

As of March 2018, Postgrex now supports connecting via sockets.

This can be done by supplying a socket or socket_dir option. Here's the changelog from where I picked this up and the source code where you can see an exhaustive list of all options.

From the source code:

  • :socket_dir - Connect to Postgres via UNIX sockets in the given directory; The socket name is derived based on the part. This is the preferred method for configuring sockets and it takes precedence over the hostname. If you are connecting to a socket outside of the Postgres convention, use :socket instead;

  • :socket - Connect to Postgres via UNIX sockets in the given path.

This is especially useful (I suppose) if you're on AppEngine which requires you to connect through an SQL proxy through localhost (127.0.01) which works only through a proxy connection.

like image 197
dsignr Avatar answered Sep 04 '25 23:09

dsignr