PG Error Connection on Mac - ruby-on-rails

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.

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

could not connect to server: Connection refused (0x0000274D/10061)

I'm using rails to develop a website but i get this error when i try to open my localhost
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
How to fix it guys
In Windows, search for "services" and search for postgres in the list. Right click and select "Start".
It looks like your postgreql server is not running.
You can try to launch it with :
On Linux :
sudo service postgresql start
On windows : changing XX by your postgresql version run :
net start postgresql-XX
You can also stop using postgres and specify a sqlite database in your config/database.yml file :
changing this line :
adapter: postgresql
by this line :
adapter: sqlite3
If you are using postgreql this issue is due to not starting a server, so you should start the server, one way to do it is to cd to postgresql bin and start it with pg_ctl, here is an example:
cd "C:\Program Files\PostgreSQL\14\bin"
pg_ctl -D "C:\Program Files\PostgreSQL\14\data" start
If you are running postgres in a docker image, be sure to map the container port to the host. You can do this with docker run -p 5432:5432 <container-name> or by adding the following to your docker-compose.yml file:
ports:
- 5342:5342

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?

Postgres stops listening on IP (Azure) / rails

I have a Postgres 9.3.9 running on Azure. I have a rails webserver connecting to it.
I can connect to it fine from the rails server for a while. I connect like this:
me#server:~$ psql -h db.mydomain.com -U myuser mydb
Then a while later (30 mins, or hours - it's random) I can't connect anymore and I need to restart the server (/etc/init.d/postgresql restart) to be able to connect again.
When it stops responding, I can't telnet to port 5432 - it does not respond.
This is what I get with psql:
me#server:~$ psql -h db.mydomain.com -U myuser mydb
psql: could not connect to server: Connection timed out
Is the server running on host "db.mydomain.com" (x.x.x.x) and accepting
TCP/IP connections on port 5432?
This is what I get with a Capistrano deploy:
initialize': could not connect to server: Connection timed out (PG::ConnectionBad)
** [out :: x.x.x.x] Is the server running on host "db.mydomain.com" (x.x.x.x) and accepting
** [out :: x.x.xx] TCP/IP connections on port 5432?
Other points:
When it stops responding, my rails web app still works OK from a browser
As soon as I restart the postgresql server it accepts the connection
It is intermittent, if it isn't responding and I leave it for a while (10 minutes? hours?) it might work the next time

After OSX 10.8 upgrade postgres can not connect to the server

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.

Resources