log_connections - AWS Prescriptive Guidance

log_connections

The log_connections parameter controls whether connections to the database are logged. When you set this parameter to on, the log contains information about each successful connection to the database, such as the client's IP address, the username, the database name, and the date and time of the connection.

You can use the log_connections parameter to monitor and troubleshoot connections to the database. You can see the users, applications, terminals, and bots that connect to the database, where they're connecting from, and how often. This information can be useful for identifying and resolving connection-related issues or tracking usage patterns.

AWS CLI syntax

The following command changes log_connections for a specific DB parameter group. This change applies to all instances or clusters that use the parameter group.

# Modify log_connections on a DB parameter group aws rds modify-db-parameter-group \ --db-parameter-group-name <parameter_group_name> \ --parameters "ParameterName=log_connections,ParameterValue=<new_value>,ApplyMethod=immediate" # Modify log_connections on a DB cluster parameter group aws rds modify-db-cluster-parameter-group \ --db-cluster-parameter-group-name <parameter_group_name> \ --parameters "ParameterName=log_connections,ParameterValue=<new_value>,ApplyMethod=immediate"

Type: Dynamic (changes are applied immediately if you set ApplyMethod=immediate)

Default value: off (PostgreSQL engine default)

Example

You can use this parameter if you suspect that too many connections to the database, or a specific user or IP address that's connecting too frequently, is affecting performance. By enabling the log_connections parameter and examining the log output, you can see the number and details of all connections.

Before you enable this parameter, check your organization's policies and consider the security implications of logging IP addresses and usernames.