Postgres.app port in use - postgresql

I am trying to start the server and getting an error
Port 5432 is already in use
I have brew uninstall postgress
which postgres
gives me nothing.
Activity monitor has 14 postgres processes which I cannot kill.
Force quit kill the process and restarts it with another pid.
The same with
sudo kill -9 PID
it kills the process and restarts it with another PID.

If you are running into this problem on OSX, do the following:
Find out what is running on that port:
$ lsof -n -i4TCP:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python2.7 28687 afdasdfasd 3u IPv4 0x2f18e1284963d3e3 0t0 TCP 127.0.0.1:54970->127.0.0.1:postgresql (CLOSE_WAIT)
Kill it
$ kill -9 28687
Restart postgresapp

Have you checked for a launch daemon? It controls the Postgres process when Postgres is installed with Homebrew, and it automatically restarts Postgres after it is killed. Try
sudo launchctl list
or
sudo launchctl list | fgrep postg
to find the name of the daemon. You can stop the daemon with sudo launchctl stop <name> where name depends on the result of the first command.

Askubuntu provided an answer that worked for me:
sudo pkill -u postgres
Source: Nicely stop all postgres processes

$ brew services stop postgresql
This will kill all processes and let you start the server.

You can get the list of ports using:
sudo launchctl list
Then enter the application name, and using this command to get the port nunber:
sudo launchctl list | fgrep postg
In my case, the port is 83. Now use:
kill 83
then
sudo kill 5432

Run those commands
To check what is running on port 5432 - $ sudo lsof -i :5432
To kill Postgres - $ sudo pkill -u postgres

Use this:
brew services stop postgresql
Good luck!

Related

Psql can not connect to server, password authentication failed for user postgres

I know this has been asked a lot before but none of the other answers have helped. I have tried changing the pg_hba.conf. I have tried altering the password for postgres with sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';". But to do that I need password for user postgres. I have tried changing password for postgres with sudo passwd postgres. It still fails authenticating. I have tried using my own password when asked for it but authentication fails.
I'm using PostgreSQL 12.2
pg_hba.conf
sudo -u postgres psql
I fixed this error by looking for live processes on the port postgres uses, port: 5432. Once these processes are killed postgres worked.
So..
lsof -i :5432 to print any current processes that may be running as well as their PID
kill -9 <PID> to kill the process.
initdb testdb to test
NOTE: Running GUI's for postgres will take up these processes and will restart them even if you kill the process on the certain PID. Close any giu's.
If this doesn't work I suggest checking launch daemons
sudo launchctl list | fgrep postgres to print out the daemon
sudo launchctl stop <printed process name>
initdb testdb to test

How to shut down Postgres 9.6.11 without pg_ctl on MacOS?

I have multiple installations of Postgres on my MacOS Mojave machine. Version 10.7 is running, and I want to shut it down, in order to start 9.6.
It's definitely running:
$ psql -h localhost -U postgres
Password for user postgres:
psql (9.6.11, server 10.7)
But I can't stop it:
/Library/PostgreSQL/10 $ bin/pg_ctl stop
pg_ctl: PID file "/usr/local/var/postgresql#9.6/postmaster.pid" does not exist
Is server running?
Nor with the 9.6 version of pg_ctl:
$ pg_ctl stop
pg_ctl: PID file "/usr/local/var/postgresql#9.6/postmaster.pid" does not exist
Is server running?
$ which pg_ctl
/usr/local/opt/postgresql#9.6/bin/pg_ctl
How can I shut down the server, when pg_ctl doesn't seem to be able to control it? I don't recall starting it - perhaps it automatically started when the machine last rebooted. I think I installed it with Homebrew but I'm not certain.
This ended up working:
First, get the pid:
$ sudo lsof -i:5432
Password:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 73 postgres 4u IPv6 0x8880707cadb2d1ab 0t0 TCP *:postgresql (LISTEN)
postgres 73 postgres 5u IPv4 0x8880707cadac18ab 0t0 TCP *:postgresql (LISTEN)
Now shut it down (SIGTERM):
$ sudo kill -15 73

MongoDB in Linux Mint 19

I am trying to use mongoDB in Linux mint 19. But I am getting below error.
What is the solution ?
You're starting the mongo shell client, which by default tries to connect to a mongod server running on localhost and listening on port 27017. However, there is no server listening there so the mongo shell notes that and exits.
You'll need to investigate why there was no mongod server listening there:
The MongoDB Server package isn't installed
You're specifying a non-default port in e.g. /etc/mongod.conf
The mongod process/service is not running
...
First verify that the Server package is installed:
sudo dpkg -l | grep -i ".*mongodb.*server"
Then check the status of the mongod service and go from there. That will tell you if it's running, what port it's listening on, what config file is used, etc.
sudo systemctl status mongod
If it's not running then try to start it:
sudo systemctl start mongod
If it's still not running then look at the log messages:
sudo journalctl -u mongod.service

Mongod [initandlisten] dbexit: rc: 48

When I run mongod I recieved this error. How can I solve this? Thanks.
enter image description here
Try to stop current active mongodb service and run it again
$ sudo service mongod stop
$ mongod
You may encounter the problem of Failed to stop mongod.service: Unit mongod.service not loaded, this error says that your mongod is not running. Check this answer
If you use Mac
$ sudo killall mongod
If it did not work, try to find out which process is running on port (27017) and kill it
$ sudo netstat -tulpn | grep :27017
Kill the process
$ sudo kill <pid>
Or just try on another port with mongod --port 27027

How to stop and restart memcached server?

How to stop and restart memcached server 1.4.5 in linux OS from command line?
Using root, try something like this:
/etc/init.d/memcached restart
Log in as root or do
su -
Then:
service memcached restart
If that doesn't work, then:
/etc/init.d/memcached restart
It all depends on which Linux distro (or other OS) you're using.
If you're using homebrew:
brew services restart memcached
sudo service memcached stop
sudo service memcached start
sudo service memcached restart
if linux
if install by apt-get
service memcached stop
service memcached restart
if install by source code
Usage: /etc/init.d/memcached {start|stop|restart|force-reload|status}
can also simply kill $pid to stop
sudo /etc/init.d/memcached restart
As root on CentOS 7:
systemctl start memcached
systemctl stop memcached
systemctl restart memcached
To tell the service to start at reboot (ex chkconfig):
systemctl enable memcached
To tell the service to not start at reboot:
systemctl disable memcached
To shutdown memcache daemon:
sudo service memcached stop
To start memcached daemon:
sudo service memcached start
Restart memcached server:
sudo service memcached restart
You can see if Memcache is currently runing:
sudo ps -e | grep memcached
And you can check the TCP or UDP ports if something (e.g. Memcache) is listening to it:
netstat -ap | grep TheChosenPort#
netstat -ap | grep 11211
For some Linuxes you need to change your commands like:
sudo /etc/init.d/memcached start
sudo /etc/init.d/memcached restart
sudo /etc/init.d/memcached stop
If you want to be allowed to shutdown the memcached server you can give it that option before start it :
memcached -A &
With this option when you connect to memcached server for example:
telnet localhost 11211
then you can use shutdown command to shutdown the server. You can also shutdown the memcached server when it is run as a process, first find the process PID using:
pidof memcached
then use:
kill PID command
This worked for me:
brew services stop memcached
If you have an older version of memcached and need a script to wrap memcached as a service, here it is:
Memcached Service Script
For me, I installed it on a Mac via Homebrew and it is not set up as a service. To run the memcached server, I simply execute memcached -d. This will establish Memcached server on the default port, 11211.
> memcached -d
> telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
version
VERSION 1.4.20