Database connection onto an module
I'm using this one to swith and send a query 

in the settings.php add

databases['customer_db']['default'] = [
  'driver' =&gt; 'pgsql',
  'database' =&gt; 'drupal',
  'username' =&gt; 'drupal',
  'password' =&gt; 'drupal',
  'host' =&gt; 'xx.xx.xx.xx',
  'port' =&gt; '5432',
  'prefix' =&gt; '',
  'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\pgsql',
];


Then use when it's necesary

$db = \Drupal\Core\Database\Database::getConnection('default', 'customer_db'); 
print_r($db-&gt;databaseType());
$query = $db-&gt;query("SELECT * FROM customer");
...