- Newest
- Most votes
- Most comments
To minimize session pinning when using RDS Proxy with a Glue connection to an Aurora PostgreSQL database, there are several strategies you can employ:
-
JDBC Connection Parameters: When using PostgreSQL with JDBC, set two important connection parameters to avoid pinning:
- Set
assumeMinServerVersionto at least '9.0'. This prevents an extra round trip during connection startup for setting extra_float_digits. - Set
ApplicationNameto 'any/your-application-name'. This avoids an extra round trip for setting the application name.
- Set
-
Consistent Variable Settings: Ensure that variables and configuration settings are consistent across all connections. This increases the likelihood of connection reuse.
-
Avoid Unnecessary Database Requests: Minimize database operations that might trigger pinning, such as setting session-specific variables or using certain PostgreSQL-specific features.
-
Monitor Pinning: Keep track of pinning frequency using the Amazon CloudWatch metric
DatabaseConnectionsCurrentlySessionPinned. This can help you identify when pinning occurs and adjust your strategy accordingly. -
Connection Pool Configuration: While you've already set some connection pool configurations, consider adjusting the following:
- Increase
max_idle_connections_percentif possible, to allow more connections to remain available for reuse. - Set an appropriate
init_queryif there are any session-level configurations that all connections should have.
- Increase
-
Glue Job Configuration: In your Glue job, when writing to PostgreSQL, try to minimize the number of separate write operations. Batch writes where possible to reduce the number of individual connections needed.
-
Extended Query Protocol: Since you're using a recent JDBC driver (42.7.3) with Glue 5, you're likely already benefiting from the Extended Query Protocol support. This should help with multiplexing for PostgreSQL, but it's not a silver bullet for all pinning scenarios.
-
Review Application Logic: Examine your Glue job to see if there are any operations that might be causing unnecessary session state changes. For example, avoid setting session-level variables if possible.
Remember that while these strategies can help reduce pinning, some level of pinning may still occur due to the nature of PostgreSQL and certain operations that require session-specific states. Continue monitoring your CloudWatch metrics and RDS Proxy logs to fine-tune your approach based on your specific workload characteristics.
Sources
Avoiding pinning an RDS Proxy - Amazon Relational Database Service
Connecting to a database through RDS Proxy - Amazon Aurora
Connecting to a database through RDS Proxy - Amazon Relational Database Service
answered 2 years ago
I tried updating the URL to include parameters assumeMinServerVersion and ApplicationName but still the sessions are getting pinned with this log message
If this prepared statement runs, the client session will be pinned to the database connection [dbConnection=25...]. Reason: SQL changed session settings that the proxy doesn't track. Consider moving session configuration to the proxy's initialization query. Digest: "set session characteristics as transaction isolation level $1 uncommitted".
answered 2 years ago
For PostgreSQL, the following interactions also cause pinning:
- Using SET commands.
- Using PREPARE, DISCARD, DEALLOCATE, or EXECUTE commands to manage prepared statements.
- Creating temporary sequences, tables, or views.
- Declaring cursors.
- Discarding the session state.
- Listening on a notification channel.
- Loading a library module such as auto_explain.
- Manipulating sequences using functions such as nextval and setval.
- Interacting with locks using functions such as pg_advisory_lock and pg_try_advisory_lock.
Using prepared statements will cause pinning.
To avoid pinning, you will have to turn off prepared statements.
answered 2 years ago
Hi @rePost-User-1308834! I appreciate your guidance.
I added &prepareThreshold=0 in the connection URL, but still the number of DatabaseConnectionsCurrentlySessionPinned and DatabaseConnectionsCurrentlyBorrowed is exactly the same when the glue job runs.
The glue job is using Glue 5, and glueContext.write_dynamic_frame.from_options method to write to a table in RDS.
I am not sure which inherited library in Glue 5 is making the listed interactions you mentioned.
Could you please guide me how to fix this?
answered 2 years ago
Relevant content
asked 2 years ago
