After OSX 10.8 upgrade postgres can not connect to the server - ruby-on-rails

After a recent upgrade to Mountain Lion, I've run into problems with my brewed postgres install.
$ rake db:create
>rake db:migratecould 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" (fe80::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?
After searching around the interwebs, I haven't yet found a solution to this issue.
I have found a suggested steps to help identify the problem but after following these, I'm not sure how to understand the results or what to do next. Can anyone help?
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
>pg_ctl: another server might be running; trying to start server anyway
>server starting
$ pg_ctl -D /usr/local/var/postgres stop -s -m fast
>pg_ctl: could not send stop signal (PID: 865): No such process
$ pg_ctl status
>pg_ctl: no server running
$ ps auxw | grep post
>myuser 19037 2.6 7.7 4388248 324520 ?? S 7:30AM 19:06.02 /Applications/Postbox.app/Contents/MacOS/postbox-bin -psn_0_917728
>myuser 54897 0.1 0.0 2432768 464 s000 R+ 1:47PM 0:00.01 grep post
$ cat /usr/local/var/postgres/server.log
>FATAL: lock file "postmaster.pid" already exists
>HINT: Is another postmaster (PID 821) running in data directory "/usr/local/var/postgres"?
Happy to provide any additional info that may be useful.

try removing:
/usr/local/var/postgres/postmaster.pid
This once worked for me.

Related

Postgresql version 13 psql: error: could not connect to server: could not connect to server: No such file or directory

I'm currently working with a Rails 6 application and Postgresql. I been having issues when I run rails db:create. This error seem to happen after I updated brew upgrade I get the following error:
rails 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'm running Mac OS Mojave and I updated postgresq to version 13.
$ postgres --version
postgres (PostgreSQL) 13.0
I'm guessing this is why I have issues, I noticed in some of the other posts that running brew postgresql-upgrade-database might be a FIX to this problem, however when I run the command I get:
$ brew postgresql-upgrade-database
Error: No such file or directory # rb_sysopen - /usr/local/var/postgres/PG_VERSION
But I can see the .old file when I navigate to postgres as shown in the image below:
Also, if I tried connecting to psql I get an error
$ psql
psql: error: could not connect to server: 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"?
I also see that the service is running:
$ ps -ef | grep postgres
501 48733 5971 0 1:23PM ttys011 0:00.31 /usr/local/Cellar/macvim/8.2-166_1/MacVim.app/Contents/MacOS/Vim /usr/local/var/postgres/
501 52975 5971 0 1:54PM ttys011 0:00.01 grep postgres
What can the issue be?
this fixed it for me
initdb `brew --prefix`/var/postgres/data -E utf8
and then running
pg_ctl -D /usr/local/var/postgres/data -l logfile start
Follow PostgreSQL with Homebrew on Mac for more detail

stop postgres processes from restarting - mac

I'm trying to run my rails projects but it keeps falling because it depends on postgres to be running. When I try to start postgres it keep saying its already running (or the port is taken). I checked activity monitor and there are ~6 postgres processes running, when I try to terminate/force-quit the processes, they just appear again...
not sure how to get around this issue.
actual error when running postgres -D /usr/local/var/postgres:
LOG: could not bind IPv6 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Address already in use
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
and when I try to stop postgres with pg_ctl -D /usr/local/var/postgres stop -s -m fast, I get this error:
pg_ctl: PID file "/usr/local/var/postgres/postmaster.pid" does not exist
Is server running?
I ended up starting from scratch:
uninstall postgres through homebrew (brew uninstall postgresql)
uninstall postgres though uninstaller (/Library/Postgresql/version/uninstall)
delete postgres through file system (delete the folder: /Library/Postgresql/)
then just do a homebrew installation:
brew install postgresql
and start postgres manually.
1:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
2:
brew services stop postgresql

Unable to restart Postgres Server

For my rails application, every time I try to do rails console, I get this error:
server: Connection refused (PG::ConnectionBad)
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 suspected that this was because my postgres server was down.. So I used the lunchy gem to stop and start my server. However, I still keep getting the same error.
lunchy stop postgres
lunchy start postgres
I also tried this:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
and got server starting
but when I do this: pg_ctl -D /usr/local/var/postgres status, it does not work because I get a pg_ctl: no server running
Why is this the case?

PG Error Connection on Mac

I am using PG for my Rails application, but suddenly today I can't access my application with this error :
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? could not connect to server: Connection refused Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432?
I already tried some ways to fix it, but it doesn't work.
I tried to check with
Irwans-MacBook-Pro:starterpad2 blackaholic$ ps auxwww | grep postgres
postgres 13342 0.0 0.0 2471272 1072 ?? S Fri04PM 0:04.50 /usr/sbin/cfprefsd agent
postgres 68867 0.0 0.0 2619716 2640 ?? Ss 17May15 0:00.10 postgres: postgres starterpad ::1(60748) idle
postgres 937 0.0 0.0 2469216 120 ?? S 8May15 0:08.83 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdflagwriter
postgres 270 0.0 0.0 2474500 140 ?? Ss 8May15 0:00.03 postgres: logger process
blackaholic 53913 0.0 0.0 2451204 684 s003 S+ 10:28AM 0:00.00 grep postgres
And when I check if the server run or not :
> pg_ctl -D /usr/local/var/postgres status
pg_ctl: no server running
Anyone know why this is happen? I already tried to restart my PG server, but it's keep saying that no server running.
Did you install it using homebrew? If not, you will probably have better luck doing so.
> brew install postgres
Once it finishes installing you will see instructions on how to start/stop it. Don't forget to run
> createdb
to install your user specific database. Once that's done you should be good to go.

Error : Starting POSTGRESQL server

i am very new to ruby and postgresql.
When i try to run
ruby scrpit/server, rake db:migrate, rake db:seed
i get this.
Rails 2.3.11 application starting on http:/0.0.0.0:3000
warning: already initialized constant SESSION_SECRET
Faraday: you may want to install system_timer for reliable timeouts
/home/user/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:941:in `initialize': could not connect to server: Connection refused (PGError)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I am on ubuntu 12.04, ruby 1.8.7, rails-2.3, gem 1.5.3
This is what you should do:
verify that postgres server is actually running
$ netstat -a | grep postgre
if its running, try connecting to it from terminal using psql command. incase its, not running. try starting it manually
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
If it still doesn't start,
Are there any error messages in the server.log? If yes do post them here.
Good luck!

Resources