Skip to content

Commit b4e0ba3

Browse files
committed
Include documentation on the URL format in the README
This summarizes the common forms, but omits some of the more particular, and unnecessary forms, such as specifying UNIX domain sockets with `pg://` URLs.
1 parent 9b89828 commit b4e0ba3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,54 @@ var parse = require('pg-connection-string').parse;
1919

2020
var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
2121
```
22+
23+
The resulting config contains a subset of the following properties:
24+
25+
* `host` - Postgres server hostname or, for UNIX doamain sockets, the socket filename
26+
* `port` - port on which to connect
27+
* `user` - User with which to authenticate to the server
28+
* `password` - Corresponding password
29+
* `database` - Database name within the server
30+
* `client_encoding` - string encoding the client will use
31+
* `ssl`, either a boolean or an object with properties
32+
* `cert`
33+
* `key`
34+
* `ca`
35+
* any other query parameters (for example, `application_name`) are preserved intact.
36+
37+
## Connection Strings
38+
39+
The short summary of acceptable URLs is:
40+
41+
* `socket:<path>?<query>` - UNIX domain socket
42+
* `postgres://<user>:<password>@<host>:<port>/<database>?<query>` - TCP connection
43+
44+
But see below for more details.
45+
46+
### UNIX Domain Sockets
47+
48+
When user and password are not given, the socket path follows `socket:`, as in `socket:/var/run/pgsql`.
49+
This form can be shortened to just a path: `/var/run/pgsql`.
50+
51+
When user and password are given, they are included in the typical URL positions, with an empty `host`, as in `socket://user:pass@/var/run/pgsql`.
52+
53+
Query parameters follow a `?` character, including the following special query parameters:
54+
55+
* `db=<database>` - sets the database name (urlencoded)
56+
* `encoding=<encoding>` - sets the `client_encoding` property
57+
58+
### TCP Connections
59+
60+
TCP connections to the Postgres server are indicated with `pg:` or `postgres:` schemes (in fact, any scheme but `socket:` is accepted).
61+
If username and password are included, they should be urlencoded.
62+
The database name, however, should *not* be urlencoded.
63+
64+
Query parameters follow a `?` character, including the following special query parameters:
65+
* `host=<host>` - sets `host` property, overriding the URL's host
66+
* `encoding=<encoding>` - sets the `client_encoding` property
67+
* `ssl=1`, `ssl=true`, `ssl=0`, `ssl=false` - sets `ssl` to true or false, accordingly
68+
* `sslcert=<filename>` - reads data from the given file and includes the result as `ssl.cert`
69+
* `sslkey=<filename>` - reads data from the given file and includes the result as `ssl.key`
70+
* `sslrootcert=<filename>` - reads data from the given file and includes the result as `ssl.ca`
71+
72+
A bare relative URL, such as `salesdata`, will indicate a database name while leaving other properties empty.

0 commit comments

Comments
 (0)