Why does netstat show multiple entries for the Postgres process?

Posted on

Question :

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.

Answer :

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.

Leave a Reply

Your email address will not be published. Required fields are marked *