In order to use streaming backups I need pg_receivexlog which I'm getting from the postgres repo (9.6+180.pgdg14.04+1), thus my barman server has a full installation of postgres even though it's not needed...
When trying to configure streaming from a remote server I was getting connection timeout from 'barman receive-wal' and errors in the barman log such as:
2017-04-25 12:40:02,373 [25422] barman.server ERROR: failed opening the PostgreSQL streaming connection
2017-04-25 12:40:09,346 [25365] barman.command_wrappers INFO: postgres01: pg_receivexlog: could not connect to server: could not connect to server: Connection timed out
2017-04-25 12:40:09,347 [25365] barman.command_wrappers INFO: postgres01: Is the server running on host "postgres01" (10.x.x.x) and accepting
2017-04-25 12:40:09,348 [25365] barman.command_wrappers INFO: postgres01: TCP/IP connections on port 5433?
However, if I ran the same pg_receivexlog command as was shown in the ps output, it connected immediately to my server and began streaming - e.g.:
/usr/lib/postgresql/9.6/bin/pg_receivexlog --dbname="dbname=replication host=postgres01 replication=true user=streaming_barman application_name=barman_receive_wal" --verbose --no-loop --no-password --directory=/var/lib/barman/pg01/streaming --slot=barman
Using strace to look at the envionment variables I could see that when barman's command_wrappers.py called out to pg_receivexlog it had PGPORT set to 5433 which I then established was being obtained fromfrom my local /etc/postgresql/9.6/main/postgresql.conf file. When running the above command from my shell, the PGPORT variable was not set.
The documentation examples e.g. ( http://docs.pgbarman.org/release/2.1/#the-server-configuration-file ) don't include a port number in the connection string, and setting one works-around this problem. However I think that the PGPORT variable should not be set based on the local config which bears no relation to the remote server's config, and pg_receivexlog should be left to try its own defaults.
This is due to the Ubuntu's pg_wrapper (more info man pg_wrapper).
The right way to solve it is to set the Barman's path_prefix setting to /usr/lib/postgresql/9.6/bin avoiding to use pg_wrapper to execute pg_receivexlog (See http://docs.pgbarman.org/release/2.1/#wal-streaming).
Regards,
Marco