I am running my development on Ubuntu 11.10, and RubyMine
Here is my development settings for the database.yml: which RubyMine created for me
development:
adapter: postgresql
encoding: unicode
database: mydb_development
pool: 5
username: myuser
password:
when I try to run the app, I get this error below, it seems that I didn't create a 'project' user yet, but, how can I create a user and grant it a database in postgres ? if this is the problem, then, what is the recommended tool to use in Ubuntu for this task ? if this is not the problem, then, please advice.
Exiting
/home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize': FATAL: Peer authentication failed for user "project" (PG::Error)
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `new'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `connect'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:303:in `new_connection'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:313:in `checkout_new_connection'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:237:in `block (2 levels) in checkout'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:232:in `loop'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:232:in `block in checkout'
from /home/sam/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activerecord-3.2.3/lib/active_record/railtie.rb:91:in `block (2 levels) in <class:Railtie>'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:418:in `_run__757346023__prepare__404863399__callbacks'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `__run_callback'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/actionpack-3.2.3/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/actionpack-3.2.3/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/sam/RubymineProjects/project/config/environment.rb:5:in `<top (required)>'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
from /home/sam/RubymineProjects/project/config.ru:4:in `block in <main>'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/sam/RubymineProjects/project/config.ru:1:in `new'
from /home/sam/RubymineProjects/project/config.ru:1:in `<main>'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/commands/server.rb:46:in `app'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in `start'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
from /home/sam/.rvm/gems/ruby-1.9.3-p0@project/gems/railties-3.2.3/lib/rails/commands.rb:50:in `<top (required)>'
from /home/sam/RubymineProjects/project/script/rails:6:in `require'
from /home/sam/RubymineProjects/project/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
Process finished with exit code 1
I was facing same problem on Ubuntu machine so I removed this error by following some steps. Switch to postgres user
$ sudo su - postgres
it will ask for password and by default password is
postgres
After switch the user to postgres, open psql console
so check the version of postgres if multiple versions are available
Now Open
postgres user
vim /etc/postgresql/9.1/main/pg_hba.conf
9.1
is version return form upper commandand replace
to
sudo service postgresql restart
I write steps on my blog also
http://tarungarg402.blogspot.in/2014/10/set-up-postgresql-on-ubuntu.html
This is the most foolproof way to get your rails app working with postgres in the development environment in Ubuntu 13.10.
1) Create rails app with postgres YAML and 'pg' gem in the Gemfile:
2) Give it some CRUD functionality. If you're just seeing if postgres works, create a scaffold:
3) As of
rails 4.0.1
the-d postgresql
option generates a YAML that doesn't include a host parameter. I found I needed this. Edit the development section and create the following parameters:Note the
database
parameter is for a database that doesn't exit yet, and theusername
andpassword
are credentials for a role that doesn't exist either. We'll create those later on!This is how
config/database.yml
should look (no shame in copypasting :D ):4) Start the postgres shell with this command:
4a) You may get this error if your current user (as in your computer user) doesn't have a corresponding administration postgres role.
Now I've only installed postgres once, so I may be wrong here, but I think postgres automatically creates an administration role with the same credentials as the user you installed postgres as.
4b) So this means you need to change to the user that installed postgres to use the psql command and start the shell:
And then run
5) You'll know you're in the postgres shell because your terminal will look like this:
6) Using the postgresql syntax, let's create the user we specified in
config/database.yml
's development section:Now, there's some subtleties here so let's go over them.
You should see this in your terminal:
That means, "ROLE CREATED", but postgres' alerts seem to adopt the same imperative conventions of git hub.
7) Now, still in the postgres shell, we need to create the database with the name we set in the YAML. Make the user we created in step 6 its owner:
You'll know if you were successful because you'll get the output:
8) Quit the postgres shell:
9) Now the moment of truth:
If you get this:
Congratulations, postgres is working perfectly with your app.
9a) On my local machine, I kept getting a permission error. I can't remember it exactly, but it was an error along the lines of
Though I'd advise thinking very carefully about recursively setting write privaledges on a production machine, locally, I gave my whole app read write privileges like this:
9b) Climb up one directory level:
9c) Set the permissions of the my_application directory and all its contents to 666:
9d) And run the migration again:
Some tips and tricks if you muck up
Try these before restarting all of these steps:
The mynewusername user doesn't have privileges to CRUD to the
my_app_development
database? Drop the database and create it again with mynewusername as the owner:1) Start the postgres shell:
2) Drop the
my_app_development
database. Be careful! Drop means utterly delete!3) Recreate another
my_app_development
and make mynewusername the owner:4) Quit the shell:
The
mynewusername
user can't log into the database? Think you wrote the wrong password in the YAML and can't quite remember the password you entered using the postgres shell? Simply alter the role with the YAML password:1) Open up your YAML, and copy the password to your clipboard:
2) Start the postgres shell:
3) Update
mynewusername
's password. Paste in the password, and remember to put single quotes around it:4) Quit the shell:
Trying to connect to localhost via a database viewer such as Dbeaver, and don't know what your postgres user's password is? Change it like this:
1) Run
passwd
as a superuser:2) Enter your accounts password for
sudo
(nothing to do with postgres):3) Create the postgres account's new passwod:
Getting this error message?:
4) You need to give your user the ability to create databases. From the psql shell:
For permanent solution:
The problem is with your pg_hba. This line:
Should be
Then restart your postgresql server after changing this file.
If you're on Linux, command would be
If you installed postresql on your server then just host: localhost to database.yml, I usually throw it in around where it says pool: 5. Otherwise if it's not localhost definitely tell that app where to find its database.
Make sure your user credentials are set correctly by creating a database and assigning ownership to your app's user to establish the connection. To create a new user in postgresql 9 run:
set the postgresql user password if you haven't, it's just backslash password.
Create a new user and password and the user's new database:
Now update your database.yml file after you've confirmed creating the database, user, password and set these privileges. Don't forget host: localhost.
You can go to your /var/lib/pgsql/data/pg_hba.conf file and add trust in place of Ident It worked for me.
For further details refer to this issue Ident authentication failed for user
If you get that error message (
Peer authentication failed for user (PG::Error)
) when running unit tests, make sure the test database exists.