-1

I'm encountering a persistent issue with PostgreSQL where I repeatedly face the error message: 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? This issue occurs intermittently and seems to happen after some time of running normally. The only way I've been able to resolve it is by manually restarting the PostgreSQL service. However, the problem reoccurs after some time.

I have tried troubleshooting by checking if PostgreSQL is running using the ps aux | grep postgres command, verifying that PostgreSQL is indeed running. Also, I have reviewed the PostgreSQL logs, but I couldn't find any specific error messages or patterns that might be causing this issue.

I am hoping someone can shed light on what might be causing this issue and provide steps or insights on how to diagnose and fix it more effectively. If there are specific logs or configurations I should be looking at or testing, I would greatly appreciate any guidance.

Has anyone else encountered this issue and successfully resolved it? Your help is highly appreciated.

Thank you in advance!

Here is the postgresql log:

LOG: worker process: logical replication launcher (PID 13195) exited with exit code 1 user@db FATAL: terminating connection due to administrator command LOG: shutting down LOG: database system is shut down LOG: listening on IPv4 address "127.0.0.1", port 5432 LOG: could not bind IPv4 address "10.1.4.26": Cannot assign requested address HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. WARNING: could not create listen socket for "10.1.4.26" LOG: listening on IPv4 address "10.1.4.26", port 5432 LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" LOG: database system was shut down at 2023-08-10 22:35:12 UTC LOG: database system is ready to accept connections [unknown]@[unknown] LOG: incomplete startup packet user@db LOG: could not receive data from client: Connection reset by peer

shehinn p
  • 1
  • 3
  • What is your OS and how did you install? How do you restart the postgresql service? When it won't accept connections over localhost, does it still accept them over the unix-domain socket? When you run `ps aux | grep postgres`, what specifically do you see? – jjanes Aug 08 '23 at 14:05
  • OS is ubuntu. I'm restarting postgresql using the command `sudo service postgresql restart`. when im running the command `ps aux | grep postgres` im getting this `ubuntu@ip-172-31-18-203:~$ ps aux | grep postgres postgres 30490 0.0 0.1 708876 13824 ? Sl Aug10 0:07 /tmp/kinsing postgres 30670 99.3 29.9 2864088 2399804 ? Ssl Aug10 337:53 /tmp/kdevtmpfsi ubuntu 33774 0.0 0.0 8168 2364 pts/0 S+ 04:28 0:00 grep --color=auto postgres` – shehinn p Aug 11 '23 at 04:29
  • Here is the postgresql error log: `db_user@user FATAL: terminating connection due to administrator command LOG: received smart shutdown request LOG: background worker "logical replication launcher" (PID 617) exited with exit code 1 LOG: shutting down` – shehinn p Aug 11 '23 at 04:34
  • One more thing is that while this issue is happening when im checking `htop`, im getting : `PID:30670 USER:postgres PRI:20 NI:0 VIRT:2796M RES:2343M SHR:0 S:S CPU%:98.7 MEM%:29.9 TIME+:5h54:43 Command: /tmp/kdevtmpfsi` – shehinn p Aug 11 '23 at 04:48

2 Answers2

0

This usually happens when your system shuts down abruptly, try running postgres -D /usr/local/var/postgres, you might get the message

FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 4573) running in data directory "/usr/local/var/postgres"?

then run kill PID which in this case would be kill 4573

To stop future occurrence of this error, I suggest you always stop the server before shutting down the system.

  • When i'm running the command `postgres -D /usr/local/var/postgres`, im getting this: `Command 'postgres' not found, did you mean: command 'postgrey' from deb postgrey (1.36-5.1) Try: sudo apt install ` – shehinn p Aug 11 '23 at 04:36
0

You've been hacked. /tmp/kdevtmpfsi is a crypto mining malware. It is not postgresql, but it is running from your postgres account which is why ps shows it.

Your server keeps shutting down because whoever hacked you keeps shutting it down.

jjanes
  • 37,812
  • 5
  • 27
  • 34