1

I want to know if it is possible to have a portable Postgresql database on an external hard drive. The idea is to use that hard drive, by plugging it to one of my computers and use the database.

For the moment, it is not possible for me to have a computer that is always running and connecting to it through the network. For some reasons I don't always have access to the same computer but I always have access to my external hard drive. The computers are both running a Linux distribution.

1
  • 1
    Database != File A PostgreSQL cluster is a running process that manages its own files. You would have to have exactly the same Postgres software version running on both machines and would have to shut the database down /cleanly/ before unplugging/ejecting the external drive - every single time. Failure to do so could completely trash your database. Take backups very, /very/ often.
    – Phill W.
    Commented Jun 13, 2022 at 11:05

1 Answer 1

1

As long as all the machines that you want to use are running the exact same versions of the same operating system on the same architecture (hint: the C library must be the same version to avoid index corruption), that is no problem. Simply create a data directory on the external drive with initdb. Make sure that the drive is reliable hardware and you are running a reliable file system on it.

2
  • 2
    I would add: make sure you always shut down Postgres properly before shutting down the computer or unplugging the drive.
    – user1822
    Commented Jun 13, 2022 at 7:05
  • 1
    Yes, that is a good idea, although PostgreSQL should have no problem recovering from a crash. Commented Jun 13, 2022 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.