Skip to content

Instantly share code, notes, and snippets.

@ola-dola
Created August 11, 2023 16:34
Show Gist options
  • Save ola-dola/1ed6bd3138b7a386a032cd0ff1a50b07 to your computer and use it in GitHub Desktop.
Save ola-dola/1ed6bd3138b7a386a032cd0ff1a50b07 to your computer and use it in GitHub Desktop.
notes from setting up Rails to use postgres on Ubuntu 22.04

Installation guide: https://gorails.com/setup/ubuntu/22.04.

Note: the guide above is only useful up until the part where you need to setup Postgres. We'll use another guide to install and setup Postgres.

Postgres

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-22-04

Edit pg_hba.conf to use password auth for local rails connections

https://stackoverflow.com/a/18664239/15065042. Your pg_hba.conf section talked about in the link above should look like:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5

#Additonal notes if you check your list of roles and you don't see a postgres as a super user, you need to create one. And also a database named postgres.

=> Setup another role you'd add to your rails app to use username and password. Would save you headache after you've switched to md5 auth.

Helpful commands

sudo -i -u postgres: enter postgres as user terminal psql in above: enter interactive repl of sort where you can write raw query and such. --- In psql repl ---

  • \l: list databases
  • \du: list users/roles
  • \du+: more info with cmd above
  • \q: quit psql repl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment