Skip to main content
This example provisions a production-ready PostgreSQL 17 RDS instance including VPC, security groups, parameter group, CloudWatch log groups, enhanced monitoring, and cross-region automated backup replication. A second db_default instance using AWS-managed groups is also included.
Option groups are not supported for PostgreSQL. The module automatically skips option group creation when the engine is postgres. Any value set for option_group_name will be ignored.
Enable performance_insights_enabled = true for PostgreSQL instances in production. Performance Insights provides query-level diagnostics that are especially valuable for identifying slow queries, lock contention, and wait event bottlenecks. The 7-day retention tier is free.

Configuration

main.tf

PostgreSQL-specific configuration

No option groups

PostgreSQL on RDS does not support option groups. The module skips option group creation entirely when engine = "postgres", regardless of what is set for create_db_option_group or option_group_name.

Log exports

PostgreSQL supports two CloudWatch log export types: These differ from MySQL which uses general, slowquery, audit, and error log types.

Parameter group configuration

The example sets two parameters:
  • autovacuum = 1 — ensures autovacuum is enabled (it is on by default, but making it explicit prevents accidental disabling)
  • client_encoding = utf8 — sets the client-side character encoding

Reserved usernames

Do not use user as the value for username. PostgreSQL reserves this word and RDS will return an InvalidParameterValue error. Other reserved words include rdsadmin, rds_superuser, and postgres (for some versions).

Managed password rotation

The example configures Secrets Manager to rotate the master user password on a 15-day schedule using manage_master_user_password_rotation = true with master_user_password_rotation_schedule_expression = "rate(15 days)". Setting master_user_password_rotate_immediately = false prevents an immediate rotation on first apply.

Automated backup replication

The example uses the db_instance_automated_backups_replication submodule to replicate automated backups to eu-central-1. A KMS key is created in the target region to encrypt the replicated backups.

Engine lifecycle support

engine_lifecycle_support = "open-source-rds-extended-support-disabled" opts out of RDS Extended Support (which incurs additional charges for end-of-life engine versions). This is appropriate for PostgreSQL 17, which is current. Remove this setting or use "open-source-rds-extended-support" if you need extended support for older engine versions.

Outputs