Postgresql – What exactly is the use of the column USER in a pg_hba.conf file

postgresql

Let's say I have a pg_hba.conf file for my Postgresql server. I know that in order to allow other IP addresses to access my Postgresql server, I need to write their entries in my pg_hba.conf file. Now, what I don't understand is the use of the column USER in the pg_hba.conf file. Lets say my file contains the following entry

host all    user123     192.168.10.27/32    md5

According to my understanding, it means that in order to access my Postgresql server from the machine with IP 192.168.10.27, someone needs to be logged in as the user 'user123'.
But, as far as i understand, in order to access my Postgresql server from 192.168.10.27, i need to create a separate connection to my server from 192.168.10.27. So even if I am logged in as 'user123', I will be anyways creating a separate connection to access my Postgresql server, which won't depend on whether I am logged in as 'user123' or someone else.
Hence, I don't understand the use of USER column.
Can someone please help me?

Best Answer

"someone needs to be logged in as the user 'user123'" - no, that means that someone tries to connect with the Postgres database user user123.

This can be used to allow certain database users to connect only from certain client computers, e.g. the user for a web application is only allowed to connect from the IP of the webserver.

Or this can be used to prevent superuser logins from remote connections by only allowing local connections for the database user postgres.