Nfs – Moving postgres data folder on NFS drive. Is it better to symlink, reinit cluster, or modify init.d script

migrationnfspostgresqlsymbolic-link

I want to move my postgres data folder to an NFS drive but I'm not sure what would be the best way to do it. I've got three options in mind:

  1. According to Postgres Documentation, one method would be to use the initdb command with the -D option.

    initdb will attempt to create the directory you specify if it does not already exist.

  2. Another method listed on LinuxQuestions.org is to update the postgressql init script to point to the new directory, which in this case would be the NFS drive.

  3. Lastly, I was thinking I would just copy the pgsql/data folder to the NFS drive and simply symlink the folder.

    i.e., pgsql/data -> nfs/data

Symlinking or updating the init script seem like the simplest approach to me, but I'm not sure if they would be best or the safest way. This is where I hope someone can help me out. Any suggestions, concerns, and pros/cons would be appreciated.

Environment Information

  • Red Hat Enterprise Linux Server 5.7
  • PostgreSQL 8.3.6

Assume that the NFS drive is mounted with -maproot=root option and that the NFS drive would be accessed by the root user.

Best Answer

You can simply shut down Postgres, move the folder over and change the init scripts to point to the correct location for the data directory. Double-check the configuration files under data/ for references to the old path before restarting the server.


You probably don't want to do this. Really. It's a BAD idea.
NFS's other name is the Network Failure System. It is not known for its reliability, and having the underlying filesystem go away at an inopportune time (e.g. when appending to the WAL) could really ruin your day, not to mention your database. Remember that Postgres does nothing special for NFS, and will freak out if something unexpected happens (see 17.2.1 in the Postgres manual).

Perhaps if you describe the underlying problem you're trying to solve (ask a new question) we can help you do so in a less risky way?

Related Topic