PostgreSQL 9.3 – Server Integrity After Losing a Tablespace

postgresqlpostgresql-9.3tablespaces

I'm running a PostgreSQL server with 2 tablespaces: 'ssd' and 'hdd'. The first contains databases that need to be queried quickly, and is located on a single SSD that is not redundant in any way (no RAID). I don't care if I lose these databases to a disk failure. By contrast, the 'hdd' tablespace is located on a RAID array and contains critical databases that need to survive a disk failure.

Question: if my SSD fails and PostgreSQL loses the 'ssd' tablespace completely (or it becomes corrupt/unstable), will databases in 'hdd' continue functioning normally? Or will the entire server experience issues?

Best Answer

I can't describe this better than the manual does

Warning

Even though located outside the main PostgreSQL data directory, tablespaces are an integral part of the database cluster and cannot be treated as an autonomous collection of data files. They are dependent on metadata contained in the main data directory, and therefore cannot be attached to a different database cluster or backed up individually. Similarly, if you lose a tablespace (file deletion, disk failure, etc), the database cluster might become unreadable or unable to start. Placing a tablespace on a temporary file system like a RAM disk risks the reliability of the entire cluster.

Or this blog post

You can’t just throw a tablespace away and have the rest of the database system keep on working.

Most importantly, the write-ahead log (WAL) that provides PostgreSQL’s crash safety is stored in pg_xlog, and is shared across all tablespaces. PostgreSQL expects to be able to replay this log in order and without errors after a crash or shutdown. Until the log has replayed, the database is assumed to be in an unsafe state and connections will be refused