I'm having trouble changing an existing app with SQLite3 to postgreSQL. I'm following this tutorial to convert SQLite3 to postgreSQL and deploy it to heroku: https://devcenter.heroku.com/articles/sqlite3#running-rails-on-postgres.
I removed gem 'sqlite3' and replaced with gem 'pg'.
After modifying config/database.yml, I ran migration.
$rake db:create and $rake db:migrate resulted this error:
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"?
Gemfile used in production:
gem 'rails_12factor'
gem 'thin'
gem 'pg'
Following is the errors I get when I run with the local server:
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `initialize': could not connect to server: No such file or directory (PG::ConnectionBad)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
It looks like you have not added a Heroku Postgres database to your Heroku account. When a database is configured, your application will connect to it. Without a database configured, it's falling back to looking for one locally.
If you do have a database configured, something is wrong with your Heroku environment preventing your database connection settings from being found.
Related
I need to create a new test database (postgres) and am having trouble. It seems that when I try to run any tests it is attempting to connect to the production database which is worrisome for many reasons. Here is my database.yml currently.
test:
adapter: postgresql
encoding: unicode
database: xxxxxx-test
pool: 5
username: xxx
host: localhost
But when I run a test I see:
An error occurred while loading ./spec/models/recipe_spec.rb.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
PG::ConnectionBad:
FATAL: no pg_hba.conf entry for host "IP_ADDRESS", user "PRODUCTION_USER", database "PRODUCTION_DATABASE", SSL off
I'm not sure why this is happening or how I am supposed to set this up.
Here's my gemfile for test:
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
gem 'rspec-rails', '~> 3.5'
gem 'database_cleaner'
gem 'factory_bot_rails'
end
It's worth noting that I do not have database_cleaner doing anything at the moment.
The database configuration from database.yml is merged with ENV["DATABASE_URL"]. But ENV["DATABASE_URL"] ALWAYS takes precedence over the YML configuration. See the Rails guides on configuration.
The bad news is that you have set ENV["DATABASE_URL"] to point to your production database which could have been catastrophic.
The good news is that you seem to have a IP whitelist on the production DB that denied your local IP. Otherwise you would be clobbering your production DB!
To fix this you need to determine where ENV["DATABASE_URL"] is being set and get rid of it. Depending on your setup this can be anywhere from your ~/.profile to the docker container configuration. Then confirm that you have the correct config:
$ rails runner -e test "puts ActiveRecord::Base.connection_config"
This should print something like:
{"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"xxxxxx-test"}
At this point its safe to create the databases for dev/test with:
$ rails db:create
$ rails db:schema:load
You can use ENV["DATABASE_URL"] to let developers use their own local configuration, but you should NEVER let it point to the production DB on anything except the actual production server!
I just launched my Rails app that I am building in Cloud9 to Heroku (woohoo!). My default database was sqlite3, so in the deployment process I added PostgreSQL in my gem as such:
# Use postgresql as the database in production
group :production do
gem 'pg'
end
# Use sqlite3 as the database in development
group :development do
gem 'sqlite3'
end
I want to keep my sqlite3 database in development and use PostgreSQL for production. My question is how do I monitor or run queries for the PostgreSQL data in my production Heroku site.
I'm used to running "rails c" then "User.all" in my terminal to see my users. Now if I run that it doesn't show any data from production. How do I see that data? I did some searching and i think I should be using "psql" command. But if I run "psql -l" for example I get:
psql: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
If you just want to run some PostgreSQL queries on Heroku production then type following command in your terminal:
heroku pg:psql (or heroku pg:psql -a your-heroku-app-name)
Here you will be able to run such queries like select * from users. To exit the terminal type \q.
You can also invoke Heroku production console with
heroku run console (or heroku run console -a your-heroku-app-name)
to run such queries like User.all.
I have adapter set to "mysql2" in my database.yml, yet when I try to deploy to Heroku, I get an error telling me, that I don't have Postgres installed... What the heck?
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded.
Heroku works ONLY WITH POSTGRESQL
you should add postgresql to envirement what you use on Heroku
UPDATED
but Heroku has huck for MySQL:
TAKE A LOOK
I'm using nitrous on a PC (Windows 7), and having trouble connecting to the server (using ruby on rails). It worked perfectly yesterday (same project, same computer).
The error I'm getting:
psql: 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"?
My database.yml file:
development:
adapter: postgresql
database: mvp_development
test:
adapter: postgresql
database: mvp_test
I've confirmed that my Gemfile does contain 'pg', tried running bundle update and bundle install, uninstalling pg and running bundle install, and running gem pristine pg.
Make sure you're starting the postgresql server. If your box has been shutdown then the process will get killed so you need to restart.
You can do this using the parts start postgresql command in the console.
There will be paid plans in the near future that allow you to keep your box alive indefinitely so you won't need to restart postgresql and other services everytime you sign in.
I wanted to deploy my local Rails app (that works perfectly) to Heroku, but get the following error message:
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
/tmp/build_21pkcz898c28o/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize'
Followed by many lines about postgres_adapter.
I'm a bit disappointed because I red that Heroku overwrite config/database.yml so why does it talk about running the server on 127.0.0.1 (I'm not looking for remote db)?
Thanks,
Update
If this can help, running heroku config gives the following:
DATABASE_URL: xxx
HEROKU_POSTGRESQL_GRAY_URL: xxx (the same xxx as above)
Include the following in your application.rb, above the Module Appname
config.assets.initialize_on_precompile = false
And read the Heroku Labs: user-env-compile Article
I am using Rails 4.0.4 and none of the above worked for me.
Following the heroku documentation
RAILS_ENV=production bundle exec rake assets:precompile
then
git add public/assets
git commit -m "vendor compiled assets"
Resolved it partially for me ... I could 'git push heroku master' but then my Bootstrap styling is not applied.
To resolve this final part, I added the recommended 'rails_12factor' gem in my gemfile.
group :production do
gem 'thin'
gem 'rails_12factor'
end
And all worked fine after that after my git push