Moving PostgreSQL and MySQL data off a Mac's internal SSD: stop, copy, point, verify

By the Zofle team · 12 November 2026 · 5 min read

PostgreSQL and MySQL data directories moved from the internal SSD to an external APFS drive, with the old copy kept for rollback

If you develop on a Mac, a local PostgreSQL or MySQL server quietly keeps every test database, every imported dump and every write-ahead log you ever made. On our own dev Mac, three Homebrew data folders added up to about 900 MB, and that was a light one: imported production dumps easily reach tens of gigabytes.

You can move that data to an external drive. The one rule that matters: <b>never copy or move a data directory while the server is running.</b> PostgreSQL's manual is blunt about it: the server must be shut down to get a usable copy, and even blocking connections isn't enough.

Step 1: find the real data directory

Don't guess the path. Ask the running server, then measure:

bash
# PostgreSQL: where the data lives
psql -d postgres -Atc 'SHOW data_directory;'

# MySQL: same question
mysql -u root -p -Nse 'SELECT @@datadir;'

# Sizes of the usual Homebrew data folders (Apple silicon; Intel Macs use /usr/local/var)
du -sh /opt/homebrew/var/postgresql@* /opt/homebrew/var/mysql 2>/dev/null
  • Each PostgreSQL major version has its own folder (postgresql@16, postgresql@18...). An old one left over from an upgrade is often the biggest win, but check with brew services list which ones still run before you touch anything.
  • Postgres.app, Docker volumes and MySQL's own installer keep data elsewhere. The SHOW/SELECT answer is the truth.

Step 2: make a backup you can restore from

The file copy in step 4 is the move; this dump is your insurance if the copy or the drive fails.

bash
# PostgreSQL: every database plus roles, as SQL
pg_dumpall -f ~/pg-backup-$(date +%Y%m%d).sql

# MySQL: every database, consistent for InnoDB tables
mysqldump -u root -p --all-databases --single-transaction --routines --events \
  > ~/mysql-backup-$(date +%Y%m%d).sql

Step 3: prepare the external drive

  • Format it as APFS (exFAT doesn't keep Unix owners and permissions, which both servers need).
  • In Finder, select the drive, File > Get Info, and make sure Ignore ownership on this volume is off. PostgreSQL refuses to start if its data folder isn't owned by the user that runs it.
  • Use a drive that stays plugged in. If it's missing when the server starts, the server will fail to start (which is better than starting on an empty folder, but still annoying).
  • Check Time Machine's options: external drives are often on the exclude list, so the moved data may not be backed up unless you add it.

Step 4: stop, copy, point (PostgreSQL)

This keeps Homebrew's service working by leaving a symbolic link at the old path. The old folder is renamed, not deleted, so you can go back.

bash
V=postgresql@16                      # the version you are moving
OLD=/opt/homebrew/var/$V
NEW=/Volumes/DevData/$V             # your external drive

brew services stop $V
pg_isready -q || echo "stopped"     # must say stopped before you go on

rsync -a "$OLD/" "$NEW/"            # copy with owners and permissions
chmod 700 "$NEW"
mv "$OLD" "$OLD.internal-old"        # keep the original for rollback
ln -s "$NEW" "$OLD"

brew services start $V

Step 4: stop, copy, point (MySQL)

MySQL has a setting for this, so no link is needed: change <code>datadir</code> in the config file Homebrew's MySQL reads (<code>/opt/homebrew/etc/my.cnf</code>).

bash
brew services stop mysql
rsync -a /opt/homebrew/var/mysql/ /Volumes/DevData/mysql/
mv /opt/homebrew/var/mysql /opt/homebrew/var/mysql.internal-old

# then in /opt/homebrew/etc/my.cnf, under [mysqld]:
#   datadir=/Volumes/DevData/mysql

brew services start mysql

Step 5: verify before you free any space

  1. Check the server is up: pg_isready or mysqladmin -u root -p status.
  2. Ask it where it is: SHOW data_directory; / SELECT @@datadir;.
  3. Open a database you care about and count rows in a big table. Run your app's test suite against it.
  4. Look at the log if it didn't start (brew services info $V shows the log path). Operation not permitted or wrong ownership means a permission or privacy setting on the drive; roll back and fix that first.

Rolling back

bash
brew services stop $V
rm "$OLD"                            # removes only the link
mv "$OLD.internal-old" "$OLD"
brew services start $V

Only when everything has worked for a week or so, delete the <code>.internal-old</code> folder. That's the moment the internal SSD actually gets the space back.

Zofle, our free Mac app, measures big app folders like these and shows what each one is before you remove anything, so the cleanup goes through the app that owns the data first.

Download Zofle for Mac

Related

Sources

Zofle Pro news

People signing up now will get Zofle Pro, with more features, for free when we launch it.

One email when it's ready. No spam, ever.