-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #522 from CartoDB/521-test-robustness-pgbouncer
521 test robustness pgbouncer
- Loading branch information
Showing
5 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
#!/bin/bash | ||
|
||
# To make output dates deterministic | ||
export TZ='Europe/Rome' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const { Client } = require('pg'); | ||
|
||
const dbConfig = { | ||
db_user: process.env.PGUSER || 'postgres', | ||
db_host: global.settings.db_host, | ||
db_port: global.settings.db_port, | ||
db_batch_port: global.settings.db_batch_port | ||
}; | ||
|
||
module.exports.resetPgBouncerConnections = function (callback) { | ||
// We assume there's no pgbouncer if db_port === db_batch_port | ||
if (dbConfig.db_port === dbConfig.db_batch_port) { | ||
return callback(); | ||
} | ||
|
||
const client = new Client({ | ||
database: 'pgbouncer', | ||
user: dbConfig.db_user, | ||
host: dbConfig.db_host, | ||
port: dbConfig.db_port | ||
}); | ||
|
||
// We just chain a PAUSE followed by a RESUME to reset internal pool connections of PgBouncer | ||
client.connect(); | ||
client.query('PAUSE', err => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
client.query('RESUME', err => { | ||
client.end(); | ||
return callback(err); | ||
}); | ||
}); | ||
}; |