Postgresql – Filesystem tuning for PostgreSQL

linuxperformancepostgresqlpostgresql-performanceUbuntu

I want to install PostgreSQL 9.x version in an Ubuntu 14.04 workstation and I'm looking for a recommendation on how to set it up in order to

  • get a good read-write (50/50-balance) performance

  • keep a decent performance for overall conventional system usage.

My idea is to have two main partitions in an SSD drive:

  • [A] an ext4 for the root system ("/") with OS recommended/default settings.

  • [B] an ext4 for postgres database files ("/var/lib/pgsql") with a large block size (eg. 1MB) and a large readahead size (how much?) and proper flags (which?).

I have no clue whether separating postgres db files from general system is a good idea. In such a case, any piece of advice on [B] block size, readahead size, filesystem flags?

Furthermore any helpful hint?

Best Answer

Since you're on SSD you're better of disabling readahead. Seek time is not an issue for flash based drives. That's for the spinning era. It's more important to align the filesystem properly.

Postgresql is using 8k pages so best performance generally comes with matching blocksize.

With XFS use nobarrier and make the filesystem with proper agcount and logging. (https://serverfault.com/questions/222305/trying-to-determine-the-correct-number-of-xfs-allocation-groups-for-postgresql-s).

You can also benefit from having compressed file system like ZFS especially if your data cannot fit in cache and has to be read from disk. Usually I get 2-4x for databases which results in 2-4 times less blocks read from disk but that's very use case dependant. If you use ZFS use recordsize=8k, compression=lz4, primarycache=all and check if you need to set ashift for the particular disk (if it is using 512 byte or 4k blocks by running cat /sys/block/[device]/queue/physical_block_size). http://zfsonlinux.org/faq.html#PerformanceConsideration