PostgreSQL prevents HDD from spin-down

linuxpostgresql

I am using my router with OpenWRT as a small server. To experiment a little with more advanced database administration in my programming projects I set up psql on it. The.server uses my HDD, which is attached via USB to the router. This is no high-availability.system,. primarily as a DB connection point inside my private network.

Everything is going alright so far. I just experienced that my hd-idle setup is not working anymore. I highly suspect PostgreSQL to be the reason for that. Since the drive is not really that quiet and it's standing in my living room, I was Keen to spin the HDD down if I didn't use it for an hour. I now register quite some regular I/O on the device and I guess it's logging or similar processes.
Is it possible to reduce the frequency of these helper processes down to maybe once a day?

Best Answer

OpenWRT doesn't provide anything that I know of anyway to spindown hard drives. From the documentation,

Unfortunately there is no solution that works always for everybody. The first option to try is provided by the package hd-idle, which will spin down any disk accessible via the SCSI layer. Install it and test if it can spindown the hard disk (let us assume that your disk is /dev/sda):

The other solution is hdparm -y. So what you're doing is using something to tell your drives when to spin down. The idea is you now either

  1. Script a daemon to monitor for when use stops (such as in the case of unmount),
  2. Periodically tell the hard drive to spin itself down and hope it doesn't wake.

If PostgreSQL wakes the drive up, that's absolutely to be expected. Like any decent database, there is always maintenance to be done, and even when you're not accessing that database it will autovacuum. You may consider

  1. Disabling autovacuum (which will help). But, then you'll have to manually VACUUM. Even disabling autovacuum, I have no idea if the PostgreSQL daemon will wake back up the drive.
  2. Shutting down PostgreSQL before you set the hard drives to spindown.