The PostgreSQL installer (both web and CLI) ignores the port specification for the database server. It always assumes the default port 5432. This fix works for me:
--- includes/installer/PostgresInstaller.php 2020/02/17 08:12:10 1.1 +++ includes/installer/PostgresInstaller.php 2020/02/17 08:12:28 @@ -270,6 +270,7 @@ try { $p = [ 'host' => $this->getVar( 'wgDBserver' ), + 'port' => $this->getVar( 'wgDBport' ), 'user' => $user, 'password' => $password, 'dbname' => $db