Mind Dump, Tech And Life Blog
written by Ivan Alenko
published under license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)copy! share!
posted at 05. Dec '20

Howto Set Up Postgres For Rails Development

The first step and always fucking frustrating is to get to postgres console and then create database user:

Postgres 13.1 in MacOS Big Sur homebrew:

psql -d template1

Older versions something like this:

sudo -u postgres psql -h localhost

For Rails development the superuser is needed. Since db:drop removes also extensions on database which need a superuser to be created on a database.

Like this:

rails aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied to create extension "pgcrypto"
HINT:  Must be superuser to create this extension.

I tried to do it with regular user with privileges, but didn’t succeed and was such a pain.

CREATE USER oni_sorceress WITH ENCRYPTED PASSWORD 'my password';
ALTER USER oni_sorceress WITH SUPERUSER;

And you are done, just run:

bin/rails db:create db:migrate db:seed

Add Comment