diff --git a/accountsdb-plugin-postgres/src/accountsdb_plugin_postgres.rs b/accountsdb-plugin-postgres/src/accountsdb_plugin_postgres.rs index d06a2fd316..8150f6fc2d 100644 --- a/accountsdb-plugin-postgres/src/accountsdb_plugin_postgres.rs +++ b/accountsdb-plugin-postgres/src/accountsdb_plugin_postgres.rs @@ -39,6 +39,7 @@ pub struct AccountsDbPluginPostgresConfig { pub host: String, pub user: String, pub threads: Option, + pub port: Option, } #[derive(Error, Debug)] diff --git a/accountsdb-plugin-postgres/src/postgres_client.rs b/accountsdb-plugin-postgres/src/postgres_client.rs index e17834b8a8..05e3043e29 100644 --- a/accountsdb-plugin-postgres/src/postgres_client.rs +++ b/accountsdb-plugin-postgres/src/postgres_client.rs @@ -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 { - 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 {