Skip to content
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

[fix] Make postgres connections magically work in common setups #352

Merged
merged 2 commits into from
Dec 21, 2021

Conversation

liclac
Copy link
Contributor

@liclac liclac commented Dec 20, 2021

First of all, this changes the default database name to gotosocial; dumping our tables into the system postgres table probably shouldn't be the default.

Second, I started reading the pgx code, and it actually goes to great lengths to make postgres connections work out of the box:

  • It defaults to using your system username to authenticate.
  • It supports ~/.pg_service.conf and TLS client certificates in standard paths.
  • It tries to make UNIX socket connections if it can find a socket at a common path. (not on Windows)
  • ...before falling back to TCP on localhost.

Which means that if we just unset our default credentials, and apply them only if actually set in our config, the database connection should Just Work(tm) anywhere psql gotosocial would.

https://github.com/jackc/pgconn/blob/a123e5b4e575b5eb3c68ae4ab87c508d341242df/defaults.go
https://github.com/jackc/pgconn/blob/a123e5b4e575b5eb3c68ae4ab87c508d341242df/defaults_windows.go

@tsmethurst tsmethurst changed the title Make postgres connections magically work in common setups [fix] Make postgres connections magically work in common setups Dec 20, 2021
The pgx code actually goes to great lengths to make postgres connections
Just Work(tm) out of the box, including supporting `~/.pg_service.conf`,
SSL certificates, UNIX sockets if it can find a socket at a common path,
and falling back to TCP to localhost if not.

(On Windows, it won't try to use UNIX sockets, but will read credentials
from %appdata% as is standard over there.)

By applying our flags as overrides only when they're specified, database
connections should Just Work(tm) anywhere `psql gotosocial` does.
@tsmethurst tsmethurst merged commit ed9158f into superseriousbusiness:main Dec 21, 2021
@liclac liclac deleted the database-magic branch December 21, 2021 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants