rails 5 app generated with postgresql - what's my password? - ruby-on-rails

I have created a Rails 5.0.2 app with postgres as the database, it all works fine in the development environment.
But when I try to test the app in the production environment (Still on my local machine) I just can't figure out what the password for the database is.
I see this error in the log:
PG::ConnectionBad (FATAL: Peer authentication failed for user "myapp"
My database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_development
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
Can I access the ENV['MYAPP_DATABASE_PASSWORD'] somehow? Was I supposed to set it up when I created the app?
I realize this may be very trivial. Thanks.

Related

receiving "PG::ConnectionBad fe_sendauth: no password supplied" error when storing passwords in ENV variables in rails

I recently switched db's from sqlite3 to PG. My username and password for pg were hard-coded, and although it was working, this was not safe practice. SO I stored my password in an ENV variable in a .yml file, and I reference that variable in my database.yml file, but when I run the server, it gives me the error "PG::ConnectionBad
fe_sendauth: no password supplied"
the following is my pg_keys.yml file
PG_PASSWORD: "***********"
And the following is my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: stockapp_development
username: postgres
password: <%= ENV['PG_PASSWORD'] %>
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: stockapp_test
host: localhost
username: postgres
password: <%= ENV['PG_PASSWORD'] %>
production:
<<: *default
database: stockapp_production
username: stockapp
password: <%= ENV['STOCKAPP_DATABASE_PASSWORD'] %>
Why is it saying that no password is supplied? Does my database.yml not see the password in the other file? Do I need to export the password?
It is because ENV variables come from https://github.com/bkeepers/dotenv.
Install this gem by adding it to your Gemfile, then run bundle and set the variable PG_PASSWORD=*********** in .env in your root. Then it should work fine.

POSTGRES Problems : fe_sendauth: no password supplied

I have seen many answers on here to "solve" this similar issue,However my database.yml in my app is not formatted the same.
Rails S: Works
Rails C: Works
Rails db:create -> Error: fe_sendauth:
adapter: postgresql
encoding: unicode
host: ''
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: chic_development
host: localhost
test:
<<: *default
database: chic_test
production:
<<: *default
database: chic_production
username: chic
password: <%= ENV['CHIC_DATABASE_PASSWORD'] %> ```
My Postgres App is on port 5433, not 5432. I am unsure if this is relevant. But in General I am constantly having issues with my PG being flighty.
Please Help.
I looked up my postgres.app and looked to see the server name and used that as username..got my password and put them in my database.yml file like this...
username: xxxxxx
password: xxxxxxxxxxx
...under the "default" block of code then bundled everything and it worked. Thanks

Staring Rails App With Postgresql - PG::ConnectionBad

I Cannot get the welcome screen not matter what I do, all I get is the connection issue with the postgres db error.
I ran this command to start the app.
rails new -T appName --database=postgresql
Here is my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
adapter: postgresql
encoding: unicode
database: dbname
pool: 5
username: toolshiring
password: toolshiring
host: localhost
port: 5432
production:
<<: *default
database: toolshiring
username: toolshiring
password: <%= ENV['toolshiring'] %>
I used pgAdmin to add a user with full permissions named toolshiring and has the same password. Then created the database with owner toolshiring.
I decided to try something and it seems to have worked for the time being.
I decided to reset the password for the default db 'postgres' to the password 'postgres' as well, and delete the new db that I created....because the wasn't working for some reason.
in my database.yml file i commented everything but this
development:
adapter: postgresql
encoding: unicode
database: postgres
pool: 5
username: postgres
password: postgres
host: localhost

Rake db:create fails to connect to server: No such file or directory

I'm trying to upload a rails app to heroku and I'm running into problems to change my app from sqlite3 to postgres, mainly when I run rake db:create I get:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
This is what my database.yml looks like:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: anagram_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: anagram_test
production:
<<: *default
database: anagram_production
Do you have postgresql installed locally? If so, double check that it's running. Your database.yml file is also missing some required information to connect to a postgres database. You need to provide username, password and hostname.
Here's an example of mine which connects to a local postgres db:
development:
adapter: postgresql
encoding: unicode
database: app_development
pool: 10
username: <%= %x(whoami) %>
password:
For heroku/production, you can use the following:
production:
url: <%= ENV['DATABASE_URL'] %>
pool: <%= ENV['DB_POOL'] || 10 %>

rails SQlite 3: Cant open the connection

I have existing rails project with PostgreSQL DB. When I am running the same in my local machine I am receiving SQLite exception.
But my database.yml configured with postgres adapter only.
Here is the exception:
SQLite3::CantOpenException: unable to open database file
database.yml
postgres: &postgres
adapter: postgresql
encoding: unicode
host: localhost
pool: 5
username: postgres
password: postgres
min_messages: warning
development:
<<: *postgres
database: dev_development
username: <%= ENV['PG_USER'] || 'postgres' %>
password: <%= ENV['PG_PASSWORD'] || 'postgres' %>
test:
<<: *postgres
database: dev_test
username: <%= ENV['PG_USER'] || 'postgres' %>
password: <%= ENV['PG_PASSWORD'] %>
Perhaps you have an environment variable set (DATABASE_URL) that is overriding your database.yml file? Look at this for more info: http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database
If that's not it, is it possible you recently changed your database.yml file and haven't restarted the server?

Resources