2017-12-25 20:13 GMT+01:00 Wietse Venema <[email protected]>:
> Magos?nyi ?rp?d:
> > Hi,
> >
> > Any news with this patch? I don't see it in 3.2.4 yet.
>
> Features are not added to the stable release.
>
>
I have submitted it more than a year ago (2016.12.11).
I guess there should have been a release since then.
> > >
> > > Thanks. I'll queue this with the other part. Postfix does not change
> > > often, so patch against a stable release is probably your best bet.
>
> I can't find this in the work queue. Is this patch complete, or
> does there need to be code that adds support for the postgresql:
> prefix, in addition to the existing support for unix: and inet:?
>
>
I have submitted the code earlier. I am attaching that patch again.
Wietse
>
> > > > --- pgsql_table.orig 2016-12-11 20:53:49.030543785 +0100
> > > > +++ pgsql_table 2016-12-11 20:56:44.386592266 +0100
> > > > @@ -89,10 +89,12 @@
> > > > # .IP "\fBhosts\fR"
> > > > # The hosts that Postfix will try to connect to and query from.
> > > > # Specify \fIunix:\fR for UNIX-domain sockets, \fIinet:\fR for
> TCP
> > > > -# connections (default). Example:
> > > > +# connections (default), of \fIpostgresql:\fR if you use a
> connection
> > > > +# string. Example:
> > > > # .nf
> > > > # hosts = host1.some.domain host2.some.domain:port
> > > > # hosts = unix:/file/name
> > > > +# hosts =
> > > > postgresql://[email protected]/tablename?sslmode=require
> > > > # .fi
> > > > #
> > > > # The hosts are tried in random order, with all connections over
> > > >
> > > >
> > >
>
Description: connection string support for pgsql
You can use a postgres connection string at the hosts line
.
postfix (3.1.0-3) unstable; urgency=medium
Author: Arpad Magosanyi <[email protected]>
---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:
Origin: other
Bug-Ubuntu: https://launchpad.net/bugs/1553928
Last-Update: <2016-12-11>
--- postfix-3.1.0.orig/src/global/dict_pgsql.c
+++ postfix-3.1.0/src/global/dict_pgsql.c
@@ -180,6 +180,7 @@
#define TYPEUNIX (1<<0)
#define TYPEINET (1<<1)
+#define TYPECONNSTRING (1<<2)
#define RETRY_CONN_MAX 100
#define RETRY_CONN_INTV 60 /* 1 minute */
@@ -190,7 +191,7 @@ typedef struct {
char *hostname;
char *name;
char *port;
- unsigned type; /* TYPEUNIX | TYPEINET */
+ unsigned type; /* TYPEUNIX | TYPEINET |
TYPECONNSTRING*/
unsigned stat; /* STATUNTRIED | STATFAIL | STATCUR */
time_t ts; /* used for attempting
reconnection */
} HOST;
@@ -467,7 +468,8 @@ static HOST *dict_pgsql_get_active(PLPGS
/* try the active connections first; prefer the ones to UNIX sockets */
if ((host = dict_pgsql_find_host(PLDB, STATACTIVE, TYPEUNIX)) != NULL ||
- (host = dict_pgsql_find_host(PLDB, STATACTIVE, TYPEINET)) != NULL) {
+ (host = dict_pgsql_find_host(PLDB, STATACTIVE, TYPEINET)) != NULL ||
+ (host = dict_pgsql_find_host(PLDB, STATACTIVE, TYPECONNSTRING)) !=
NULL) {
if (msg_verbose)
msg_info("%s: found active connection to host %s", myname,
host->hostname);
@@ -483,7 +485,9 @@ static HOST *dict_pgsql_get_active(PLPGS
((host = dict_pgsql_find_host(PLDB, STATUNTRIED | STATFAIL,
TYPEUNIX)) != NULL ||
(host = dict_pgsql_find_host(PLDB, STATUNTRIED | STATFAIL,
- TYPEINET)) != NULL)) {
+ TYPEINET)) != NULL ||
+ (host = dict_pgsql_find_host(PLDB, STATUNTRIED | STATFAIL,
+ TYPECONNSTRING)) != NULL)) {
if (msg_verbose)
msg_info("%s: attempting to connect to host %s", myname,
host->hostname);
@@ -622,11 +626,21 @@ static PGSQL_RES *plpgsql_query(DICT_PGS
*/
static void plpgsql_connect_single(HOST *host, char *dbname, char *username,
char *password)
{
- if ((host->db = PQsetdbLogin(host->name, host->port, NULL, NULL,
- dbname, username, password)) == NULL
- || PQstatus(host->db) != CONNECTION_OK) {
- msg_warn("connect to pgsql server %s: %s",
- host->hostname, PQerrorMessage(host->db));
+ PGconn *conn;
+ if (msg_verbose)
+ msg_info("dict_pgsql: connecting to host %s (%u)", host->hostname,
+ host->type);
+ if (host->type = TYPECONNSTRING) {
+ conn = PQconnectdb(host->name);
+ } else {
+ conn =
+ PQsetdbLogin(host->name, host->port, NULL, NULL, dbname, username,
+ password);
+ }
+ host->db = conn;
+ if (conn == NULL || PQstatus(host->db) != CONNECTION_OK) {
+ msg_warn("connect to pgsql server %s: %s", host->hostname,
+ PQerrorMessage(host->db));
plpgsql_down_host(host);
return;
}
@@ -815,6 +829,12 @@ static HOST *host_init(const char *hostn
* Ad-hoc parsing code. Expect "unix:pathname" or "inet:host:port", where
* both "inet:" and ":port" are optional.
*/
+ if (strncmp(d, "postgresql:", 11) == 0) {
+ host->type = TYPECONNSTRING;
+ host->name = mystrdup(d);
+ host->port = 0;
+ } else {
+
if (strncmp(d, "unix:", 5) == 0 || strncmp(d, "inet:", 5) == 0)
d += 5;
host->name = mystrdup(d);
@@ -825,11 +845,11 @@ static HOST *host_init(const char *hostn
host->type = TYPEINET;
else
host->type = TYPEUNIX;
-
+ }
if (msg_verbose > 1)
msg_info("%s: host=%s, port=%s, type=%s", myname, host->name,
host->port ? host->port : "",
- host->type == TYPEUNIX ? "unix" : "inet");
+ host->type == TYPEUNIX ? "unix" : (host->type == TYPEINET ?
"inet" : "connstring"), host->type);
return host;
}