Software Crafting

Optimizing SaaS Database Costs: Migrating Multi-Tenant PostgreSQL Workloads to Amazon Aurora Serverless v2

DDeepak RajputCloud and DevOps10 min read06 Apr 2026Updated 2026-11-07
Five glowing cyan and magenta circuit cubes linked by light traces on a dark surface, with the central cube in sharp focus

TL;DR: Migrating an over-provisioned B2B SaaS PostgreSQL database to Amazon Aurora Serverless v2 can cut costs when traffic follows a strong 9-to-5 pattern, because you stop paying for peak capacity around the clock. This guide covers how to validate workload variance with CloudWatch metrics, deploy a highly available cluster with Terraform, choose Aurora Capacity Unit (ACU) limits that keep your working set in the buffer cache, and run the numbers so you know when serverless is the more expensive option.

Key Takeaways

  • Analyze 14-day CPUUtilization metrics via the AWS CLI to validate a high peak-to-trough variance before committing to a serverless migration.
  • Calculate compute needs using Aurora Capacity Units (ACUs), where 1 ACU equates to approximately 2 GB of RAM.
  • Avoid a very low minimum ACU for latency-sensitive workloads: Aurora shrinks shared_buffers as capacity scales down, so cached data is evicted and must be re-read later, and a higher current capacity also scales up faster.
  • Use Terraform's serverlessv2_scaling_configuration to set precise boundaries, such as min_capacity = 2.0 for overnight baseline and max_capacity = 32.0 for morning connection storms.
  • Deploy at least one reader (count = 2 in Terraform) in a separate Availability Zone, in promotion tier 0 or 1 so it scales with the writer, for fast failover.

Running a B2B SaaS application often means paying for database capacity you only use part of the day. Because your users follow business hours, the application sees a traffic spike around 9:00 AM when users log in, run analytical queries, and load their dashboards. By the evening, traffic falls sharply, leaving the database mostly idle until the next morning.

To handle this morning peak, many teams over-provision their Amazon RDS instance, paying 24/7 for a large instance class to cover a few hours of load. If you downsize, the morning spike can exhaust memory, leading to connection timeouts and slow queries. Provisioned RDS does not resize instances automatically: adding read replicas takes minutes, and changing the instance class involves a restart (brief with Multi-AZ, but still a failover).

Amazon Aurora Serverless v2 addresses this by adjusting capacity in place, in fine-grained ACU increments, without dropping connections. Unlike the retired Serverless v1, which paused to find a scaling point, v2 scales while queries run. However, migrating a production multi-tenant workload isn't just about clicking "modify" in the AWS console. You need to manage connection storms, calculate your true baseline capacity, and execute the migration with minimal downtime.

Here is a playbook for migrating a high-traffic SaaS PostgreSQL workload to Aurora Serverless v2.

Analyzing the Multi-Tenant Workload Profile

Before migrating, check with real metrics that your workload is "spiky" enough to benefit. Aurora Serverless v2 charges per Aurora Capacity Unit (ACU) hour. If your database runs at 80% CPU utilization 24/7, migrating to Serverless v2 will likely increase your AWS bill.

To determine if your B2B SaaS fits the serverless model, analyze your existing RDS CloudWatch metrics over a 14-day period to identify the delta between your peak and trough utilization.

You can pull this data programmatically using the AWS CLI to analyze your CPU variance:

aws cloudwatch get-metric-statistics \
  --namespace AWS/RDS \
  --metric-name CPUUtilization \
  --dimensions Name=DBInstanceIdentifier,Value=your-prod-rds-instance \
  --start-time 2026-04-01T00:00:00Z \
  --end-time 2026-04-14T00:00:00Z \
  --period 3600 \
  --statistics Maximum Minimum Average \
  --query 'Datapoints[*].[Timestamp, Maximum, Minimum, Average]' \
  --output table

If the results show a peak CPU of 85% during business hours and an average of 10% overnight and on weekends, your workload is a good candidate. A provisioned instance is sized for the high-water mark all the time, while Serverless v2 follows the usage curve and scales down toward your minimum ACU setting when tenants log off. Also check FreeableMemory, because memory, not CPU, often decides the instance size.

Aurora Serverless v2 Architecture: ACUs and Scaling

Aurora Serverless v2 capacity is measured in ACUs. Each ACU corresponds to approximately 2 GiB of memory, with corresponding CPU and networking. Depending on engine version, the capacity range goes from 0.5 ACUs (or 0 with automatic pause) up to 256 ACUs per instance.

The most important decision is your minimum and maximum ACU limits. AWS documents two reasons not to default to the lowest minimum. First, Aurora adjusts shared_buffers with capacity, so scaling down evicts data from the buffer cache, and after the next scale-up that data is read back from storage over time. Second, the scaling rate depends on current capacity: the higher the current capacity, the faster an instance can scale up. A minimum of 0 enables auto-pause, which saves the most when a cluster is truly idle but adds resume latency to the first connection.

Here is how you provision an Aurora Serverless v2 cluster using Terraform, optimized for a medium-scale SaaS application:

resource "aws_rds_cluster" "saas_aurora_cluster" {
  cluster_identifier      = "prod-multi-tenant-db"
  engine                  = "aurora-postgresql"
  engine_version          = "16.8" # pin a currently supported minor version
  database_name           = "saas_production"
  master_username         = "dbadmin"
  # Let RDS generate and rotate the password in Secrets Manager instead of passing it in
  manage_master_user_password = true
  backup_retention_period = 7
  preferred_backup_window = "02:00-04:00"
  skip_final_snapshot     = false

  serverlessv2_scaling_configuration {
    # 2 ACUs = ~4 GiB memory baseline. Size this to your hot working set.
    min_capacity = 2.0
    # 32 ACUs = ~64 GiB memory max capacity for 9 AM spikes.
    max_capacity = 32.0
  }
}

resource "aws_rds_cluster_instance" "saas_aurora_instances" {
  count               = 2 # One writer, one reader for high availability
  identifier          = "prod-aurora-instance-${count.index}"
  cluster_identifier  = aws_rds_cluster.saas_aurora_cluster.id
  instance_class      = "db.serverless"
  engine              = aws_rds_cluster.saas_aurora_cluster.engine
  engine_version      = aws_rds_cluster.saas_aurora_cluster.engine_version
  publicly_accessible = false
  promotion_tier      = 1 # readers in tier 0 or 1 scale with the writer
}

Production Note: Deploy at least one Serverless v2 reader in a different Availability Zone. Aurora readers share the cluster's storage volume, so if the writer fails, Aurora promotes a reader instead of restoring data. Readers in promotion tier 0 or 1 scale along with the writer, so the promoted reader already has comparable capacity; readers in tiers 2 to 15 scale independently.

Tackling Connection Storms with PgBouncer

Aurora Serverless v2 scales CPU and memory quickly, but it does not change PostgreSQL's architecture. PostgreSQL uses a process-per-connection model: every new connection forks a backend process that consumes memory (typically several megabytes, more with large work_mem usage or many cached relations), whether or not a query is running.

If your multi-tenant application scales out its application servers (e.g., Node.js or Go pods in EKS) during a traffic spike, thousands of simultaneous connection attempts will hit the database. Even if Aurora scales up ACUs, a burst of new connections can consume memory faster than capacity grows, and connection setup itself costs CPU. Note also that max_connections is derived from the maximum ACU setting, and is capped at 2,000 on Aurora PostgreSQL when the minimum is 0 or 0.5 ACUs.

To absorb connection storms, put a connection pooler like PgBouncer (or Amazon RDS Proxy) in transaction mode in front of the database.

Below is an example pgbouncer.ini for a multi-tenant environment. It caps the server connections hitting Aurora while allowing thousands of client connections from your app servers. Transaction pooling breaks session-level features such as SET without LOCAL, advisory session locks and LISTEN, so check your driver and ORM settings before enabling it:

[databases]
# Route tenant traffic to the Aurora cluster endpoint
saas_production = host=prod-multi-tenant-db.cluster-xxx.eu-west-1.rds.amazonaws.com port=5432 dbname=saas_production pool_size=150

[pgbouncer]
listen_addr = 0.0.0.0
listen_port = 6432
# Use SCRAM rather than md5, and require TLS on both sides
auth_type = scram-sha-256
auth_file = /etc/pgbouncer/userlist.txt
client_tls_sslmode = require
client_tls_key_file = /etc/pgbouncer/tls/server.key
client_tls_cert_file = /etc/pgbouncer/tls/server.crt
server_tls_sslmode = verify-full
server_tls_ca_file = /etc/pgbouncer/tls/rds-global-bundle.pem

# Transaction pooling is critical for serverless.
# It assigns a server connection to a client only during an active transaction.
pool_mode = transaction

# Allow the application to open up to 5000 logical connections
max_client_conn = 5000

# Keep the physical connections to Aurora manageable
default_pool_size = 100
max_db_connections = 200

# Close idle server connections after 60 seconds so unused backends release memory
server_idle_timeout = 60

With max_db_connections = 200, this PgBouncer instance opens at most 200 server connections to Aurora (multiply by the number of PgBouncer instances you run, and leave headroom under max_connections). Excess client transactions queue in PgBouncer instead of creating new backends, while ACUs scale to provide CPU for the active transactions.

The Migration Playbook: Provisioned RDS to Aurora Serverless v2

Migrating a terabyte-scale SaaS database from provisioned RDS PostgreSQL to Aurora PostgreSQL requires a minimal-downtime strategy. Because Aurora uses a different, distributed storage layer, you cannot simply change the instance type.

A well-documented approach is an Aurora read replica. AWS lets you create an Aurora cluster that replicates from your existing RDS for PostgreSQL instance using streaming replication, in the same Region and account. Once replication catches up, you stop application writes, promote the Aurora cluster to a standalone cluster, and point PgBouncer at it. AWS notes the initial copy can take several hours per terabyte.

Here is the AWS CLI sequence to initiate the migration:

# Step 1: Create an Aurora Serverless v2 cluster as a replica of your RDS instance.
# --engine-version must equal the source version or be a higher minor in the same major.
# Add --storage-encrypted if the source instance is encrypted.
aws rds create-db-cluster \
  --db-cluster-identifier prod-aurora-migration \
  --db-subnet-group-name your-db-subnet-group \
  --vpc-security-group-ids sg-0123456789abcdef0 \
  --engine aurora-postgresql \
  --engine-version 16.8 \
  --replication-source-identifier arn:aws:rds:eu-west-1:123456789012:db:your-prod-rds-instance \
  --serverless-v2-scaling-configuration MinCapacity=2,MaxCapacity=32

# Step 2: Add a serverless instance to the new cluster to handle replication processing
aws rds create-db-instance \
  --db-instance-identifier prod-aurora-migration-instance \
  --db-cluster-identifier prod-aurora-migration \
  --engine aurora-postgresql \
  --instance-class db.serverless

# Watch RDSToAuroraPostgreSQLReplicaLag in CloudWatch until it is near zero.
# Step 3: During your maintenance window, stop writes, confirm the replica has replayed
# past the source's pg_current_wal_lsn(), then promote:
aws rds promote-read-replica-db-cluster \
  --db-cluster-identifier prod-aurora-migration

After the promotion completes, import the new cluster into Terraform (terraform import or an import block) so it is managed as code, keep the old RDS instance for a short rollback window, and then decommission it. If you would rather have someone run this cutover with you, our DevOps and cloud deployment services cover database migrations.

Cost-Benefit Analysis: When Does Serverless v2 Save Money?

Switching to Aurora Serverless v2 is also a financial decision, so model it before migrating.

At the time of writing, the Aurora pricing page lists Serverless v2 at $0.12 per ACU-hour for Aurora Standard in US East (N. Virginia), and $0.156 for I/O-Optimized. Storage and I/O are billed separately in both cases. Check the pricing page for your region before relying on these numbers.

Because each ACU is about 2 GiB of memory, matching a provisioned db.r6g.4xlarge (128 GiB) takes roughly 64 ACUs, and a db.r6g.xlarge (32 GiB) roughly 16 ACUs. Running 16 ACUs around the clock costs 16 x $0.12 x 730 h = about $1,402/month. Compare that with the on-demand price of the equivalent provisioned instance class in your region: per unit of memory, an always-on serverless instance generally costs more than a provisioned one, so if your workload never scales down, Serverless v2 is usually the more expensive option.

The savings come from hours at low capacity. If your app averages 4 ACUs for 16 hours a day and 16 ACUs for 8 hours a day, the compute cost is ((4 x 16) + (16 x 8)) x 30 x $0.12 = 5,760 ACU-hours x $0.12 = about $691/month, roughly half of the always-on 16 ACU figure, while still allowing bursts to 32 ACUs during unexpected spikes. Whether that beats your current provisioned bill depends on the instance you are replacing and any Reserved Instance discounts you hold, since Serverless v2 has no reserved pricing.

To accurately model this before migrating, run this SQL query on your existing Postgres instance to profile your active session load. This helps you map your current usage to equivalent ACUs:

-- Profile active, idle, and waiting connections over time
SELECT
    state,
    wait_event_type,
    count(*) as total_connections
FROM
    pg_stat_activity
WHERE
    pid <> pg_backend_pid()
    AND datname = 'saas_production'
GROUP BY
    state, wait_event_type
ORDER BY
    total_connections DESC;

Combining this connection profile (sampled at several times of day) with your CPU and memory metrics gives you a reasonable starting point for min_capacity and max_capacity. Expect to tune both after a few weeks of production data.

Monitoring and Fine-Tuning Scale Targets

Once you are in production on Aurora Serverless v2, your operational focus shifts from managing instances to monitoring the ACU scaling behavior.

If your minimum ACU is set too low, you might observe a drop in your BufferCacheHitRatio and elevated ReadIOPS after quiet periods. This happens because scaling down shrinks shared_buffers and evicts cached pages. When the next spike hits, the database reads from storage instead of memory, causing latency spikes even as ACUs scale up.

Set up CloudWatch alarms on ServerlessDatabaseCapacity and ACUUtilization. Here is a Terraform snippet to alert your engineering team via SNS if your cluster consistently hits its maximum capacity, indicating that you need to raise the ceiling:

resource "aws_cloudwatch_metric_alarm" "acu_max_utilization" {
  alarm_name          = "aurora-serverless-max-capacity-reached"
  comparison_operator = "GreaterThanOrEqualToThreshold"
  evaluation_periods  = "2"
  metric_name         = "ServerlessDatabaseCapacity"
  namespace           = "AWS/RDS"
  period              = "300"
  statistic           = "Maximum"

  # Trigger if we hit our max_capacity of 32 ACUs
  threshold           = "32.0"
  alarm_description   = "Aurora cluster has maxed out its ACU limits. App may degrade."

  dimensions = {
    DBClusterIdentifier = aws_rds_cluster.saas_aurora_cluster.id
  }

  alarm_actions = [aws_sns_topic.db_alerts.arn]
}

Aurora Serverless v2 fits B2B SaaS workloads with a strong daily cycle well. It removes the need to pay for peak capacity 24/7 and the work of resizing instances by hand. Combined with PgBouncer for connection control, ACU limits sized to your working set, and CloudWatch alarms on capacity, it gives you a data tier that follows demand. For flat, always-busy workloads, a provisioned instance (ideally reserved) remains the cheaper choice.

Sources

Available for Work

Need help building this in production?

SoftwareCrafting is a full-stack dev agency - we ship fast, scalable React, Next.js, Node.js, React Native & Flutter apps for global clients.

Get a Free Consultation

Frequently Asked Questions

How do I know if my PostgreSQL workload will actually save money on Aurora Serverless v2?

Aurora Serverless v2 is cost-effective primarily for "spiky" workloads, such as B2B SaaS applications with distinct 9-to-5 traffic peaks. If your database runs at a consistently high CPU utilization (e.g., 80%) 24/7, migrating to Serverless v2 will likely increase your AWS bill. You should analyze your CloudWatch metrics to ensure there is a significant delta between peak and trough usage before migrating.

Does Aurora Serverless v2 suffer from cold starts or scaling downtime?

Unlike the retired v1, Aurora Serverless v2 scales compute capacity in place while queries run, without dropping connections or requiring a reboot. The exception is a minimum capacity of 0 ACUs: an auto-paused instance must resume before serving the first connection, which adds noticeable latency. Scaling up is also faster from a higher current capacity, so very low minimums respond more slowly to sudden spikes.

Why shouldn't I set my minimum Aurora Capacity Units (ACUs) to 0.5 to maximize savings?

Aurora shrinks shared_buffers as an instance scales down, so a very low minimum evicts cached data that must be read back from storage when traffic returns, and low-capacity instances also scale up more slowly. Set a baseline (like 2 ACUs or more) whose memory holds your frequently accessed data. A minimum of 0.5 or 0 also caps max_connections at 2,000 on Aurora PostgreSQL.

How do I ensure high availability when using Aurora Serverless v2?

Deploy at least one Serverless v2 reader in a different Availability Zone, in promotion tier 0 or 1 so it scales with the writer. Because Aurora readers share the cluster's storage volume, Aurora can promote a reader to writer quickly if the writer fails, without restoring data.

About the author

Deepak Rajput

Founder and CEO of SoftwareCrafting

Deepak Rajput is the Founder and CEO of SoftwareCrafting in Delhi and writes about web, mobile, backend, cloud, security, and engineering leadership.

Writes about Next.js, Node.js, React Native, PostgreSQL, AWS, Kubernetes.

View author profile

Last updated: 2026-11-07