diff --git a/lib/dialects/postgres/index.js b/lib/dialects/postgres/index.js index a45edc3ee..6b5771853 100644 --- a/lib/dialects/postgres/index.js +++ b/lib/dialects/postgres/index.js @@ -80,6 +80,14 @@ class Client_PG extends Client { _acquireOnlyConnection() { const connection = new this.driver.Client(this.connectionSettings); + connection.on('error', (err) => { + connection.__knex__disposed = err; + }); + + connection.on('end', (err) => { + connection.__knex__disposed = err || 'Connection ended unexpectedly'; + }); + return connection.connect().then(() => connection); } @@ -90,14 +98,6 @@ class Client_PG extends Client { return this._acquireOnlyConnection() .then(function (connection) { - connection.on('error', (err) => { - connection.__knex__disposed = err; - }); - - connection.on('end', (err) => { - connection.__knex__disposed = err || 'Connection ended unexpectedly'; - }); - if (!client.version) { return client.checkVersion(connection).then(function (version) { client.version = version;