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. …
## 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.
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.
- Posted to Moving PostgreSQL Data to Different Drive (StackExchange).
- [good tips] How To Move a PostgreSQL Data Directory to a New Location on Ubuntu 16.04
[postgres docs] pg_dumpall
- [Arch Linux docs] Manual Dump and Reload
- [StackOverflow] Copying PostgreSQL Database to Another Server
- [StackOverflow] PostgreSQL Dump Permission Denied