Moving Session Initialization into RDS Proxy: What to Test
Test common PostgreSQL session defaults before moving client SET statements into an RDS Proxy initialization query. Compare fresh backends, pooled clients and rollback.
Move initialization into RDS Proxy only when every affected client needs the same initial state. Test that state on newly created backend connections, reused application clients and replacement connections before removing the client-side statements. A successful proxy configuration update does not establish that all pooled connections have the intended state.
AWS documents an initialization query that runs when the proxy opens a new backend database connection. It does not run on every application-pool checkout. Client statements still reach the database, even if the initialization query contains the same SQL. The application change and proxy change therefore need a coordinated comparison. See AWS's initialization-query guidance.
This article gives application and database owners a bounded test for RDS for PostgreSQL. The worked example uses PostgreSQL 16 semantics, two synthetic clients and a common UTC time-zone requirement. Check the actual supported engine version, driver and proxy configuration before running anything. No AWS request, SQL statement or load test was executed for this article. MySQL, MariaDB and SQL Server require separate engine-specific tests.
Establish which state can be shared
Inventory the SQL and connection options sent by the deployed driver, framework and pool. Include startup, first query, checkout, return, cancellation and error paths. A statement hidden in an ORM callback can remain active after an engineer removes a similar line from application code.
For each setting, record who needs its value and for how long. A common time zone may be a candidate. A tenant-specific schema, request identity or user-selected locale needs a different state contract. Moving such a value into shared initialization can give another caller the wrong behavior. Exclude credentials and customer identifiers from the query and shared evidence.
The RDS API's InitQuery contract also warns that people who can view or manage the target-group configuration can see the initialization query. Do not place passwords or long-lived encryption keys there. Session initialization is not a secret-distribution mechanism.
Confirm why the change is being considered. PostgreSQL client SQL SET commands are a documented pinning trigger. MySQL and MariaDB track some settings, so an identical-looking statement may already permit reuse. Use the engine-specific pinning reference and the existing pinning diagnosis before expecting a connection reduction. This article tests a proposed state migration, rather than diagnosing every cause of high backend occupancy.
Separate backend creation from client checkout
An application client can remain connected to the proxy across many checkouts. Its next transaction can use a pooled backend when reuse is safe. Creating another application client does not, by itself, demonstrate that the proxy created another database connection.
Consequently, three observations belong in the comparison: the proxy configuration readback, evidence of backend setup, and the value returned through the application's real connection path. None substitutes for the others. Keep the endpoint, target, database user, driver build and test cohort beside the results so a direct database probe cannot be mistaken for a proxy test.
Do not assume an initialization-query edit reinitializes already-open backends. AWS describes new-connection setup, not an immediate refresh of every pooled connection. If an in-place change cannot establish the state of older backends, record that transition as unresolved. Do not terminate production sessions to manufacture a clean sample.
A separate approved test proxy or other explicitly controlled fresh-backend test can make the lifecycle observable. It adds configuration and resource costs, so obtain an owner-approved budget, duration and cleanup plan first. Preserve TLS, authentication, database privileges and network boundaries. The test does not need broader permissions or a live customer workload.
Compare the same read before and after
Assume an isolated PostgreSQL 16 test target has an effective default time zone of America/New_York. This deliberately different default is a fixture assumption, not an AWS default or a production setting recommendation. Both clients require UTC. Neither driver's startup options nor a pool-reset callback override the time zone in this fixture. There are no tenant-dependent settings or external effects.
In the baseline, the application initializes a new client with SET TIME ZONE 'UTC'. In the candidate, the reviewed proxy initialization query contains that statement and the application omits the corresponding client statement. Keep other driver, pool and workload behavior unchanged. A reset that independently issues SET is a confound to investigate, not something to disable without checking what it protects.
Read current_setting('TimeZone') and format one fixed instant with to_char(TIMESTAMPTZ '2026-01-15 12:00:00+00', 'YYYY-MM-DD HH24:MI'). The SQL result is text; retain that exact text before any application date conversion. PostgreSQL documents time-zone display behavior and the to_char formatting fields. The expected values below are synthetic acceptance fixtures, not captured query output.
| Controlled case | Expected readback | Decision |
|---|---|---|
| Baseline client sends its UTC initialization | UTC; 2026-01-15 12:00 | Establish the old behavior before comparing a change |
| Candidate uses a newly initialized backend; client omits that statement | UTC; 2026-01-15 12:00 | State matches the baseline for this check |
| Negative control omits both initialization paths on a fresh backend | America/New_York; 2026-01-15 07:00 | Detect the five-hour mismatch and reject the candidate |
| A later client operation intentionally selects New York time | That client's agreed New York result; the other client still meets its UTC contract | Shared initialization cannot replace intentional per-client behavior |
The third row is the discriminator. If the test cannot distinguish it from the candidate, its readback path is unsuitable. The five-hour difference follows this fixed January instant; it is not a year-round offset assumption. For another test date, use the named zone's applicable rules.
Run the read at first use, after a completed transaction, on a later checkout and after a normally closed client reconnects. Exercise both clients, their ordinary error cleanup and cancellation paths within the approved scope. Record unexpected results rather than assuming which backend was selected. Two clients cannot prove production multiplexing capacity or guarantee that a particular backend is reused.
Require correctness before interpreting the connection chart
Keep expected state and business-result checks separate from proxy metrics. A correct time-zone result says nothing about a different setting that the application also depends on. Add a small synthetic operation that exercises the setting's real consequence before accepting a migration for that application. Schema selection, collation or transaction behavior needs its own expected result, not a copied time-zone check.
Then compare offered work, completed work, acquisition waiting, errors and proxy observations over matching windows. AWS defines DatabaseConnectionsCurrentlySessionPinned and related metrics, including their dimensions and statistics. Keep those fields with each series. A quiet two-client test can be invisible in aggregated data. Label an inconclusive metric result instead of reporting zero pinning or increasing load without permission.
If values match but pinning persists, check whether the client still sends initialization, reset or another documented pinning operation. Do not add a pinning filter as an unrecorded second change. A lower pinned count accompanied by wrong results, timeouts or missing completions fails the comparison. No connection-count or cost improvement is assumed here.
Use one compact acceptance record for the candidate:
| Record field | Evidence to retain |
|---|---|
| Connection scope | Engine/version, driver/pool build, endpoint, target and synthetic database role |
| State contract | Exact common setting, old initialization path and callers that need a different value |
| Lifecycle coverage | First use, transaction boundary, checkout, reconnect and observed backend-setup boundary |
| Correctness and negative control | Exact returned values, expected synthetic operation and the deliberately missing-initialization failure |
| Operational comparison | Matching workload/windows, completion/error evidence, metric scope and any inconclusive observation |
| Transition and reversal | Configuration versions, cohort owner, old-backend uncertainty and the approved restoration test |
Store credentials and detailed traces in the team's restricted system, with appropriate retention. The record should identify that evidence without copying secrets or customer SQL parameters into a shared document.
Choose the smallest change that satisfies the contract
Keeping client initialization can be the right decision when state differs between callers or the migration cannot yet be tested. Accept and budget for its documented connection behavior while investigating the specific constraint. A proxy-wide default is attractive only when its ownership and scope fit every affected consumer, including jobs and separately deployed services.
For PostgreSQL, supported startup parameters are another option. AWS lists TimeZone among the parameters accepted in the client's startup message through RDS Proxy. Check how the deployed driver sends the value and whether a later callback still issues SQL. This is a separately tested alternative, not an instruction to combine two changes and attribute the result to one.
Changing database or role defaults has a wider authority boundary. It can affect consumers outside this proxy path. Review those consumers and the deployed engine's rules before considering it. Do not change a global default merely to make an isolated candidate pass. Likewise, SQL Server and MySQL-family behavior cannot be inferred from this PostgreSQL example.
Stop on mixed state and rehearse reversal
Stop expansion for a wrong readback, a caller with a conflicting requirement, initialization/setup errors, unexpected permission or target differences, missing negative-control detection, or exceeded workload and cost bounds. If older backends cannot be distinguished from newly initialized ones, hold the transition rather than treating a successful fresh client as fleet acceptance.
Retain the old application initializer, proxy configuration and routing/cohort configuration before the test. The owner should rehearse returning the isolated cohort to that combination, then repeat the original expected-value and error-path checks. Restoring a configuration string alone does not prove that existing pooled state has reverted. A real release needs a planned connection-lifecycle transition in both directions, with controlled draining or replacement only where separately approved.
This reversal does not undo committed writes or external effects. If the test exposes uncertain operation outcomes, stop and use the separately owned connection recovery and reconciliation review. Before replacing many pools, check the fleet connection budget; simultaneous replacement can create a different capacity problem.
Next action: prove one shared setting through the real driver
Select one application path, one genuinely common setting and its accountable database owner. Capture the deployed initializer and reset behavior, then fill the acceptance record for an approved isolated comparison. Start with the baseline and the missing-initialization negative control. Move to a candidate only when those distinguish the intended state reliably. Bring the readbacks, lifecycle gaps and proposed transition to the application owner before scheduling a production change.
Related resources
Why RDS Proxy Is Not Reducing Connections as Expected
Distinguish session pinning, long transactions, backend limits and churn before changing an RDS Proxy workload. Includes engine-aware evidence and a proposed synthetic test.
Local Connection Pools Can Exceed the Database Fleet Budget
Count database connections across processes, replicas and deployment overlap. Separate application pools, proxy backends and query capacity before scaling.
Why Connection Pools Matter During Database Failover
Review RDS failover beyond database availability: stale pooled sessions, interrupted transactions, bounded reconnection and evidence of application recovery.