In step 5, we have installed PostgreSQL. We then performed some benchmarks, by following tips and tricks contained in the world famous book about “PostgreSQL High Performance” by our dear Gregory Smith.
Results will be now presented, to test the efficiency of a PostgreSQL database server installed on a Raspberry PI. This represents a good challenge: build up a database server in a cheap way! Let’s not forget our goal: be able to adopt Postgres in schools so that the SQL language can be taught!
Obviously performances of a good server with a multicore CPU, having more than 32GB RAM and supported by one of the latest high performance storage units cannot be reached in our example. Anyway, we’ll show how some typical database servers operations can be reproduced in reduced scale also in a Raspberry PI with PostgreSQL.
To better understand the results, we need to know the hardware configuration at our disposal:
- CPU: ARMv6-compatible processor rev 7 (v6l), 700MHz, single core
- RAM: 512MB
- SD card speed class 10 (30MB/s)
- Operating system: Raspbian (Debian wheezy 7.0)
- PostgreSQL version: 9.2 (the one used at the time of the benchmark)
Useful tools used for the benchmark
The benchmark foresees the measurement of I/O rate of the storage device, filesystem speed and database transactions rate. This last was checked using the
pgbench tool. Pgbench submits queries as test and measures transactions rate for different DML commands and client configurations and which was yet installed with PostgreSQL.
For the benchmark of the storage unit and of the operative system we used the
bonnie++ tool. On Raspbian can be easily installed such as in a Debian distribution.
The access rate of memory streams, known also as “stream scaling”, has been tested using a
bash script and
C libraries developed by the department of computer science of the University of Virginia and published in their web page.
Benchmarks were executed tweaking operative system settings, like read-ahead and file system, to test performances and find the best system configuration. For this purpose, we used the
fabric library creating
Python scripts to be launched from remote hosts.
SD card read speed
This benchmark is made measuring the “zcav” that is the measurement of read speed as a function of the data position in the read device. This is possible with the
zcav tool, installed by default with the
Above picture summarizes the obtained results for the SD card zcav: constant behaviour is expected being a digital device and not a disk. More interesting the found speed value: 22.5 MB/s, to be compared with what producer declared (30 MB/s).
IO rate and filesystem speed
bonnie++ we have measured the sequential W/R speeds and seek rates, varying filesystem (
ext4) and read-ahead (
The filesystem with the highest performances resulted the
ext4 (sequential read in this case reach more than 26 MB/s). Best configuration includes also 4096 as read-ahead value, although performances did not seem to change modifying this parameter.
Usually, once the best configuration is set, stream scaling is measured varying the concurrency by the
bash script mentioned above. In the Raspberry PI case, this can be made only referring to the CPU single core. The results of the benchmark showed a CPU access to memory speed equal to 282 MB/s, which is not a bad result considering that Raspberry PI has 512MB RAM.
PostgreSQL performances on Raspberry PI
This benchmark consists of two tests:
- creating a small size database (155MB of data), able to be contained totally in RAM
- creating a large size database (1920MB of data), about four time the size of available RAM (to be sure that it will not be totally contained only in RAM)
For each database,
TPC-B like test are executed, measuring the commit rate. Moreover, multi-client commits can be checked using
pgbench launching it from a remote multi-core machine (we used a quad-core CPU with enabled hyperthread, so a total of 8 clients can be reached).
The following tables summarize the obtained results:
small size database benchmark results
|INSERT (single client)||22|
|INSERT (multi client)||33|
|SELECT (multi client)||412|
large size database benchmark results
|SELECT (multi client)||197|
We could not reach performances of a real server, anyway just with a raspberry PI we were able to do typical database server operation, multiclient connections included!
 Be sure
gcc compiler is installed:
apt-get install gcc.
 Concurrency could not be changed because of the single core Raspberry PI CPU.
 see www.tpc.org/tpcb/
Raspberry PI has 512MB RAM