Postgresql install errors on Ubuntu 16.04

While trying to install Discourse on my laptop (Ubuntu 16.04) using this guide, I got some errors like this:

PG::InsufficientPrivilege: ERROR: permission denied to create extension "hstore"

and:

rails aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "discourse_test_multisite" does not exist

I got rid of the errors by changing this:

# Postgresql
sudo su postgres
createuser --createdb --superuser -Upostgres $(cat /tmp/username)
psql -c "ALTER USER $(cat /tmp/username) WITH PASSWORD 'password';"
psql -c "create database discourse_development owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
psql -c "create database discourse_test        owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
psql -d discourse_development -c "CREATE EXTENSION hstore;"
psql -d discourse_development -c "CREATE EXTENSION pg_trgm;"
exit

to this:

# Postgresql
sudo su - postgres
createuser --createdb --superuser -Upostgres $(cat /tmp/username)
psql -c "ALTER USER $(cat /tmp/username) WITH PASSWORD 'password';"
psql -c "create database discourse_development owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
psql -c "create database discourse_test        owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
psql -c "create database discourse_test_multisite        owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
psql -d discourse_development -c "CREATE EXTENSION hstore;"
psql -d discourse_development -c "CREATE EXTENSION pg_trgm;"
psql -d discourse_test -c "CREATE EXTENSION hstore;"
psql -d discourse_test -c "CREATE EXTENSION pg_trgm;"
psql -d discourse_test_multisite -c "CREATE EXTENSION hstore;"
psql -d discourse_test_multisite -c "CREATE EXTENSION pg_trgm;"
exit

Diff:

2c2
< sudo su postgres
---
> sudo su - postgres
6a7
> psql -c "create database discourse_test_multisite        owner $(cat /tmp/username) encoding 'UTF8' TEMPLATE template0;"
8a10,13
> psql -d discourse_test -c "CREATE EXTENSION hstore;"
> psql -d discourse_test -c "CREATE EXTENSION pg_trgm;"
> psql -d discourse_test_multisite -c "CREATE EXTENSION hstore;"
> psql -d discourse_test_multisite -c "CREATE EXTENSION pg_trgm;"

I’m too new to Rails/Discourse to know if it’s just my laptop or if I should add them to the docs, but I’ll leave the fix here in case someone else finds it useful. :slight_smile:

(If it’s something that should go in the docs, let me know and I could make a pull request.)

1 Like

I was getting the same error but I realized my problem was that I initially had a role with my username so what I needed to do was to drop that role in postgres and then follow the steps again:

# Postgresql
sudo -u postgres -i
createuser --superuser -Upostgres $(cat /tmp/username)
psql -c “ALTER USER $(cat /tmp/username) WITH PASSWORD ‘password’;”
exit

1 Like