HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Seeting up a PostgreSQL database on another hard drive than my system one on OS X?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlthansystemhardseetingdatabaseoneanotherdrive

Problem

I am on OS X 10.8.3, I've install PostgreSQL from macports, but I've realized that I have not enough space on my system drive for the DB I am about to populate with data.

Is there a way to create new database on another drive/partition (not the system one, where postgres is installed)?

How can I do that?

Solution

I very strongly recommend that you do not put a tablespace on an external removable drive. If the tablespaces disappears (ie: drive unplugged) you risk severe database corruption that will be difficult to recover from. You'll likely find permissions management a challenge, too.

You should generally initdb a new database cluster on the drive, then start it with pg_ctl. If you like you can change your launchd properties to auto-start the database (this will require messing with file permissions) or you can just manually start it with pg_ctl when you want to use it.

It may be easier to move the existing data directory to the new location and either create a symlink from the old location to the new one or edit your launchd configuration to tell the PostgreSQL launcher to look in the new location. If your postgresql.conf is outside the data directory you can just change the data_directory parameter in postgresql.conf instead.

See the PostgreSQL user manual for details on initdb and pg_ctl if you need to use them.

For how to set PostgreSQL up to start your new database on boot-up you'll want to do some learning about file permisisons and launchd properties. I don't use OS X much so I can't be of much help with this part; if you're stumped and you've done some reading to try to figure it out, consider asking for help on the OSX stack exchange site. Just remember to explain what you've tried and what you've done already. You won't need to do this if you just symlink it from the old location.

Context

StackExchange Database Administrators Q#41938, answer score: 8

Revisions (0)

No revisions yet.