rake db:migrate RAILS_ENV=production gives error - ruby-on-rails

When I run the command: rake db:migrate RAILS_ENV=production I get the following error:
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "93.188.167.2" and accepting
TCP/IP connections on port 5432?
So I guess my server is not listening on port 5432. So how do I solve this?
I know I have to edit some file so in addition to the instructions on how to actually edit the file (I guess it is the file named postgresql.conf?) please also tell me where I should find it.
My web application is on this directory at the server: /home/admin/www/webstudio
EDIT: I have already tried my best to follow the instructions given here: http://alexbachuk.com/launch-rails-4-application-with-passenger-and-nginx/

Related

How to enable PostgreSQL in a rails app with termux

I'm trying create a app with ruby on rails in termux, I already installed the necessary gems and packages for the setup, but when doing rails db:create. I get this error
rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/data/data/com.termux/files/usr/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Caused by:
PG::ConnectionBad: connection to server on socket "/data/data/com.termux/files/usr/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
You need to start a PostgreSQL server manually for your app to be able to connect to.
Install postgresql via pkg install postgresql
See the wiki for sample setup instructions https://wiki.termux.com/wiki/Postgresql

Rake Migrate Not Working

I am in no way a code developer. Our code developer quit, and I was just given the project. So I am trying to learn code while fixing what ever issues happen. This is the issue that I am currently facing. I need to add new columns into two different tables, I did three separate Active Record Migrations, following the direction. When I tried to update the schema.rb with
$ rake db:migrate
I got the following.
[pcms -update to 4.4 (master)]$ rake db:migrate
WARNING: Nokogiri was built against LibXML version 2.9.2, but has
dynamically loaded 2.8.0
I, [2017-07-20T08:57:20.436515 #64621] INFO -- : ** [Raven] Raven 0.13.0
configured not to send errors.
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
database.yml
development:
adapter: postgresql
database: pcms_development
host: localhost
test:
adapter: postgresql
database: pcms_test
host: localhost

Does rails server have to be running for you to run rake db: actions?

I've always been confused on how you can executive rake db actions from the terminal. Does it go through rails and then change the db? Or does it go through some environment variable you have on your computer to find the db and then changes it?
I'm asking this because I want to run bundle exec rake db:drop but I keep getting
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
even though my bundle exec rails s connects me to a server correctly.
You can run the rake db commands with the rails server running
The error says there is no connection happening with the database and solution for this is either restart the db server
(if its postgres)
sudo service postgres restart
or may be you are providing wrong user name and password in database.yml file(this should match with the db user name and password)

Unable to connect postgres server

When I try to connect server to create database. I am getting this error.
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "socket"=>"/var/run/postgresql/.s.PGSQL.5432", "pool"=>5, "min_messages"=>"error", "database"=>"rails_contributors_test"}
-- enable_extension("plpgsql")
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I tried a lot but didn't get success. Looking for help.
Postgres version I have as
which postgres
=> /usr/local/bin/postgres
postgres --version
=> postgres (PostgreSQL) 9.4.4
Try installing Postgres.app on your Mac OSX.
and start the postgres i.e. click on Open psql.
Then, restart the rails server.
After this, it should fix your issue.
Update (If the above does not work)
To fix the issue, remove the PID file. Find the postgres data directory. On Mac OSX using homebrew it is /usr/local/var/postgres/.
To make sure this is the problem, look at the log file (server.log). On the last lines you will see: FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?
If so, rm postmaster.pid
Restart your server. On Mac OSX, do:
launchctl unload homebrew.mxcl.postgresql.plist
launchctl load -w homebrew.mxcl.postgresql.plist

How do I setup ElasticSearch and Searchkick on my Nitrous.io box?

I've added the searchkick gem to my GEMFILE and I also installed ElasticSearch 1.0 with Autoparts. I'm still getting a connection refused message though when I attempt to reindex one of my models. I'm thinking it is possibly because my elasticsearch server hasn't been started. I'm unsure how to start it though on Nitrous.io. Below is the command I'm attempting to run and the error message I'm receiving...
Command
rake searchkick:reindex CLASS=Player
Result
rake aborted!
Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9200
...
So as silly as this is... I just thought to try and type elasticsearch in my Console of Nitrous.io and that command started my elasticsearch server and then I was able to proceed. Thanks to anyone that had looked into the issue with me!

Resources