Postgres database on a separate drive

In psql:

CREATE TABLESPACE mytablespace LOCATION '/Volumes/MyVolume/postgres';
CREATE DATABASE mydatabase TABLESPACE mytablespace;

Kudos to GregHNZ for posting this on StackOverflow.

In macOS (possibly other OSes as well) you can safely unmount the drive without stopping the Postgres process as long as there are no I/O operations running. When you mount the drive again, the database works instantly — again, Postgres doesn’t even need to be restarted. Magic!

This entry was posted in How to’s and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *