POSTGRES Problems : fe_sendauth: no password supplied - ruby-on-rails

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

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.

Rails 6 on Heroku: ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter

Our Rails app has just been upgraded to Rails 6.0 but the deployment to Heroku fails with:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
DEPRECATION WARNING: Including LoggerSilence is deprecated and will be removed in Rails 6.1. Please use `ActiveSupport::LoggerSilence` instead (called from <top (required)> at /tmp/build_b9759d496c72c1085bb8441e3c2159fb/config/application.rb:7)
rake aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
/tmp/build_b9759d496c72c1085bb8441e3c2159fb/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0/lib/active_record/connection_adapters/connection_specification.rb:163:in `spec'
config/database.yml:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
username: <%= ENV['POSTGRESQL_USER'] %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
url: <%= ENV['DATABASE_URL'] %>
Using version:
rails (6.0.0)
Ruby (2.6.5)
Does anybody have an idea how to solve this issue?
The problem has been solved by adding the 'adapter' to 'production' in the database.yml. This wasn't necessary when our project was on Rails 4 and 5.
production:
adapter: postgresql
A better solution altogether would just be to use ENV["DATABASE_URL"] to specify the connection details and keep your defaults segment to the actual minimal defaults:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
development:
<<: *default
database: OurApplication_development
test:
<<: *default
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default
This avoids potential developer wars. You can use DotEnv to load different ENV vars for each environment. Alternatively you can add another hash to to your database.yml and merge it:
default: &default
adapter: postgresql
encoding: utf8
pool: 5
local_settings: &local_settings
# will raise an exception on nil instead of failing silently
username: <%= ENV.fetch('POSTGRESQL_USER') %>
password:
socket: /tmp/mysql.sock
development:
<<: *default
<<: *local_settings
database: OurApplication_development
test:
<<: *default
<<: *local_settings
database: OurApplication_test
production:
# doing url: is just stupid as thats what rails does anyways
<<: *default

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

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.

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

Rails Console, Password needed to create new record

I am currently trying to complete a tutorial on ruby on rails and have had this error within IRB when I enter "subject = Subject.new"
Mysql2::Error: Access denied for user 'simple_cms'#'localhost' (using password: YES)
is there a way to supply this to irb when i run
rails console
What is the best way to resolve this?
database.yml is below:
default: &default
adapter: mysql2
encoding: utf8
reconnect: false
host: localhost
pool: 5
username: simple_cms
password: mypasshere
socket: /tmp/mysql.sock
development:
<<: *default
database: simple_cms_development
<<: *default
database: simple_cms_test
production:
<<: *default
database: simple_cms_production
username: simple_cms
password: <%= ENV['SIMPLE_CMS_DATABASE_PASSWORD'] %>
Much appreciated for any help!

Resources