According to https://www.postgresql.org/docs/current/gssapi-auth.html:
When GSSAPI uses Kerberos, it uses a standard principal in the format servicename/hostname@realm
and
care needs to be taken to specify the correct principal details when making the connection from the client using the krbsrvname connection parameter. (See also Section 33.1.2.) The installation default can be changed from the default postgres at build time using ./configure --with-krb-srvnam=whatever.
But if I look into the Postgres source code at Github,
Does this mean the server does not need to be recompiled if I need to use another krbsrvname?
It is the client, not the server, that would need to be recompiled. (Although usually you would probably recompile both together). Or you could just override the default with the correct value, and not recompile anything.