Skip to content

Commit 4978825

Browse files
authored
Documentation improvements for ipv6 and unix sockets (#4615)
1 parent 098ea72 commit 4978825

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ See the [getting started guide](https://hexdocs.pm/ecto/getting-started.html) an
8181

8282
* [The Little Ecto Cookbook](https://dashbit.co/ebooks/the-little-ecto-cookbook), a free ebook by Dashbit, which is a curation of the existing Ecto guides with some extra contents
8383

84+
### IPv6 support
85+
86+
Does not happen automagically. If your database's host resolves to ipv6 address you should
87+
add `socket_options: [:inet6]` to configuration block like below:
88+
89+
```elixir
90+
import Mix.Config
91+
92+
config :your_app, :tds_conn,
93+
hostname: "db12.dc0.comp.any",
94+
username: "test_user",
95+
password: "test_password",
96+
database: "lomaster",
97+
port: 1433,
98+
socket_options: [:inet6] # here you may also add all the options for `gen_tcp` erlang module
99+
```
100+
84101
## Usage
85102

86103
You need to add both Ecto and the database adapter as a dependency to your `mix.exs` file. The supported databases and their adapters are:

guides/introduction/Getting Started.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,49 @@ This tells our application about the repo, which will allow us to run commands s
119119

120120
We've now configured our application so that it's able to make queries to our database. Let's now create our database, add a table to it, and then perform some queries.
121121

122+
### IPv6 support
123+
124+
Does not happen automagically. If your database's host resolves to ipv6 address you should
125+
add `socket_options: [:inet6]` to configuration block like below:
126+
127+
```elixir
128+
import Mix.Config
129+
130+
config :your_app, :your_connection,
131+
hostname: "db12.dc0.comp.any", # just an example
132+
socket_options: [:inet6] # here you may also add all the options for `gen_tcp` erlang module
133+
# ... other options
134+
```
135+
136+
### Unix socket connection
137+
138+
For faster communication, you may consider communicating with Postgres via Unix sockets.
139+
If your PG server was started on the same machine as your code, you could check that.
140+
141+
```bash
142+
% sudo grep unix_socket_directories /var/lib/postgres/data/postgresql.conf
143+
unix_socket_directories = '/run/postgresql'
144+
```
145+
146+
```bash
147+
% ls -lah /run/postgresql
148+
итого 4,0K
149+
drwxr-xr-x 2 postgres postgres 80 июн 4 10:58 .
150+
drwxr-xr-x 35 root root 840 июн 4 21:02 ..
151+
srwxrwxrwx 1 postgres postgres 0 июн 5 07:41 .s.PGSQL.5432
152+
-rw------- 1 postgres postgres 61 июн 5 07:41 .s.PGSQL.5432.lock
153+
```
154+
155+
So you have postgresql started and listening on the socket.
156+
157+
Add then this line to config block:
158+
159+
```elixir
160+
config :your_app, :your_connection,
161+
# ...
162+
socket_dir: "/run/postgresql"
163+
```
164+
122165
## Setting up the database
123166

124167
To be able to query a database, it first needs to exist. We can create the database with this command:

0 commit comments

Comments
 (0)