Overview

There are a number of articles describing how to create a custom PostgreSQL database location, but very few  describe how to move an existing database to a new location (folder, partition).

Here is a brief description of how to do that on Arch Linux (these steps should be similar for other Linux distributions).

pg_dumpall is a utility for writing out (dumping) all PostgreSQL databases of a cluster into one script file. … It does this by calling pg_dump for each database in the cluster. …

For example:

## To dump all databases:
  $ pg_dumpall > /tmp/db.out                      ## backup all postgres databases to file
  $ pg_dumpall -Fc dbname > /tmp/outfile          ## backup a database

## To reload database(s) from that file:
  $ psql -f /tmp/db.out postgres
  
It is not important to which database you connect here since the script file created by pg_dumpall
will contain the appropriate commands to create and connect to the saved databases.

TL/DR

You need to:

  • export (pg_dumpall) database
  • create new EMPTY directory
  • edit postgresql.conf file
  • restart postgres server service
  • load old data from dump file into new database

Summary of Commands

I’m leaving my my shell prompts (hostname …) in place, to clarify what shell I am in as I proceed.


Done! 


Example

2019-05-02


Awesome! 


References