Moving Postgres 10 data dir on Ubuntu 18
after a clean ubuntu installation (clean all partiotions), auto mounting my second drive and using the answer from here everything works!
installed postgresql-common via:
sudo apt install postgresql-common
open createcluster.conf with nano
sudo nano /etc/postgresql-common/createcluster.conf
uncomment line
create_main_cluster = true
change line
data_directory = '/var/lib/postgresql/%v/%c'
tonew/dir/%v/%c
save file
install postgresql via
sudo apt install -y postgresql-10
How can I move postgresql data to another directory on Ubuntu over Amazon EC2?
Stop the server.
Copy the datadir while retaining permissions - use cp -aRv
.
Then (easiest, as it avoids the need to modify initscripts) just move the old datadir aside and symlink the old path to the new location.
How to move location of postrgresql 13 database
Assuming your configuration files are located under $PG_DATA, where they belong:
- Shut down the (old) database
- Copy the data directory to the new location (use
cp -rp
, orrsync -acv
, ortar
, orcpio
, ...) Make sure that file attributes and ownership are preserved by the copy. Thepgdata
directory should be mode ==0600
, and owner.group ==postgres.postgres
. - [optionally] rename the old data directory
- [optionally] you may want to edit the configuration files at the new location
- edit the startup file (in
/etc/init.d/postgresql
) and make sure $PG_DATA points to the new location. [note: this is for ubuntu; other distributions may us a different starting mechanism] - Start the new database, and check if it runs (
ps auxw| grep postgres
, and if you can connect (psql -U postgres postgres
) - [optionally] remove the directory tree at the old location.
Moving postgres data folder on Ubuntu
- You can just copy or move the directory, including all subdirs and files
cp -rp
ormv
should be enough for this. - Postgres must not be running while you are messing with the files
- The base of the data-drectory (PG_DATA) must be owned by postgres and have file mode 0700 . (when not: pg will refuse to start)
- [the rest of the files must at least be readable/writeble by postgres]
- the new location must also be known to the startup process (in
/etc/init.d/
and (possibly) in the postgres.conf file within the data directory. (for the log file location)
Related Topics
Sql-Server: Error - Exclusive Access Could Not Be Obtained Because the Database Is in Use
If Exists, Then Select Else Insert and Then Select
Insert a Blob via a SQL Script
"Order by ... Using" Clause in Postgresql
Make All Store Images the Base, Small and Thumbnail Images in Magento
Do Indexes Work with "In" Clause
Reverse String Word by Word Using SQL
Identity_Insert Is Set to Off - How to Turn It On
What's the Most Efficient Way to Check If a Record Exists in Oracle
Add Time 23:59:59.999 to End Date for Between
Group by and Count in Postgresql