rails SQlite 3: Cant open the connection - ruby-on-rails

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?

Related

Can't run rails db:create for postgres RDS on AWS

I created an postgres RDS instance,** which I can connect to from my EC2 instance and my local shell**.
But for some reason when I run rails db:create I get the following error:
FATAL: password authentication failed for user "my_user"
Any pointers?
I can connect to the RDS instance from EC2 instance and local machine.
I expect rails to be able to run migrations as well, but it throws an error.
db.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: use
password: gresgres
development:
<<: *default
database: myapp_dev
test:
<<: *default
database: myapp_test
production:
<<: *default
database: <%= ENV['PG_RDS_DBNAME'] %>
username: <%= ENV['PG_RDS_USERNAME'] %>
password: <%= ENV['PG_RDS_PASSWORD'] %>
host: <%= ENV['PG_RDS_ENDPOINT'] %>
port: <%= ENV['PG_RDS_PORT'] %>

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

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

Resources