Sub topic 11
Tuning with Parameter Groups
This chapter assumes you can run AWS CLI commands, you know what a PostgreSQL or MySQL configuration setting is, and you have an RDS instance like demo-pg from the earlier provisioning chapter.
What a parameter group is
On a self-managed server you edit postgresql.conf or my.cnf. RDS gives you no shell on the host, so you can't edit those files. Instead you change engine settings through a parameter group, a named set of engine configuration values that you attach to one or more DB instances.
Every instance has exactly one DB parameter group. If you don't pick one at creation, RDS attaches the default parameter group for your engine and version, such as default.postgres16. You can't change a default group. To change any setting you must create a custom parameter group and attach it to the instance.
A parameter group belongs to a family, such as postgres16 or mysql8.0. The family fixes which parameters exist, so a group can only be attached to instances running a matching engine and major version.
Dynamic and static parameters
Each parameter is either dynamic or static. This determines when a change takes effect.
| Type | Takes effect | Reboot needed |
|---|---|---|
| Dynamic | Immediately, or at the next opportunity the engine allows | No |
| Static | Only after the instance reboots | Yes |
In the CLI and API, the ApplyMethod field controls this:
immediateapplies a dynamic parameter right away. RDS rejects it for static parameters.pending-rebootstores the value and applies it at the next reboot. It works for both types.
Check the type before you plan a change. In describe-db-parameters, the ApplyType field is dynamic or static, and IsModifiable tells you whether you can change it at all.
aws rds describe-db-parameters \
--db-parameter-group-name default.postgres16 \
--query "Parameters[?ParameterName=='log_min_duration_statement'||ParameterName=='shared_buffers'].[ParameterName,ApplyType,IsModifiable,DataType,AllowedValues]" \
--output tableYou should see log_min_duration_statement listed as dynamic and shared_buffers as static.
Creating and editing a custom group
Create the group with the family that matches your instance. Then set a dynamic parameter that logs statements slower than 500 ms.
aws rds create-db-parameter-group \
--db-parameter-group-name demo-pg16 \
--db-parameter-group-family postgres16 \
--description "Custom parameters for demo-pg"
aws rds modify-db-parameter-group \
--db-parameter-group-name demo-pg16 \
--parameters "ParameterName=log_min_duration_statement,ParameterValue=500,ApplyMethod=immediate"Creating the group doesn't change any instance. The group does nothing until you attach it.
Attaching the group to an instance
Use modify-db-instance to attach the group.
aws rds modify-db-instance \
--db-instance-identifier demo-pg \
--db-parameter-group-name demo-pg16 \
--apply-immediatelyAttaching a new group is itself a pending change. The instance's parameter group status shows pending-reboot until you reboot it, even if every parameter in the group is dynamic. Reboot once after the first attachment:
aws rds reboot-db-instance --db-instance-identifier demo-pgAfter that, dynamic changes made inside demo-pg16 apply without a reboot. You can confirm the state with the following Python script.
import boto3
rds = boto3.client("rds")
instance = rds.describe_db_instances(DBInstanceIdentifier="demo-pg")["DBInstances"][0]
for group in instance["DBParameterGroups"]:
print(group["DBParameterGroupName"], group["ParameterApplyStatus"])The status is in-sync when the instance runs with the group's current values. It is pending-reboot when static changes or a newly attached group are waiting for a restart.
Common parameters to tune
The useful parameters depend on the engine. These are typical starting points for PostgreSQL.
| Parameter | Type | Purpose |
|---|---|---|
| `log_min_duration_statement` | Dynamic | Logs statements slower than the given milliseconds |
| `log_connections` | Dynamic | Logs each new connection |
| `work_mem` | Dynamic | Memory per sort or hash operation |
| `max_connections` | Static | Upper limit on client connections |
| `shared_preload_libraries` | Static | Loads extensions such as `pg_stat_statements` |
| `rds.force_ssl` | Dynamic | Rejects unencrypted client connections |
For MySQL and MariaDB, comparable settings include slow_query_log, long_query_time, max_connections, and innodb_buffer_pool_size.
Formulas and defaults
Many RDS defaults are formulas based on instance memory, not fixed numbers. For example, the default max_connections in PostgreSQL is derived from the instance class's memory, shown in the console as something like LEAST({DBInstanceClassMemory/9531392},5000). If you scale the instance to a larger class, the default value scales with it. If you override it with a fixed number, it stays at that number after a resize.
Prefer leaving memory-derived parameters at their defaults until a measurement shows a problem. Raising work_mem is a common mistake. PostgreSQL allocates it per sort or hash operation, and one query can run several, so a large value multiplied by many connections can exhaust memory.
Validation and invalid values
RDS checks parameter values against the allowed range when you call modify-db-parameter-group. It does not always catch settings that are valid in range but incompatible with each other or with your workload.
A static parameter with a bad combination of values can stop the engine from starting after a reboot. In that case the instance enters the incompatible-parameters status. To recover, set the parameter back to a working value (or reset it to its default), then reboot again. Test static changes on a restored copy of the instance before applying them to production.
You can reset a parameter to its default with reset-db-parameter-group:
aws rds reset-db-parameter-group \
--db-parameter-group-name demo-pg16 \
--parameters "ParameterName=log_min_duration_statement,ApplyMethod=immediate"Passing --reset-all-parameters instead of --parameters resets every parameter in the group.
Sharing and managing groups
Several points affect how you organize groups across an account:
- One group can serve many instances. A change to the group affects all of them, so a shared group widens the blast radius of a mistake.
- Create separate groups per environment (for example
app-prod-pg16andapp-test-pg16) so that testing a setting doesn't touch production. - A group can't be deleted while an instance uses it.
- Copy a group with
copy-db-parameter-groupto start a new variant from a known good one. - Changing the engine's major version requires a group from the new family. You create it and attach it as part of the upgrade, which the maintenance chapter covers.
- Read replicas use their own parameter group setting. Some parameters, such as
max_connectionsin some engines, must be at least as large on a replica as on its source, so keep them aligned.
Multi-AZ deployments don't need a separate group. The standby uses the same group as the primary.
Comparing the group with what the engine is using
The parameter group states what you asked for. To see what the engine actually uses, query the engine:
SHOW log_min_duration_statement;
SHOW max_connections;If the two disagree, check ParameterApplyStatus first. A pending-reboot status explains most mismatches.
Quick checklist
- Create a custom group in the correct family.
- Check each parameter's
ApplyTypebefore choosingApplyMethod. - Attach the group and reboot once.
- Change dynamic parameters freely, and schedule reboots for static ones.
- Test risky static changes on a restored copy first.
- Keep production and test groups separate.
Exercise
You changed max_connections in your custom parameter group with ApplyMethod=pending-reboot. An hour later, SHOW max_connections; still returns the old value. What is the most likely cause, and what do you do?
Show answer
max_connections is a static parameter, so the new value only takes effect after a reboot. The instance's parameter group status shows pending-reboot. Schedule a reboot with aws rds reboot-db-instance, then run SHOW max_connections; again to confirm the new value.
Exercise
A teammate wants one parameter group shared by the production and test databases to keep things simple. Give one reason this is risky and one safer approach.
Show answer
A change to the shared group applies to every attached instance, so an experimental setting or a reboot-requiring change meant for testing can reach production. Create separate groups per environment, such as app-test-pg16 and app-prod-pg16, and promote a change to production only after it works in test.