This repository contains the implementation, experimental results, and analysis for a DBMS research project investigating whether Bayesian Optimisation (BO) can identify PostgreSQL configurations that outperform a specified baseline.
The study compares three approaches:
- A fixed PostgreSQL baseline configuration.
- Grid search over selected memory parameters.
- Gaussian Process-based Bayesian Optimisation using Expected Improvement.
Experiments were conducted using PostgreSQL 18.7 and the built-in pgbench benchmark on Windows 11.
Research question: Can Bayesian Optimisation discover PostgreSQL configurations that deliver higher transaction throughput than a fixed baseline and conventional grid search?
The study evaluates:
- Transaction throughput (TPS).
- Average transaction latency.
- Performance improvements relative to the baseline.
- Bayesian Optimisation convergence.
- Variability and stability of benchmark measurements.
The objective is to investigate the effectiveness of automated database configuration tuning while documenting experimental limitations.
| Component | Specification |
|---|---|
| Operating system | Windows 11 |
| Database | PostgreSQL 18.7 |
| Benchmark | pgbench 18.7 |
| Programming language | Python |
| Optimisation model | Gaussian Process |
| Acquisition function | Expected Improvement |
| Machine | Lenovo LOQ |
| Processor | Intel Core i5-13450HX |
| RAM | 24 GB |
| Storage | SSD |
| Benchmark scale | 30 |
| Clients | 8 |
| Threads | 1 |
| Measured duration | 20 seconds |
| Warmup duration | 5 seconds |
The benchmark uses pgbench's built-in TPC-B-like transaction workload.
The benchmark database was initialised with approximately 3 million accounts.
Five PostgreSQL parameters were included in the Bayesian Optimisation search space:
| Parameter | Description |
|---|---|
shared_buffers |
Memory allocated to PostgreSQL's shared buffer cache |
work_mem |
Memory available for individual query operations |
max_wal_size |
WAL size threshold influencing checkpoint frequency |
wal_buffers |
Shared memory used for WAL buffering |
checkpoint_completion_target |
Target fraction of the checkpoint interval used to spread checkpoint I/O |
The baseline configuration was:
| Parameter | Baseline value |
|---|---|
shared_buffers |
128 MB |
work_mem |
4 MB |
max_wal_size |
1 GB |
wal_buffers |
4 MB |
checkpoint_completion_target |
0.9 |
synchronous_commit |
on |
Important: This is the explicitly configured experimental baseline, not necessarily the unmodified default configuration of PostgreSQL 18.7.
The baseline configuration was evaluated five times.
Each measurement used:
- 8 clients.
- 1 benchmark thread.
- 5 seconds of warmup.
- 20 seconds of measured execution.
The baseline mean and sample standard deviation were calculated from the five throughput measurements.
Grid search evaluated nine configurations using:
shared_buffers:
- 128 MB
- 256 MB
- 512 MB
work_mem:
- 4 MB
- 16 MB
- 64 MB
The remaining parameters were held at their baseline values.
Each grid-search configuration was evaluated once.
Bayesian Optimisation used a Gaussian Process surrogate model and an Expected Improvement acquisition function.
The optimiser evaluated 25 configurations.
Each candidate was applied to PostgreSQL and evaluated using pgbench.
The highest observed throughput was retained as the best configuration.
The initial search included randomly sampled configurations, followed by model-guided candidate selection.
The original experiments exhibited substantial performance variability.
Later BO trials experienced a pronounced throughput decline, and subsequent baseline checks also produced lower throughput than the original baseline measurements.
Consequently, the highest observed BO throughput cannot be interpreted as a statistically validated improvement.
Independent validation and supplementary experiments were not completed.
| Trial | Throughput (TPS) |
|---|---|
| 1 | 4151.34 |
| 2 | 4964.64 |
| 3 | 5086.24 |
| 4 | 4858.95 |
| 5 | 4533.72 |
Baseline mean: 4718.98 TPS
Sample standard deviation: 377.94 TPS
| shared_buffers | work_mem = 4 MB | work_mem = 16 MB | work_mem = 64 MB |
|---|---|---|---|
| 128 MB | 4304.84 | 3658.87 | 4640.93 |
| 256 MB | 4828.77 | 4623.13 | 4900.11 |
| 512 MB | 4789.30 | 4878.36 | 4880.82 |
The best grid-search configuration was:
shared_buffers = 256MBwork_mem = 64MB
Best observed throughput: 4900.11 TPS.
The highest observed BO throughput occurred during trial 11.
| Parameter | Value |
|---|---|
shared_buffers |
1009 MB |
work_mem |
7 MB |
max_wal_size |
3143 MB |
wal_buffers |
11 MB |
checkpoint_completion_target |
0.7619 |
Best observed throughput: 5246.90 TPS.
| Method | Throughput (TPS) | Difference relative to baseline mean |
|---|---|---|
| Baseline mean | 4718.98 | — |
| Best grid-search observation | 4900.11 | +3.84% |
| Best BO observation | 5246.90 | +11.19% |
The best BO observation was approximately 7.08% higher than the best grid-search observation.
These percentages describe observed differences. They do not establish statistically significant improvements.
The repository includes:
Bayesian Optimisation Convergence
figures/bo.pdf
figures/bo.png
This figure displays:
- Individual BO trial throughput.
- Best-observed throughput so far.
- Baseline mean throughput.
Grid Search Heatmap
figures/grid.pdf
figures/grid.png
This figure visualises throughput across the nine grid-search configurations.
bayesian_opt/
├── figures/
│ ├── bo.pdf
│ ├── bo.png
│ ├── grid.pdf
│ └── grid.png
│
├── results/
│ ├── baseline.json
│ ├── grid.json
│ ├── bo.json
│ ├── smoke.json
│ ├── summary.json
│ └── tables.txt
│
├── analyze.py
├── db_connection.py
├── tune.py
├── supp.py
├── verify_results.py
├── requirements.txt
├── README.md
├── FINAL_VERIFICATION.md
└── .gitignore
The smoke.json file contains a preliminary functionality test and must not be included in the formal experimental analysis.
- Python
- PostgreSQL 18
- PostgreSQL command-line utilities
- pip
- PowerShell
- Administrator privileges for PostgreSQL service restarts
Clone the repository:
git clone <YOUR_REPOSITORY_URL>
cd bayesian_optCreate a virtual environment:
python -m venv .venvActivate it:
.\.venv\Scripts\Activate.ps1Install dependencies:
pip install -r requirements.txtEnsure the PostgreSQL binaries are available:
$env:Path = "C:\Program Files\PostgreSQL\18\bin;$env:Path"Do not hardcode database passwords in Python scripts or commit credentials to GitHub.
For local execution:
$env:PGPASSWORD = Read-Host "Enter PostgreSQL password"Connection settings can be supplied using a PostgreSQL DSN:
$D = "dbname=testdb user=postgres host=localhost port=5432"WARNING: Use only a dedicated, disposable PostgreSQL instance.
The tuning scripts execute PostgreSQL configuration commands, including:
ALTER SYSTEM RESET ALL;This resets settings stored in postgresql.auto.conf.
The scripts also restart PostgreSQL and may overwrite custom server configuration.
Back up the PostgreSQL configuration before running any experiment.
Example configuration:
$D = "dbname=testdb user=postgres host=localhost port=5432"
$P = "pgbench -h localhost -U postgres testdb"
$R = "net stop postgresql-x64-18 && net start postgresql-x64-18"Run the baseline experiment:
python tune.py --dsn "$D" --pgbench "$P" --restart-cmd "$R" --mode baseline --duration 20 --warmup 5 --clients 8 --jobs 1 --repeats 5 --output results/baseline.jsonRun grid search:
python tune.py --dsn "$D" --pgbench "$P" --restart-cmd "$R" --mode grid --duration 20 --warmup 5 --clients 8 --jobs 1 --output results/grid.jsonRun Bayesian Optimisation:
python tune.py --dsn "$D" --pgbench "$P" --restart-cmd "$R" --mode bo --trials 25 --n-random 5 --duration 20 --warmup 5 --clients 8 --jobs 1 --seed 42 --output results/bo.jsonThese commands are provided for reproducibility. Running them again is not necessary to inspect the existing results.
To regenerate the analysis from the existing experimental data:
python analyze.py --baseline results/baseline.json --grid results/grid.json --bo results/bo.jsonThe analysis script generates summary statistics, tables, and figures.
The main output files are:
results/summary.json
results/tables.txt
figures/bo.pdf
figures/bo.png
figures/grid.pdf
figures/grid.png
The repository contains:
verify_results.py
This script checks the expected experimental evidence and generated outputs.
The original verification workflow expects additional validation and supplementary results.
Because those experiments were not completed, the full verification audit may report missing files.
Do not interpret a missing-file failure as evidence that the completed baseline, grid-search, or BO results are invalid.
The study has several limitations:
- Experiments were conducted on a single Windows laptop.
- The benchmark used one workload and one client-concurrency level.
- Grid-search and BO candidate configurations were evaluated only once.
- Throughput varied substantially during the experiment.
- Independent validation was not completed.
- No statistically supported claim of BO superiority can be made.
- Results may differ across PostgreSQL versions, workloads, hardware, and operating systems.
Bayesian Optimisation identified the highest single-trial throughput among the configurations tested.
The best BO observation reached 5246.90 TPS, compared with a baseline mean of 4718.98 TPS and a best grid-search observation of 4900.11 TPS.
However, substantial benchmark variability prevents these results from establishing a reliable performance advantage.
The experiment demonstrates both the potential of automated PostgreSQL configuration tuning and the importance of reproducible benchmarking, repeated validation, and controlling system-level variability.
This repository accompanies a DBMS research study on PostgreSQL configuration tuning.
Experimental results are provided for academic analysis and reproducibility.
No benchmark values should be interpreted as independently validated performance improvements unless supported by additional controlled experiments.