---
title: "Autoscaling in Action: Postgres Load Testing with pgbench"
description: "A pgbench load test against Neon serverless Postgres runs a CPU-heavy query, SELECT log(factorial(32000)) / log(factorial(20000)), to trigger autoscaling."
url: "https://swe.quest/articles/autoscaling-in-action-postgres-load-testing-with-pgbench-9e7339241ec6e0af"
canonical: "https://neon.com/blog/autoscaling-in-action-postgres-load-testing-with-pgbench"
source: "Neon"
published: "2024-02-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["postgres","capacity-planning","performance","serverless"]
---

# Autoscaling in Action: Postgres Load Testing with pgbench

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-02-23, 5 min read, How-to. Original: [https://neon.com/blog/autoscaling-in-action-postgres-load-testing-with-pgbench](https://neon.com/blog/autoscaling-in-action-postgres-load-testing-with-pgbench)

## Summary

A pgbench load test against Neon serverless Postgres runs a CPU-heavy query, SELECT log(factorial(32000)) / log(factorial(20000)), to trigger autoscaling. On ¼ vCPU the query spends about 1.9 s in planning, because constant folding happens there, so a modest number of concurrent clients is enough to make the compute scale within a ¼–7 CU range. The walkthrough covers the pgbench flags (-f, -c, -T, -P), reading EXPLAIN ANALYZE output and interpreting the results: roughly 6 s average latency, about 5 TPS and a high latency standard deviation.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Capacity planning](https://swe.quest/tags/capacity-planning.md) (Reliability & operations)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- command-line tools

## Keywords

Neon, pgbench, EXPLAIN ANALYZE, autoscaling

## Related posts

- [Dynamically estimating and scaling Postgres’ working set size](https://swe.quest/articles/dynamically-estimating-and-scaling-postgres-working-set-size-9625ea29ef0bf2ef.md): Neon · 2024-09-05 · Medium · 12 min read · PostgreSQL, Algorithms, Capacity planning, Caching, Serverless
  Neon autoscales Postgres compute to keep the workload's working set in memory, using a modified HyperLogLog whose register bits are replaced with timestamps so the number of distinct pages accessed can be estimated for any lookback window.
- [Autoscaling Lakebase Postgres](https://swe.quest/articles/autoscaling-lakebase-postgres-63257ef0753db067.md): Neon · 2026-08-31 · Hard · 12 min read · PostgreSQL, Capacity planning, Virtualization, Algorithms, Kubernetes
  Neon's Lakebase Postgres resizes compute in place about once every 81 seconds by taking the maximum of three target sizes: CPU load (one-minute average kept under 90%), memory (polled every 100 ms by an in-VM monitor and kept under 75%), and the working set of the compute cache.
- [Performance tips for Neon Postgres](https://swe.quest/articles/performance-tips-for-neon-postgres-9739985c47432424.md): Neon · 2024-04-04 · Medium · 8 min read · PostgreSQL, Performance engineering, Serverless, SQL
  Neon's serverless Postgres follows mostly standard Postgres tuning, plus a few Neon-specific checks.
- [PostgresBench: A Reproducible Benchmark for Postgres Services](https://swe.quest/articles/postgresbench-a-reproducible-benchmark-for-postgres-services-3a30213211ea6b71.md): ClickHouse · 2026-04-02 · Medium · 9 min read · PostgreSQL, Performance engineering, Storage systems, Cloud platforms
  PostgresBench is an open, reproducible benchmark for managed Postgres services built on pgbench's TPC-B-like workload (256 clients, 16 threads, 10-minute runs, three runs each) at ~100 GB and ~500 GB scale factors, with default configs, HA disabled and all services in us-east-2.
- [Scaling serverless Postgres: How we implement autoscaling](https://swe.quest/articles/scaling-serverless-postgres-how-we-implement-autoscaling-6cecd10b4a114371.md): Neon · 2023-03-29 · Medium · 9 min read · PostgreSQL, Serverless, Kubernetes, Virtualization, Capacity planning
  Neon autoscales serverless Postgres by running each compute endpoint in a QEMU/KVM VM on Kubernetes (via its NeonVM controller) and hot-adding or removing CPU and memory based on load average.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
