On Thu, Oct 24, 2024 at 07:35:26PM -0400, Wietse Venema via Postfix-users wrote:

> > Note, my cursory look at the code suggests that URI connection strings
> > MUST specify a database name, the required "dbname" parameter is never
> > used to augment the URI, even if it appears to not include the required
> > databasename path component.
> 
> I was thinking of URIs that specify no database name.
> 
>     postgresql://localhost
>     postgresql://localhost:5432
>     postgresql://user@localhost
>     postgresql://user:secret@localhost
> 
> Does that mean it will use a hard-coded database name?

At least for unix-domain socket connections, Postgres appears to
default a database equal to the username attempting the connection.

With "hosts = postgresql:///" I get:

    postmap: warning: connect to pgsql server postgresql:///: connection to 
server on socket "/run/postgresql/.s.PGSQL.5432" failed: FATAL:  database 
"viktor" does not exist?
    postmap: fatal: table pgsql:/tmp/table.cf: query error: Application error

while with "hosts = postgresql:///dane", I am able to make queries
against the DANE/DNSSEC survey database:

    $ postmap -q postfix.org pgsql:/tmp/table.cf
    list.sys4.de

Lots of text at: https://www.postgresql.org/docs/16/libpq-connect.html
It also mentions that:
    
    The URI scheme designator can be either postgresql:// or
    postgres://. 

Perhaps we should support both?

All the while the unused "dbname" was set to "dane".

    
https://github.com/vdukhovni/postfix/blob/a5b1b93841f14c32ddc9772887a664e7736b3826/postfix/src/global/dict_pgsql.c#L565-L573

    static void plpgsql_connect_single(DICT_PGSQL *dict_pgsql, HOST *host)
    {
        if (host->type == TYPECONNSTR) {
            host->db = PQconnectdb(host->name);
        } else {
            host->db = PQsetdbLogin(host->name, host->port, NULL, NULL,
                                    dict_pgsql->dbname, dict_pgsql->username,
                                    dict_pgsql->password);
        }
        ...

The "dict_pgsql->dbname" value is only used for non-URI "hosts" elements.

I've never used "pgsql" tables myself.  The only Postgres database I
operate listens only on a unix-domain socket.  I don't 

-- 
    Viktor.
_______________________________________________
Postfix-users mailing list -- postfix-users@postfix.org
To unsubscribe send an email to postfix-users-le...@postfix.org

Reply via email to