-
Notifications
You must be signed in to change notification settings - Fork 2
Moving Redis Postgres directories to different disks
Dave Lawrence edited this page Jun 7, 2021
·
4 revisions
Redis and Postgres can get very large, so you probably need to move it off the root partition on servers (especially VMs)
The easiest way is to softlink the data dirs on a different partition to the standard location, so the config file doesn't need to change (and get wiped out during upgrades)
# as root user
service redis-server stop
mkdir /mnt/redis_database
chmod 755 /mnt/redis_database
chown redis /mnt/redis_database
mv /var/lib/redis/* /mnt/redis_database
rmdir /var/lib/redis
ln -s /mnt/redis_database /var/lib/redis
The service is restricted to what directories it can write to. So modify:
vi /lib/systemd/system/redis-server.service
Then add a line eg:
ReadWriteDirectories=-/mnt/redis_database
systemctl daemon-reload # Applies ReadWriteDirectories change above
sudo service redis-server start
To hard shutdown the server:
redis-cli
>shutdown NOSAVE
Make sure to check redis logs that backups work etc
tail -f /var/log/redis/redis-server.log
Ran out of space on VM instance (10G), so moved to Ephemeral disk (120G)
#!bash
sudo bash
# as root
service postgresql stop
cd /var/lib/postgresql/9.4
cp -aRv main /mnt/postgresql
mv main main.OLD
su postgres
# as postgres
ln -s /mnt/postgresql main
# CTR+D to logout of postgres account
service postgresql start
# Note: Sometimes I have trouble with starting postgres, so use:
sudo systemctl start postgresql