Support port number in postgres connection (#20662)

* Support port number in postgres connection

* Addressed a few comments from Trent
This commit is contained in:
Lijun Wang 2021-10-14 11:55:10 -07:00 committed by GitHub
parent e9a427b9c8
commit ad0a88f1f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -39,6 +39,7 @@ pub struct AccountsDbPluginPostgresConfig {
pub host: String,
pub user: String,
pub threads: Option<usize>,
pub port: Option<u16>,
}
#[derive(Error, Debug)]

View File

@ -25,6 +25,7 @@ use {
/// The maximum asynchronous requests allowed in the channel to avoid excessive
/// memory usage. The downside -- calls after this threshold is reached can get blocked.
const MAX_ASYNC_REQUESTS: usize = 10240;
const DEFAULT_POSTGRES_PORT: u16 = 5432;
struct PostgresSqlClientWrapper {
client: Client,
@ -147,7 +148,10 @@ pub trait PostgresClient {
impl SimplePostgresClient {
pub fn new(config: &AccountsDbPluginPostgresConfig) -> Result<Self, AccountsDbPluginError> {
let connection_str = format!("host={} user={}", config.host, config.user);
let port = config.port.unwrap_or(DEFAULT_POSTGRES_PORT);
let connection_str = format!("host={} user={} port={}", config.host, config.user, port);
match Client::connect(&connection_str, NoTls) {
Err(err) => {
return Err(AccountsDbPluginError::Custom(Box::new(AccountsDbPluginPostgresError::DataStoreConnectionError {