-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add further common Postgres Unix socket URL examples #459
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,19 @@ A `socket` or `host` parameter can be specified to connect through a unix socket | |
DATABASE_URL="postgres://username:password@/database_name?socket=/var/run/postgresql" | ||
``` | ||
|
||
For passwordless authentication like Postgres [peer auth-method](https://www.postgresql.org/docs/current/auth-pg-hba-conf.html) the URL can be shortened: | ||
|
||
```sh | ||
DATABASE_URL="postgres://username/database_name?socket=/var/run/postgresql" | ||
``` | ||
|
||
Additionaly, when the username and database name are identical the URL can be shortened further: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, this is also surprising to me. I guess it's postgres-specific behavior. It's not something dbmate does. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, i tested it with Postgres 14.9. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It actually has nothing to do with the username and database name being identical. When relying on Postgres peer authentication method, specifying the username and hostname in the connection string are unnecessary: Check this out:
I think adding these shorthand Postgres database URL examples to the documenation might be handy, but the current PR's explanation for why they work in the README are not accurate. |
||
|
||
```sh | ||
DATABASE_URL="postgres:///database_name?socket=/var/run/postgresql" | ||
``` | ||
|
||
|
||
A `search_path` parameter can be used to specify the [current schema](https://www.postgresql.org/docs/13/ddl-schemas.html#DDL-SCHEMAS-PATH) while applying migrations, as well as for dbmate's `schema_migrations` table. | ||
If the schema does not exist, it will be created automatically. If multiple comma-separated schemas are passed, the first will be used for the `schema_migrations` table. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? I would have expected needing at least
postgres://username@/database_name?socket=/var/run/postgresql
(with@
, to differentiate it from a hostname)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i tested it with Postgres 14.9.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amacneil This only works with a local connection with the
peer
authentication method, because in that specific mode, Postgres isn't using the hostname or username from the connection string, as it's connecting locally (so hostname is irrelevant) andpeer
auth relies on Postgres getting the OS username, so the username from the connection string is irrelevant.In other words, this works:
Notice that I'm doing this as user
postgres
, which happens to be a valid database user. If I try this as userroot
that isn't a valid user in this Postgres database, we get this error: