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?
Related
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.
I'm trying to push my Rails app to Heroku and running into difficulty.
In the config/database.yml file I've seen examples like this, where the database name is prefixed with 'db/':
production:
<<: *default
database: db/the_business_casual_pro
As well as examples like this, without the prefix:
development:
<<: *default
database: FullstackProject_development
Is one way preferred over the other, or is one an older way of doing it?
Right now my database.yml file is just this:
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/the_business_casual_dev
test:
<<: *default
database: db/the_business_casual_test
production:
<<: *default
database: db/the_business_casual_pro
I've seen the code below in a previous project but am unsure what I'd need to do first to add these lines.
production:
<<: *default
database: FullstackProject_production
username: FullstackProject
password: <%= ENV['FULLSTACKPROJECT_DATABASE_PASSWORD'] %>
Any insights very much appreciated!
Usually when you locally develop a Rails application you're not using a Postgres instance for development, but a SQLite database. Rails stores these databases in a folder called db. You can actually check the db for your project if there are any files in it.
With Heroku, you're using a Postgres instance and you're defining the database in another way.
So I would keep the db/ for development (including the SQLite adapter) and for production you probably want to use ENV["DATABASE_URL"] as Heroku suggests it.
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'm new to ruby on rails, i'm trying to run an app with postgres database, but it didn't work, i have tried to search lots of information, but i wasn't useful, Someone posted the exactly same question here Problems with rails server , I tried to use command rails new blog it created an app with sqlite3 database, it works fine, but i created app with command rails new myapp --database=postgresql after that i visit localhost page, it ocurred the exactly same error
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Can anyone help? it would be very much appreciated.
database.yml file information:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
Delete this file:
/usr/local/var/postgres/postmaster.pid
Original Answer: psql: could not connect to server: No such file or directory (Mac OS X)
I'm learning ruby. I've created some application and played with it.
i wanted to change the database to postgres. I modified gemfile with
gem 'pg'
[pg already installed in usr/bin/pg]
then update database.yml with
postgresql where sqllite is used.
pg connection bad:
FATAL: role "user" does not exist
i've created some postgres user already. what should i have to change to work with postgres?
development:
adapter: postgresql
database: db/development.postgresql
pool: 5
timeout: 5000
user:
adapter: postgresql
database: db/test.postgresql
pool: 5
timeout: 5000
production:
adapter: postgresql
database: db/production.postgresql
pool: 5
timeout: 5000
If you don't specify a username to connect to PostgreSQL as, libpq will connect using the login username of the current running user.
libpq is what the Pg gem used by Rails uses to connect to PostgreSQL.
So, in your database.yml, specify the PostgreSQL user to connect to the database as with a user: entry. Make sure this corresponds to a user that exists in PostgreSQL, and that pg_hba.conf permits this user to connect.
To learn more, see the client authentication chapter of the PostgreSQL docs.
I know its a two year old question, but I just ran into the same problem, and i fixed it by changing the syntax of config.yml, then I rake db:migrate
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: yourappnamehere_development
test:
<<: *default
database: yourappnamehere_testdevelopment:
production:
<<: *default
database: YOURAPPNAME_production
username: YOURUSERNAME
password: <%= ENV['YOURAPPNAME_DATABASE_PASSWORD'] %>