Why is PostgreSQL rejecting my password when I try to migrate? - ruby-on-rails

I have PostgreSQL installed via this link and all seems good. I can use the GUI interface and I can see my databases but when I run rake db:migrate I get the following error:
$ rake db:migrate
(in /Users/tamer/Sites/sample)
rake aborted!
FATAL: password authentication failed for user "tamer"
(See full trace by running task with --trace)
Here is my database.yml file:
development:
adapter: postgresql
database: test
encoding: unicode
host: localhost
user: postgres
password: mypass
timeout: 5000
Where "mypass" is my password I set.
Here is a picture of it running
Any ideas what i am doing wrong?

Well something doesn't quite add up. The error message refers to a user "tamer" but the database.yml file has the "postgres" user. Are you sure this is the database.yml file that's being used? What happens when you try to log in with the GUI tool with either user?

Related

fe_sendauth: no password supplied error after setting up PostgreSQL database on Cloud9 IDE

So I've set up a PostgreSQL database on my cloud9 IDE account according to the instructions of the top voted comment: Cloud9 postgres.
This is what my database.yml file looks like:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: <%= ENV['USERNAME'] %>
password: <%= ENV['PASSWORD'] %>
host: <%= ENV['IP'] %>
development:
<<: *default
database: sample_app_development
test:
<<: *default
database: sample_app_test
production:
<<: *default
database: sample_app_production
I then created a user model, migrated it, and reloaded my app. However when I loaded the app on the local server using this command: rails server -b $IP -p $PORT on the cloud9 command line, I get the following error message: fe_sendauth: no password supplied error. I do not understand what is going wrong since I have created a superuser with a password and have included those in my database.yml file. The only thing I found was that this error can be fixed by changing the pg_hba.conf file to trust the local server. However I thought the whole point of creating a superuser and password in the Cloud9 IDE was so that you don't have to do this. Also Cloud9 doesn't give you access to the pg_hba.conf file.
You don't need to change the pg_hba.conf file.
Just type in these commands in the terminal:
$ source ~/.profile
$ rake db:create
$ rake db:migrate
Then restart the server normally.
I know you already ran the source ~/.profile command at the beginning of the instructions you mentioned (I have used the answer before and struggled with the same issue) but for some mysterious reason Cloud9 environment (I never had to to do any of this on my Mac) requires to manually source the '.profile' file again after doing the setup specified in those instructions (Cloud 9 just decides to be weird sometimes - like all machines... duh!). The second command creates the new pg database in your development environment with all the configuration from your pg gem and your database.yml file.
The final 'migrate' command might not be necessary but again for mysterious reasons I have also had database issues fixed after just running a 'rake db:migrate' (If I am correct it just updates your database to be able to use your Models or any new dummy data you might have added to your development environment).
Hope this helps.

No password Supplied, but no changes made

I just opened an app I haven't worked on in a while to get back to work. When I tried opening the app in the browser on my local machine, I get this error PG::ConnectionBad (fe_sendauth: no password supplied):. I haven't messed with it lately, so I'm not sure what might have broken. Here's my database.yml (just default rails created verbage)
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
host: localhost
development:
<<: *default
database: project2_development
Any ideas what might have broken? Like I said, I haven't changed anything recently with this app, so I'm not sure what's going on.
The error clearly shows that postgresql the password you have not supplied, and after successful installation of gem 'pg'
perform the following,
sudo -i -u postgres
you will be as a user of postgres eg:- postgres#user >
psql
you will login in postgresql console
alter user user_name with password 'new_password';
will change the password as provided
\q
exit the psql console
change the database.yml as
username: 'postgres
password: 'new_password'
rake db:create
now try to create the database from rails
Should work !

$development_db_name$ does not exist error even after running db:create and db:migrate and getting report that they exist

So I seemingly successfully installed postgres for production for heroku deployment, but locally rails seems to not find/nor create the database.
When I go to localhost:3000 I get the error:
ActiveRecord::NoDatabaseError
FATAL: database "dimension_development" does not exist Run `$ bin/rake db:create db:migrate` to create your database
When I run $bin/rake db:create I get:
~ already exists
Then, run db:migrate and restart the rails server, reload the page, and get same error.
So I tried instead to run $bin/rake db:create:all and got:
~ already exists
dimension_test already exists
dimension_production already exists
Then did db:migrate again but nothing changed.
If they already exist, why isn't rails finding them? I notice that in the config/db folder there is still the old development.sqlite3 file but no postgres file.
Any idea what could be going on to cause this error?
My database.yml is:
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: dimension_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: dimension_production
pool: 5
timeout: 5000
Thanks! This has got me stumped and I haven't been able to find anything on stackoverflow dealing with this pitfall.
In case of postgresql you will not find any file like development.sqlite3. It's in case of sqlite only.
You did not provided database credential in your database.yml file might causing this error. Try pass username and password as well.
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
username: xxxx
password: xxxx

database.yml file configuration and postgres - rake db:drop db:create db:migrate

I recently switched to postgres for a rails app in development since I deployed on Heroku and want to match production. Postgres is installed and working correctly for my application when I set the database name equal to 'postgres', which is the default name from what I understand.
However, I would like to change the database name for development, test and production. If I simply change the names in database.yml, and try to run a rake task, I get the following error in my terminal:
NOTICE: database "something_development" does not exist, skipping
Couldn't drop something_test : #<PG::Error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?>
rake aborted!
FATAL: database "something_development" does not exist
Here is what my database.yml file currently looks:
development:
adapter: postgresql
host: localhost
database: something_development
username: name
test:
adapter: postgresql
database: something_test
pool: 5
timeout: 5000
production:
adapter: postgresql
host: localhost
username: name
database: something_production
Are there some other steps I am missing? Apologies if I am missing something obvious here! Thanks!
Changing the name in the database.yml file only changes the place that it looks for the database, it does not actually rename the database itself. If you change the specified location, you will need to rename the database to match, using a GUI tool (like navicat or pgadmin) or the command line.
Also, it is probably an obfuscation omission, but your posted output refers to both shredset_development and something_development. If this continues to fail, perhaps verify that all of your names are the same everywhere...

mongoid/mongodb and rake task authorization in production/passenger

When trying to run rake db:seed on my app, I get the error:
Database command 'count' failed: {"assertion"=>"unauthorized db:app_development lock type:-1 client:127.0.0.1", "assertionCode"=>10057, "errmsg"=>"db assertion failure", "ok"=>0.0}
I get the same error with db:drop
Mmy app is connecting to the DB fine, it's just these rake taks are failing, and I'm not sure wh. I dont think seeding should need admin privileges. Maybe it's a passenger issue?
You need to have the username and password set in mongoid.yml for rake tasks to be able to connect to your database.
Example:
production:
host: host-name
port: 27017
username: itsmeyo
password: supasecret
database: project_production
You can also have them set in environment variables, but they need to be set.
password: <%= ENV['MONGOID_PASSWORD'] %>

Resources