https://www.postgresql.org/docs/current/libpq-example.html
compile the 1st example source code.
gcc test.c -L/usr/local/pgsql15/lib -I/usr/local/pgsql15/include -lpq
Cannot figure out the connection string. All the following failed.
./a.out postgresql:///test15?host=/tmp&port=5415
./a.out postgresql://test15?host=/tmp:5415
./a.out postgresql://test15?host=/tmp&port='5415'
./a.out postgresql://test15?host=/tmp:'5415'
./a.out postgresql://test15?host=/tmp&port=/tmp
./a.out postgresql:///tmp:5415/test15?
The error is almost similar:
connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
[1]+  Exit 1                  ./a.out postgresql:///test15?host=/tmp
cat  /usr/local/pgsql15/data_42091266/postgresql.conf | rg unix
return
unix_socket_directories = '/tmp'        # comma-separated list of directories
#unix_socket_group = ''                 # (change requires restart)
unix_socket_permissions = 0777          # begin with 0 to use octal notation


&is special to the shell, and ended the command before it got to the port part. Escape the ampersand.