Skip to main content

Posts

Showing posts from March, 2019

move postgresql datadir

How to move PostgreSQL datadirThe contextI run RHEL 7 and CentOS 7 .
The sysadmin team has setup a virtual machine for me and they put a big "/data" partition.
The default PostgreSQL installation usually use "/var/lib/pgsql" for PostgreSQL location.
I want to change it to "/data/pgsql"

How toStop PostgreSQL
systemctl stop postgresql
Move  "/var/lib/pgsql" and retain ownership & permissions
rsync -av /var/lib/pgsql /data/
Note: don't remove "/var/lib/pgsql" yet!

Configure "/data/pgsql/data/postgresql.conf" with the new location:
- #data_directory = 'ConfigDir'           + data_directory = '/data/pgsql/data'
Configure systemd service file "/usr/lib/systemd/system/postgresql.service"
- Environment=PGDATA=/var/lib/pgsql/data + Environment=PGDATA=/data/pgsql/data
Start PostgreSQLand check it all:
# systemctl start postgresql # systemctl status postgresql # ps aux | grep pgsql # su - postgres $ psql p…