Why does netstat show multiple entries for the Postgres process?

All we need is an easy explanation of the problem, so here it is.

netstat -ap | grep postgre

return

tcp        0      0 localhost:5433          0.0.0.0:*               LISTEN      15416/postgres
tcp        0      0 localhost:5433          localhost:33138         ESTABLISHED 15435/postgres: 15/
unix  2      [ ACC ]     STREAM     LISTENING     75271    15416/postgres       /var/run/postgresql/.s.PGSQL.5433

psql:

select pg_backend_pid();

return

+----------------+
| pg_backend_pid |
+----------------+
|          15435 |
+----------------+

in another tab. run ps aux | grep postgres
return

postgres 15416  0.0  0.7 217652 29532 ?        Ss   20:42   0:00 /usr/lib/postgresql/15/bin/postgres -D /var/lib/postgresql/15/main -c config_file=/etc/postgresql/15/main/postgresql.conf

First command return 3 rows. I get the meaning of the second row.
So i guess 15416 refer to the server process id. But what does last row 75271 mean?
I also didn’t get the meaning of unix 2 in the last row.

I found the man page of netstat: https://man7.org/linux/man-pages/man8/netstat.8.html
But I don’t know how to display column.So the netsat result not that intuitive.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Your server is listening on both a TCP socket, and a Unix domain socket (i.e. a special file, which has a name and directory like regular files do, but doesn’t have any content and is just there to help client and server find each other).

That last line is about the Unix domain socket. 75271 is the inode of that file. Your grep has stripped off the header lines which netstat outputs, so of course you can’t see them. It might be better to pipe the output to less rather than grep. Or sent it to a file, then use your favorite text editor to look at the file.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply