JohnJ JohnJ - 2 months ago 11
Linux Question

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

I have a debian installed server, where I have used

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

/var/lib/postgresql/9.4/main


is taking up all my space of
rootfs
(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
move
this folder/installation in postgres to another disk? and still not affect my db? Can this be even done?

Answer

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