I'm trying to connect to Postgres in a C program using libpq
. When I'm running under my own username (which is the same as the username I've created for my Postgres database) everything is fine. When I try to run the program under root it fails with:
FATAL: Peer authentication failed for user "jqpublic"
In both cases the conninfo string I'm passing to PQconnectdb
is something like:
dbname=somedb user=jqpublic password=somepassword
If I add a host
option to the conninfo, the connection succeeds, but then I'll be connecting over TCP/IP which my tests show is measurably slower than the default UNIX sockets. Is there a way to use the UNIX socket while running under root (or another user with a name not the same as the DB user)?