JohnJ JohnJ - 1 month ago 6
Linux Question

moving postgresql main folder out of /var/lib/postgresql/9.4

I have a debian installed server, where I have used

to install pgsql9.4 a few months ago. Now, after a month, I see that the folder totals to 19GB:


is taking up all my space of
(19GB). Agreed, I am writing some heavy UTf-8 stuff onto the instance.

It is probably daft to ask, but, is there a way I can
this folder/installation in postgres to another disk? and still not affect my db? Can this be even done?


Sure you can.

  1. Stop the PostgreSQL server.

    /etc/init.d/postgresql stop

  2. Move the data directory somewhere else.

    mv /var/lib/postgresql/9.4/main /storage/ssd/

  3. Make a symlink pointing to the new location.

    ln -s /storage/ssd/main /var/lib/postgresql/9.4/main

  4. Start the PostgreSQL server.

    /etc/init.d/postgresql start