Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -e
- # Script to relocate postgres 9.5 data dir on Ubuntu 14.04 to a compressed ZFS volume (single disk, /dev/sdb, assumed to be blank)
- # install ZFS and tools
- apt-get install software-properties-common rsync -y
- add-apt-repository ppa:zfs-native/stable
- apt-get update
- apt-get install ubuntu-zfs
- modprobe zfs
- # create a compressed single disk ZFS volume mounted at /compressed
- zpool create compressed -m /compressed /dev/disk/by-id/$(ls -l /dev/disk/by-id | grep sdb | grep scsi- | grep -v part | awk -F ' ' '{print $9}') -O compression=lz4 -f
- # expands out to the equivalent of
- # ls -l /dev/disk/by-id
- # zpool create compressed -m /compressed /dev/disk/by-id/scsi-3600224808c8b9c03e89b155933a3c8fd -O compression=lz4 -f
- # move the database
- service postgresql stop
- rsync -av /var/lib/postgresql /compressed
- mv /var/lib/postgresql/9.5/main /var/lib/postgresql/9.5/main.bak
- # reconfigure postgres
- # set data_directory = '/compressed/postgresql/9.5/main'
- sed -i -e '/^data_directory =/s/^.*$/data_directory = '"'\/compressed\/postgresql\/9.5\/main'"'/' /etc/postgresql/9.5/main/postgresql.conf
- # start postgres
- service postgresql start
- # verify results
- # check that directory returned from the following command starts with "/compressed"
- sudo -u postgres psql -c "SHOW data_directory;"
- # delete the backup
- rm -Rf /var/lib/postgresql/9.5/main.bak
- # verify that postgres still works
- service postgresql restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement