stop postgres processes from restarting - mac - ruby-on-rails

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

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

PG::ConnectionBad (rails, solidus, ubuntu 15)

I have a strange issue with my psql, which was working just fine in my last session. Suddenly when I try to access my localhost server I get this issue
PG::ConnectionBad
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?
Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision*
I'm using Postgres 9.5 and Ubuntu 14.
When I type "psql" in terminal I get the message :
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?"
You seem to be trying to open a client / console connection to postgres before you've started the server. Here's information on starting the server:
http://www.postgresql.org/docs/9.1/static/server-start.html
edit
As you're on Ubuntu try:
sudo /etc/init.d/postgresql restart
Have you already logged in to postgres? (sudo -i -u user) user being the name of your postgres account.
PostgreSQL server should be running all the time.
Since I've used Brew to install PG, the fix that worked for me is in the steps below:
$ brew uninstall postgresql
$ exec $SHELL
$ brew postgresql-upgrade-database
$ brew services start postgresql

host can not recognized in postgres

We have seen a issue in log
FATAL: lock file "/tmp/.s.PGSQL.5432.lock" already exists
HINT: Is another postmaster (PID 4696) using socket file "/tmp/.s.PGSQL.5432"?
LOG: could not bind IPv4 socket: Address already in use
We have deleted /tmp/.s.PGSQL.5432.lock
We restarted the postgres service the service restarted
But the psql -h localhost -d database -U newuser
shows error role 'newuser' does not exists
but if we connect without host
psql -d database -U newuser
It worked, How can We work with host options ?
Is there we ,missing somthing after deleting tmp file?
Same as the last one, you have two instances of PostgreSQL running on the machine.
You delete the socket file rather than shutting down the instance. This allows your second instance to start, but it's only listening on the unix socket. Presumably listen_addresses is unset/empty so it doesn't attempt to bind to a TCP/IP socket, since it'd fail if it tried and port 5432 was already in use.
The other instance is still running and still listening on port 5432 for TCP/IP connections. When you specify -h localhost you get a TCP/IP connection instead of the default unix socket connection, so you are connecting to the other instance of PostgreSQL on your system.
All your problems are caused by going around deleting and killing things rather than identifying the underlying problem - the second PostgreSQL instance - and addressing that.

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!

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