PostgreSQL Linux PAM Authentication Error
Since you didn't specify the -h option, PostgreSQL connects via local Unix socket. This is governed by the local entry in pg_hba.conf. Hence you are authenticated with &quot;peer&quot; authentication. But since you are not operating system user test, peer authentication fails.
To get PAM authentication, connect with -h 127.0.0.1.