I'm trying to run my tests for my app but I keep getting both this errors:
PG::ConnectionBad: fe_sendauth: no password supplied
PG::ConnectionBad: FATAL: sorry, too many clients already
I'be read all previous answers and it seems to be, for everybody else, either a missing password or a misconfiguration of the pg_hba.conf file.
This is how my database.yml looks like:
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
encoding: utf8
reconnect: true
host: localhost
username: postgres
password: <password>
development:
<<: *default
database: <dev-db>
host: <dev-host>
username: <dev-user>
password: <dev-pass>
test:
<<: *default
database: <test-db>
I already checked the pg_hba.conf config file and its configured to md5 for all entries listed.
Any clues to what might be the problem?
I'm running PostgreSQL 10, Rails 5.2.3 on Ruby 2.5.5, on a Macbook with Mojave.
Thanks in advance.
Does your postgres user actually have a password set on it? Typically there is no password for the default postgres user, so this is something you would need to have gone out of your way to do; judging by the error message, it sounds like you are using the default posgres user and have not gone out of your way to set a password in the PostgreSQL CLI.
I suggest stripping it down to a very basic default, functional config like:
postgres: &postgres
adapter: postgresql
encoding: utf8
pool: 5
development:
<<: *postgres
database: project_name_development
test:
<<: *postgres
database: project_name_test
Then incrementally add back additional configuration options one at a time, confirming that each one works before adding the next. Env vars also may not be available to database.yml depending on your project configuration and installed gems.
Related
I am following this guide to set up a rails project with Postgres.
So far I have installed postgress and the Heroku toolbelt and done the following:
Logged in using my heroku credentials
Created a rails project using postgres rails new myapp --database=postgresq
The default database.yml file looks like this:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
created controller for homepage rails g controller welcome
Created index.html.erb and added routing. root 'welcome#index'
Then When I run the server, go to localhost:3000 and get the following error
PG::ConnectionBad (fe_sendauth: no password supplied):
Is the issue with the database.yml file or with the installation and setup of postgres?
In config/database.yml, under default: &default, add:
host: localhost
username: postgres
password: (the password you created during postgresql installation goes here)
port: 5432
Then in your terminator run rake db:create:all(don't worry if you encountered the same problem here) and then run rake db:migrate, restart your rails server and your app should now work.
P.S. I've noticed that this question was asked over a year ago and that you already figured out a solution back then. But I am putting this solution here for anyone who might face the same problem because I encountered this problem two days ago and it took me some time to figure out a solution that worked for me.
figured it out. All I had to to was open pgAdmin and login using the password I created during installation.
Add username and password to default
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: postgres
password: postgres
I have a test database set like this in database.yml:
test:
adapter: postgresql
encoding: unicode
database: database_test
host: localhost
pool: 5
username: <%= ENV['PG_USERNAME']%>
password: <%= ENV['PG_PASSWORD']%>
I use spring gem for running tests (although this is not important as the issue occurs without using it as well)
The issue is that every time I run a bundle exec rspec spec/ I get an error no password supplied (PG::ConnectionBad):
/.bundle/ruby/2.3.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize': fe_sendauth: no password supplied (PG::ConnectionBad)
And I need to change it manually to:
test:
adapter: postgresql
encoding: unicode
database: database_test
host: localhost
pool: 5
username: postgres
password: postgres
In order for it to work.
I have set variables in ~/.bashrc:
export PG_USERNAME="postgres"
export PG_PASSWORD="postgres"
The strange is that in development mode it all working fine when I use the same structure as in test:
development:
adapter: postgresql
encoding: unicode
database: database_dev
host: localhost
pool: 5
username: <%= ENV['PG_USERNAME']%>
password: <%= ENV['PG_PASSWORD']%>
What is the problem with my test environment and how to fix it in order for it to automatically use ENV['PG_USERNAME'] like in development mode?
I proposed a quickfix in the comments, but I'd suggest to use the excellent dotenv gem for configuration loading depending on your configuration. It would incidentally solve your current problem.
I've just opened up a Rails project that I haven't accessed for about six months.
Hitting my .dev domain or running rails c gets me the following error:
/Users/me/.rubies/ruby-2.0.0-p353/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize': fe_sendauth: no password supplied (PG::ConnectionBad)
Looking at my database config, I can see that there is indeed no password supplied, but looking back through my Git history I can see there never has been a password supplied in development.
Testing other rails projects, I get the same error, so I am now unable to run any rails projects locally.
I haven't (deliberately) touched Postgres at all since the last time I successfully ran a project locally.
Here is an example of a rails app that was working 10 days ago and now fails with the above error:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: <%= ENV['APP_NAME'] %>_development
test:
<<: *default
database: <%= ENV['APP_NAME'] %>_test
production:
<<: *default
database: <%= ENV['APP_NAME'] %>_production
staging:
<<: *default
database: <%= ENV['APP_NAME'] %>_staging
[Update] This effects sites that never had an explicit user or password defined in their database.yml in the first place.
What might have changed in my setup?
There have been a few post on this issue, unfortunately none of the solutions have worked for me.
My suspicion is that my postgresql is either not running or not configured correctly.
Here is where I am at, I have a development project I have joined, they are using postgresql. Here are the step I have take to get here:
Cloned Repo
Changed name of config/ database.yml.sample -> database.yml
Changed name of config/ s3.yml.sample -> s3.yml
Ran bundle install
Ran Rake db:migrate
resulting in this error:
rake aborted!
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"?
Here is what my files currently look like:
Database.yml
development:
adapter: postgresql
encoding: unicode
database: rentsnapper_development
pool: 5
username: user
password:
test: &test
adapter: postgresql
encoding: unicode
database: rentsnapper_test
pool: 5
username: user
password:
cucumber:
<<: *test
And My s3.yml
defaults: &defaults
access_key_id:
secret_access_key:
development:
<<: *defaults
photos_bucket: rentsnapper-photos-development
Solutions Tried:
https://stackoverflow.com/a/14887090/2066855
No File listed
https://stackoverflow.com/a/14225289/2066855
No Change, when I run rake db:migrate I get the same error
https://stackoverflow.com/a/15788389/2066855
Nothing happened
Also as a side question that may or may not be relevant linux is telling me that "ruby-1.9.3-p385 is not installed", I'm running ruby-1.9.3-p362, I suspect this is unrelated. Is this something I need to update or can I get by with my current version.
Thank you in advanced...
SOLVED: I had to fix my database.yml file. Added "host: localhost" took out user & password lines.
development:
adapter: postgresql
encoding: unicode
database: rentsnapper_development
pool: 5
host: localhost
test: &test
adapter: postgresql
encoding: unicode
database: rentsnapper_test
pool: 5
host: localhost
cucumber:
<<: *test
Good afternoon,
I browsed the other questions on this topic, and it appears nobody has asked about this issue. I was expecting otherwise!
In any case - I have a PostgreSQL database server running on my local machine with a MYAPP_DEVELOPMENT database. I've tried to do a
heroku db:push
But keep getting the following error:
Failed to connect to database:
Sequel::DatabaseConnectionError -> PGError: FATAL: role "brandon" does not exist
This obviously has something to do with the permissions & users on the local/heroku shared database, but I'm honestly not that good with this kind of stuff. Any help would be appreciated. I'm currently including the "database.yml" file in my slug to Heroku, which has all of the login/password info for my local database... hence why I was not expecting this kind of error.
Thanks!
** EDIT **
Here is the contents of my database.yml file (edited for clarity):
common: &common
adapter: postgresql
encoding: unicode
username: user
password: secret
test:
<<: *common
database: myapp_test
development:
<<: *common
database: myapp_development
production:
<<: *common
database: myapp_production
I figure it must be something on the Heroku setup side. Note that nowhere in my database.yaml file does "brandon" show up. I'm not quite sure where it is pulling that from. My database user name is not that (although that is my name haha)
This error generally means a username has not been specified under the appropriate environment in your database.yml file.
Your database.yml file should resemble the following (I use MySQL locally, hence the adapter and socket parameters):
common: &common
adapter: mysql2
encoding: utf8
reconnect: false
pool: 5
username: <your_username>
password: <your_password>
socket: /tmp/mysql.sock
development:
<<: *common
database: appname_dev
test:
...
staging:
...
production:
<<: *common
database: appname_prod
If that doesn't solve your problem, check to ensure Heroku is running in the correct environment:
heroku config --app <appname>
Ensure RACK_ENV is set to production
If not: heroku config:add RACK_ENV=production --app <appname>
(It would have been helpful if you pasted the contents of your database.yml file.)
You will have to use the Heroku specific ENV var to use the DB which is usually ENV['DATABASE_URL']
Edit: If you have a db mapper like datamapper you'd write it like this:
DataMapper.setup(:default, ENV['DATABASE_URL'] || LOCAL_DB_URL)
which then either uses the Heroku DB if it exists or defaults to your local DB which is stored in the LOCAL_DB_URL var.
Thanks for everyone's input to this one. I ended up fixing my issue by explicitly providing my login details to Heroku during the db:push... e.g.:
heroku db:push postgres://postgres:PASSWORD#127.0.0.1:5432/DATABASE
Not sure why it isn't using the (same) information in my database.yml file, but oh well.