1

I'm new to Rails and Ruby and I'm trying to get an existing project to work on my environment, I'm using Ubuntu 14.04 with Rubymine, Rails 4.2 and Ruby 2.2.0

Here's the migration file:

class CreatePeople < ActiveRecord::Migration
  def change

    create_table :people do |t|
      t.string :pid, limit: 20, null: false
      t.string :firstname, limit: 40, null: false
      t.string :lastname, limit: 40, null: false
      t.integer :age
      t.string :gender, limit: 4, null: false
      t.datetime :birthday
      t.string :country, limit: 2
      t.timestamps null: false
    end

    add_index :people, :firstname
    add_index :people, :lastname
    add_index :people, :country
    add_index :people, :pid, unique: true
  end
end

My database.yml:

config=/opt/local/lib/postgresql84/bin/pg_config

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: vasco_annuaire

  <<: *default
  database: annuaire_test


  <<: *default
  database: annuaire_production
  username: annuaire
  password: <%= ENV['ANNUAIRE_DATABASE_PASSWORD'] %>

running rake db:create gives me

"role ferenan does not exist"

launching localhost:3000 gives

ActiveRecord::NoDatabaseError FATAL: role "ferenan" does not exist

Extracted source (around line #661): 659 660 661 662 663 664

    rescue ::PG::Error => error
      if error.message.include?("does not exist")
        raise ActiveRecord::NoDatabaseError.new(error.message, error)
      else
        raise
      end

I'm also having trouble connecting to Postgresql through Pg-Admin-III

server name : Postgresql
host : localhost
port : 5432
maintenance_db : postgres
username : postgres
no password

Using these parameters I get the message :

fe_sendauth : no password supplied

I've added this line to my pg_hba.conf:

host    sa    all         192.168.0.nnn/32     trust

and this one to my postgresql.conf:

listen_addresses = '*'

and run the following command afterwards:

sudo /etc/init.d/postgresql reload

I don't know what to do and how to make these things work together, but the project does work as my superior showed me earlier, unfortunately he's not available at the moment to help me get this figured out. Any help would very much be appreciated.

1 Answer 1

3

By default, when no username is specified, postgesql tries to connect using the current user (in your case ferenan), but in a vanilla installation, no such role exists.

To connect to role postgres, change your database.yml to:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: postgres

Regarding the Pg-Admin-III, it seems that you are trying to connect from localhost, so I suggest you try to add the following to pg_hba.conf (which trusts requests from localhost with md5 authorization):

host    all             all             127.0.0.1/32            trust
Sign up to request clarification or add additional context in comments.

9 Comments

Making these changes then running rake db:create gave me : FATAL: Peer authentication failed for user "postgres". Still couldn't connect to Postgresql via pg-admin it still gives : fe_sendauth : no password supplied
@ferenan - I've had some errors in the second part of my answer (the wrong file, and the wrong authentication type), sorry, try it now.
I figured it was the pg_hba.conf file, but even changing md5 to trust still gives the same error : FATAL: Peer authentication failed for user "postgres"
@ferenan - do you have any other lines in the pg_hba.conf? look for peer authorization.
Yes I have these two lines uncommented: local all postgres peer local all all peer
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.