I mean, Once I change the hostname then how will the socket read the new hostname ? Does it require a postgres service restart ?
-h doesn't strictly mean hostname (the wording choice here does seem problematic), rather it is simply a direct specification of how and where the psql client looks for and connects to the server. When the specification is a filename it is that file that is used and hostname and any other networking-related stuff is immaterial. Though the server does choose to borrow the port number 5432 from networking to construct the unique name out of convenience.