0

I started the postgresql server by doing this:

sudo service postgresql start

then I connected to the service:

sudo sudo -u postgres psql

then I created a database (i'm trying to add a voting system to my app):

postgres=# CREATE DATABASE "votes";

but i still have the same problem.

Also, when I do

rake db:create

I get a role "ubuntu" does not exist error

Here is my database.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
# default: &default
#   adapter: sqlite3
#   pool: 5
#   timeout: 5000

# development:
#   <<: *default
#   database: db/development.sqlite3

# # Warning: The database defined as "test" will be erased and
# # re-generated from your development database when you run "rake".
# # Do not set this db to the same as development or production.
# test:
#   <<: *default
#   database: db/test.sqlite3

# production:
#   <<: *default
#   database: db/production.sqlite3

# FOR HEROKU -- POSTGRES DB SETUP
# UNCOMMENT WHEN WORKING LOCALLY.
development:
  adapter: postgresql
  database: votes
  pool: 5
  timeout: 5000
  username: ubuntu

test:
  adapter: postgresql
  database: planit_test
  pool: 5
  timeout: 5000


# production:
#   <<: *default
#   database: db/production.sqlite3

I'm trying to create an ubuntu rold:

$ sudo sudo -u postgres psql
psql (9.3.10)
Type "help" for help.

postgres=# CREATE ROLE ubuntu SUPERUSER
postgres-# \q
$ rake db:migrate
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "ubuntu" does not exist
coderk
  • 71
  • 12
  • Have you configured your databases.yml? – Guido Nov 04 '15 at 19:22
  • 2
    check `database.yml` and change the username. If you want to connect with user `ubuntu` then you have to create it first in postgres. Check the [create role](http://www.postgresql.org/docs/8.3/static/sql-createrole.html) documentation. After you create it make sure you [alter role](http://www.postgresql.org/docs/9.0/static/sql-alterrole.html) with correct permisions. – radubogdan Nov 04 '15 at 19:23
  • yes i connected to the service. and then I did CREATE USER ubuntu SUPERUSER. the usernmae "ubuntu" is in my database.yml file. Still getting same problem – coderk Nov 04 '15 at 19:35
  • In Postgres, users and roles are not equivalent. If `CREATE USER` isn't sufficient, you should re-read @radubogdan's comment and look into `CREATE ROLE` and `ALTER ROLE`. – Matt Nov 04 '15 at 19:55

2 Answers2

2

The error you are getting about role "ubuntu" does not exist is because of the user (or role) that you are trying to use to access your postgress session from the app.

As your database.yml specified

development:
  adapter: postgresql
  database: votes
  pool: 5
  timeout: 5000
  username: ubuntu

Notice the last line: username: ubuntu?

Two ways you can go about this are:

1) Remove that line (maybe comment it out) - This will make your app connect to your postgress session with the default set name (or role, as you may want to call it). The default most times will be postgress or your username on your machine.

2) create the role ubuntu for your postgress. To do this, you can check out this answer.

Either of the above two ways should work well for you.

Community
  • 1
  • 1
x6iae
  • 4,074
  • 3
  • 29
  • 50
  • I had just added the username: ubuntu to the database.yml, thinking it would be a fix. however, i'v deleted it and I still get the same issue of NoDatabseError. I'll try your second option – coderk Nov 04 '15 at 21:51
  • I'm confused on what I'm supposed to do. taking your advice, look at what my results are (I edited the question above) when I try to create a new role. – coderk Nov 04 '15 at 21:58
  • When you go into `psql` and list all users `\du`, what is the output? – x6iae Nov 04 '15 at 22:06
  • the only role name listed is postgres – coderk Nov 04 '15 at 22:27
  • try to use `postgres` then as the username from inside your `database.ym`. what happens when you do this? – x6iae Nov 05 '15 at 04:09
  • And also, what are the priviledges for this your `postgres` user? Eg: [check mine](https://www.dropbox.com/s/dna2r31ryubog55/Screen%20Shot%202015-11-05%20at%205.59.11%20AM.png?dl=0) – x6iae Nov 05 '15 at 05:02
0

Use postgres instead, it's default role from Postgre. Or try this one:

    sudo su - postgres
    psql template1

then

    CREATE ROLE ubuntu superuser createdb login;

You can check if the role exist or not with command:

    \du