fix(redshift): raise postgres max_connections to 500 (#6421)

* fix(redshift): raise postgres max_connections to 500

The Postgres container behind a Redshift cluster runs with the default max_connections of 100, and each retained session keeps a connection open. Near 100 sessions, Data API calls and JDBC clients on that cluster encounter 'sorry, too many clients already', well before reaching the 500-session limit. Raising max_connections to 500 in RedshiftContainerManager lets the documented 500-session limit apply.

* fix(redshift): raise default proxy max connections to 500

The PostgreSQL backend limit was raised to 500, but the Redshift auth proxy connection semaphore defaulted to 100 via proxy-max-connections. As a result, client connections above 100 were refused by the proxy before reaching PostgreSQL. Raise the default proxy-max-connections to 500 across config, application YAML, and documentation.

* fix(redshift): follow node type for max_connections and raise proxy default to 2000

* fix(redshift): support rg node types, pass serverless from runtime, and update test stubs

- Include rg.* node types for 2,000 max_connections
- Pass 'serverless' node type from RedshiftServerlessRuntime and drop prefix check
- Update start(...) stubs across integration tests with the six-argument signature
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-24 21:09:27 -04:00
1 parent acb9fd2cd6
commit fac6378abd
17 files changed
+159 -36

No files matched your search

@@ -1729,7 +1729,7 @@ public interface EmulatorConfig {
int proxyHandshakeTimeoutMillis();
@WithDefault("5000")
int proxyBackendConnectTimeoutMillis();
@WithDefault("100")
@WithDefault("2000")
int proxyMaxConnections();
@WithDefault("1000000")
@@ -175,7 +175,8 @@ public class RedshiftService {
try {
LOG.infov("Recovering container for persisted cluster: {0}", cluster.getClusterIdentifier());
RedshiftContainerHandle handle = containerManager.adoptOrStart(
entry.accountId(), cluster.getClusterIdentifier(), cluster.getMasterUsername(), password);
entry.accountId(), cluster.getClusterIdentifier(), cluster.getMasterUsername(), password,
CLUSTER_DB_NAME, cluster.getNodeType());
// A cluster persisted before the auth proxy existed has proxyPort == 0. Allocate one
// now; its endpoint changes exactly once after this upgrade. Existing clusters keep
@@ -272,7 +273,8 @@ public class RedshiftService {
int proxyPort = -1;
try {
String accountId = clusters.accountId();
RedshiftContainerHandle handle = containerManager.start(accountId, identifier, username, password);
RedshiftContainerHandle handle = containerManager.start(
accountId, identifier, username, password, CLUSTER_DB_NAME, cluster.getNodeType());
proxyPort = allocateProxyPort();
Endpoint endpoint = proxyEndpoint(proxyPort);
cluster.setProxyPort(proxyPort);
@@ -994,7 +996,8 @@ public class RedshiftService {
String password = cluster.getMasterPassword() != null ? cluster.getMasterPassword() : "admin";
RedshiftContainerHandle handle = containerManager.start(
accountId, clusterIdentifier, cluster.getMasterUsername(), password);
accountId, clusterIdentifier, cluster.getMasterUsername(), password,
CLUSTER_DB_NAME, cluster.getNodeType());
// Reuse the stored proxy port so the advertised endpoint is unchanged by a reboot.
if (proxyPort < 0) {
@@ -1309,7 +1312,8 @@ public class RedshiftService {
int proxyPort = -1;
try {
String accountId = clusters.accountId();
RedshiftContainerHandle handle = containerManager.start(accountId, clusterIdentifier, username, password);
RedshiftContainerHandle handle = containerManager.start(
accountId, clusterIdentifier, username, password, CLUSTER_DB_NAME, cluster.getNodeType());
proxyPort = allocateProxyPort();
Endpoint endpoint = proxyEndpoint(proxyPort);
cluster.setProxyPort(proxyPort);
@@ -35,6 +35,8 @@ public class RedshiftContainerManager {
private static final Logger LOG = Logger.getLogger(RedshiftContainerManager.class);
private static final String DEFAULT_DATABASE = "dev";
static final int DEFAULT_MAX_CONNECTIONS = 500;
static final int LARGE_CLUSTER_MAX_CONNECTIONS = 2000;
private final ContainerBuilder containerBuilder;
private final ContainerLifecycleManager lifecycleManager;
@@ -69,27 +71,34 @@ public class RedshiftContainerManager {
}
public RedshiftContainerHandle start(String accountId, String clusterIdentifier, String masterUsername, String masterPassword) {
return start(accountId, clusterIdentifier, masterUsername, masterPassword, DEFAULT_DATABASE);
return start(accountId, clusterIdentifier, masterUsername, masterPassword, DEFAULT_DATABASE, null);
}
/** Starts the container with {@code databaseName} as its one database, instead of the default {@code dev}. */
public RedshiftContainerHandle start(String accountId, String clusterIdentifier, String masterUsername,
String masterPassword, String databaseName) {
return start(accountId, clusterIdentifier, masterUsername, masterPassword, databaseName, null);
}
public RedshiftContainerHandle start(String accountId, String clusterIdentifier, String masterUsername,
String masterPassword, String databaseName, String nodeType) {
String image = config.services().redshift().imageVersion();
String containerName = containerName(accountId, clusterIdentifier);
// Only the current name: adoptOrStart does not look for legacy-named survivors.
stop(accountId, clusterIdentifier);
String effectiveDb = (databaseName != null && !databaseName.isBlank()) ? databaseName : DEFAULT_DATABASE;
List<String> envVars = List.of(
"POSTGRES_USER=" + masterUsername,
"POSTGRES_PASSWORD=" + masterPassword,
"POSTGRES_DB=" + databaseName
"POSTGRES_DB=" + effectiveDb
);
int maxConnections = maxConnections(clusterIdentifier, nodeType);
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
.withName(containerName)
.withEnv(envVars)
.withCmd(List.of("postgres", "-c", "allow_system_table_mods=on"))
.withCmd(List.of("postgres", "-c", "allow_system_table_mods=on", "-c", "max_connections=" + maxConnections))
.withDockerNetwork(config.services().redshift().dockerNetwork())
.withLogRotation();
@@ -103,7 +112,7 @@ public class RedshiftContainerManager {
ContainerSpec spec = specBuilder.build();
ContainerInfo info = lifecycleManager.createAndStartEphemeral(spec);
return initializeAndRegisterHandle(info, accountId, clusterIdentifier, masterUsername, containerName, enginePort,
databaseName);
effectiveDb);
}
/**
@@ -117,20 +126,26 @@ public class RedshiftContainerManager {
* project's decision not to provision reusable named volumes for Redshift containers.
*/
public RedshiftContainerHandle adoptOrStart(String accountId, String clusterIdentifier, String masterUsername, String masterPassword) {
return adoptOrStart(accountId, clusterIdentifier, masterUsername, masterPassword, DEFAULT_DATABASE);
return adoptOrStart(accountId, clusterIdentifier, masterUsername, masterPassword, DEFAULT_DATABASE, null);
}
/** As {@link #adoptOrStart(String, String, String, String)} for a container whose database is not {@code dev}. */
public RedshiftContainerHandle adoptOrStart(String accountId, String clusterIdentifier, String masterUsername,
String masterPassword, String databaseName) {
return adoptOrStart(accountId, clusterIdentifier, masterUsername, masterPassword, databaseName, null);
}
public RedshiftContainerHandle adoptOrStart(String accountId, String clusterIdentifier, String masterUsername,
String masterPassword, String databaseName, String nodeType) {
String containerName = containerName(accountId, clusterIdentifier);
Optional<Container> existing = lifecycleManager.findByName(containerName);
if (existing.isEmpty()) {
LOG.warnv("No surviving container for cluster {0}; starting a fresh empty one: the previous"
+ " contents are not recoverable (no reusable named volume backs Redshift containers)", clusterIdentifier);
return start(accountId, clusterIdentifier, masterUsername, masterPassword, databaseName);
return start(accountId, clusterIdentifier, masterUsername, masterPassword, databaseName, nodeType);
}
String effectiveDb = (databaseName != null && !databaseName.isBlank()) ? databaseName : DEFAULT_DATABASE;
adoptedContainers.put(containerKey(accountId, clusterIdentifier), existing.get().getId());
LOG.infov("Adopting existing container {0} for cluster {1} to avoid discarding its data",
containerName, clusterIdentifier);
@@ -138,7 +153,24 @@ public class RedshiftContainerManager {
ContainerInfo info = lifecycleManager.adopt(existing.get().getId(), List.of(enginePort),
containerBuilder.resolveDockerNetwork(config.services().redshift().dockerNetwork()));
return initializeAndRegisterHandle(info, accountId, clusterIdentifier, masterUsername, containerName, enginePort,
databaseName);
effectiveDb);
}
static int maxConnections(String clusterIdentifier, String nodeType) {
return maxConnectionsForNodeType(nodeType);
}
static int maxConnectionsForNodeType(String nodeType) {
if (nodeType == null || nodeType.isBlank()) {
return DEFAULT_MAX_CONNECTIONS;
}
String normalized = nodeType.toLowerCase().trim();
if (normalized.startsWith("ra3") || normalized.startsWith("rg")
|| normalized.endsWith("8xlarge") || normalized.endsWith("16xlarge")
|| normalized.equals("serverless")) {
return LARGE_CLUSTER_MAX_CONNECTIONS;
}
return DEFAULT_MAX_CONNECTIONS;
}
private RedshiftContainerHandle initializeAndRegisterHandle(
@@ -72,8 +72,8 @@ public class RedshiftServerlessRuntime {
String backendId = backendId(region, workgroupName);
try {
RedshiftContainerHandle handle = adopt
? containerManager.adoptOrStart(accountId, backendId, masterUsername, masterPassword, dbName)
: containerManager.start(accountId, backendId, masterUsername, masterPassword, dbName);
? containerManager.adoptOrStart(accountId, backendId, masterUsername, masterPassword, dbName, "serverless")
: containerManager.start(accountId, backendId, masterUsername, masterPassword, dbName, "serverless");
proxyManager.startProxy(relayKey(accountId, backendId), endpoint.getPort(),
handle.getHost(), handle.getPort(), endpoint.getAddress(),
masterUsername, masterPassword, dbName,