Postgres just randomly stopped working (Rails, PGSQL.5432) - ruby-on-rails

I've been using the same Postgres database in this same app for a month with no problems, and I didn't change anything in the database before this error randomly came up today. However, today Postgres randomly started throwing this error when I try to "rails s" (I get the same type of error when running createdb or createuser):
Exiting
/Users/Joe/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize': could not connect to server: No such file or directory (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
What's really weird is that my friend had the exact same errors yesterday (working on the same app), and it was fixed by him running the script from http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/. After running the script, he uninstalled and reinstalled the PG gem to make everything work. However, he is running OS X Lion, and I am running Snow Leopard, so that script wouldn't work for me.
Any ideas of (1) why this would randomly start happening and (2) how to fix it?

I had a similar problem today, although in my case postgres (installed via homebrew on MacOS 10.8) wasn't running but I couldn't start or restart it. It appeared that due to a crash a zombie was blocking the socket, to resolve it i did the following
lsof -i :5432
this showed the PID of the process blocking, I simply killed it with
kill -9 PID
and postgres restarted fine.
HTH

Maybe something deleted /tmp/.s.PGSQL.5432 socket - a /tmp/ cleaning service for example.
Maybe you'll be able to connect using :host => 'localhost' as connection argument for PG::Connection.new() — it will avoid problems with locating proper path for Unix socket or file permissions problems.
If you do not want to use localhost (it probably is a little slower than a socket) then you can find where it is using lsof | grep PGSQL command as operating system administrator — if it is for example /var/run/postgres/.s.PGSQL.5432 — you would use :host => '/var/run/postres/'.

I was getting the same error when starting rails (No such file or directory). Re-installing postgres with the PostgreSQL one-click installer and rebooting resolved the issue.
In my case this happened after installing Mountain Lion, which probably cleaned the tmp directory.

I had a similar error and found this answer helpfull
Repairing Postgresql after upgrading to OSX 10.7 Lion
I resolved by adding
export PATH=/usr/local/bin:$PATH
to my .bash_profile

I faced same issue and when I checked server.log I can see it was not able to find that var/postgres folder and some of the conf files.
I did this, however I lost my data in that case
brew uninstall postgres
brew install postgres
initdb `brew --prefix`/var/postgres/data -E utf8``
That worked well for me and everything back to normal.

Related

Address already in use issue when running rails

Hi all I am new to rails and I am facing issue with running the rails app in WSL. I generated a new rails project and just set it up for deployment using capistrano. The deployment was successful. However, now I cant run rails locally. rails s gives me error.
I am posting the log here
I tried checking the port to see if any process was using port 3000 but it showed nothing. The commands that I tried are
lsof -wni tcp:3000
ps aux | grep puma
but they show no process that I can kill. I dont think this is an issue with WSL because I can run another newly created rails app.
Any help is highly appreciated. Thanks
I used to get this error too. I then realised that after I deleted the server.pid file found in either:
management\tmp\pids or > gateway\tmp\pids
and restarted the service, it ended up working.
I recommend you make a local copy of the file(s) in the pid folder incase you need it, then delete it, restart your service and see what happens.

Getting error - type "json" does not exist - in Postgresql during rake db migrate

I have recently cloned a project to my local Ubuntu box now that I am remote, and upon rake db migrate, I get the following error:
PG::UndefinedObject: ERROR: type "json" does not exist
A couple columns in my tables that are:
add_column :table, :column, :json
This migration works on the Macs at work, but are not working here. I have tried upgrading to PostgreSQL 9.3.4, but the issue still persists. I also tried sudo apt-get upgrade postgresql, and still the problem persists.
Ruby version is 2.1.0
Rails version is 4.0.3
I have tried upgrading to PostgreSQL 9.3.4, but the issue still persists
Most likely you're still connecting to the old version. Try SELECT version().
Since you mention apt-get you're presumably on Debian or Ubuntu. These use pg_wrapper to allow multiple PostgreSQL installs in parallel. Each one gets a different port number. The first install gets the default port 5432. Subsequent installs get higher ports.
You can view the installs with pg_lsclusters. Most likely your 9.3 install is on port 9433, and you need to change your database.yml (since you're using Rails) to connect to that port.
If for any reason you run into this issue, your 9.3 version is not actually running.
I found this link to very helpful:
http://nixmash.com/postgresql/upgrading-postgresql-9-1-to-9-3-in-ubuntu/
I started with the command:
sudo service postgresql stop
and ran all the commands from there. Everything works fine now.

rails server stopped working suddenly could not connect to server [duplicate]

I've been using the same Postgres database in this same app for a month with no problems, and I didn't change anything in the database before this error randomly came up today. However, today Postgres randomly started throwing this error when I try to "rails s" (I get the same type of error when running createdb or createuser):
Exiting
/Users/Joe/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize': could not connect to server: No such file or directory (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
What's really weird is that my friend had the exact same errors yesterday (working on the same app), and it was fixed by him running the script from http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/. After running the script, he uninstalled and reinstalled the PG gem to make everything work. However, he is running OS X Lion, and I am running Snow Leopard, so that script wouldn't work for me.
Any ideas of (1) why this would randomly start happening and (2) how to fix it?
I had a similar problem today, although in my case postgres (installed via homebrew on MacOS 10.8) wasn't running but I couldn't start or restart it. It appeared that due to a crash a zombie was blocking the socket, to resolve it i did the following
lsof -i :5432
this showed the PID of the process blocking, I simply killed it with
kill -9 PID
and postgres restarted fine.
HTH
Maybe something deleted /tmp/.s.PGSQL.5432 socket - a /tmp/ cleaning service for example.
Maybe you'll be able to connect using :host => 'localhost' as connection argument for PG::Connection.new() — it will avoid problems with locating proper path for Unix socket or file permissions problems.
If you do not want to use localhost (it probably is a little slower than a socket) then you can find where it is using lsof | grep PGSQL command as operating system administrator — if it is for example /var/run/postgres/.s.PGSQL.5432 — you would use :host => '/var/run/postres/'.
I was getting the same error when starting rails (No such file or directory). Re-installing postgres with the PostgreSQL one-click installer and rebooting resolved the issue.
In my case this happened after installing Mountain Lion, which probably cleaned the tmp directory.
I had a similar error and found this answer helpfull
Repairing Postgresql after upgrading to OSX 10.7 Lion
I resolved by adding
export PATH=/usr/local/bin:$PATH
to my .bash_profile
I faced same issue and when I checked server.log I can see it was not able to find that var/postgres folder and some of the conf files.
I did this, however I lost my data in that case
brew uninstall postgres
brew install postgres
initdb `brew --prefix`/var/postgres/data -E utf8``
That worked well for me and everything back to normal.

How can i setup the path for heroku postgresql app?

I just installed the heroku PSQL app (v1.0) and i'm having trouble being able to connect my rails apps using the gem pg "0.1.4". I already added the path PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" to my .profile and my .bashrc files, but nothing seems to allow me to run psql simply by calling "psql". I had success using "psql -h localhost". When i go for "psql" i get:
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I'm using mountain lion.
Still pretty sure that both of the existing answers are answering the wrong question. The author mentions right in the title that he is having trouble with PATH, not connecting to his DB or configuring rails. This is the situation I got into, and this is my solution.
After getting postgres.app running and setting PATH in my .bashrc file as directed in the postgress.app documentation - http://postgresapp.com/documentation :
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
The problem was that this path setting was not taking effect after restarting terminal.app - running which psql was returning the copy in "/usr/bin/psql", this is the copy that comes installed with Lion and Mountain Lion, not the new version installed in "/Applications/". It even says in the Postgres.app instructions "run which psql to tell that the correct version is being loaded".
Anyway - the odd thing I found was that after I ran:
source .bashrc
Then the command "which psql" would return the correct version located in /Applications/.
At this point I was stumped and had to get some extra help. The guys I tapped also thought it was quite odd too, however they quickly found out that neither the .bashrc OR the .profile files were being loaded. This is very strange, I have not seen this on any of my other macs running leopard through lion.
Now finally the solution- I am not sure this is proper, but it did permanently fix my problem. We found that their was one profile file being loaded into the terminal - the .bash_login file. In the end the solution was just to use the .bash_login to source the .bashrc file. Here is the edit to .bash_login:
source $HOME/.bashrc
And that did it.
Anyway I can't say that this is exactly the fix that diego needed / was looking for, but it is definitely the problem for me.
You'll need to add host:localhost to any database configuration you're using in your development environment (read development / test/ production / etc):
config/database.yml
development:
adapter: postgresql
encoding: unicode
database: my_awesome_app_development
pool: 5
host: localhost
username: my_awesome_app_development
password:
Edit: also see Repairing Postgresql after upgrading to OSX 10.7 Lion
I know this is an old question but I just had the same problem. The issue is that there is a typo in the documentation. The app is Postgres93.app, not Postgres.app, so the path should have Postgres93.app:
PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"
It's amazing how many posts there are about this and the typo doesn't seem to have been noticed yet. Changing that was all it took to get psql and which psql to work correctly for me.
Your PATH might be wrong. To find out the PATH of your psql script (on mac) open the sql shell script from your finder in Applications/Postgres installation. This will give you a hint as to where it is installed. That opened a window which told me it is located here: /Library/PostgreSQL/8.4/scripts/runpsql.sh
Then, I set the PATH variable from the terminal window by typing:
$ PATH="/Library/PostgreSQL/8.4/bin:$PATH"

Rails + Pow + Snow Leopard Server: I can't get Pow to work

I'm running Snow Leopard Server 10.6.7, and I need to host some Rails apps locally. Pow seems to be a good fit for what I need, but I can't seem to get it to work. At first, when I went to http://myapp.dev, I would get the OS X Server Welcome page. I asked around, and I was told to disable Web Sharing, which I did by turning off Web under Applications > Server > Server Admin. This hasn't helped.
I tried uninstalling and reinstalling Pow with Web disabled, but that didn't help anything, either. I tried restarting the Pow server by running touch /mydir/myapp/tmp/restart.txt, and that's not helped, either.
Have you followed the help carefully to create app? You must do a symlink of your app in ~/.pow
You can also use the gem powify:
Type 'gem install powify' in term
Type 'powify' in console and look at powify's help. Hint: cd in your app dir the type "powify create myapp" and then go to http://myapp.dev
Good luck!

Resources