Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding SSD data disk to Azure classic VM and moving PSQL database files to it

I use Azure infrastructure to host a Django/Postgresql application. The app and the db are on separate VM. Each VM has Ubuntu 14.04, and it's the classic flavor.

I've been using the OS disk for my db's storage (capacity: 30GB). This was fine in the early days when the size of my DB was small. But now, going out of disk space has become a real danger.

Via what steps can I procure more storage space for my DB VM. Moreover, what steps would I need to execute to move the postgresql DB to this newly procured storage space?

I want to avoid downtime or data loss, and being an accidental DBA of sorts, would love fool-proof steps explained in terms understandable for beginners. Thanks in advance!


Update:

After mounting the disk, the steps entail:

Editing the data_directory in /etc/postgresql/9.3/main/postgresql.conf to point to the new location (e.g. /home/data/postgresql/9.3/main)

Transferring contents of PG's data directory to /home/data via sudo rsync -av /var/lib/postgresql /home/data

Restarting posgtesql via sudo /etc/init.d/postgresql restart

Note: change steps accordingly if the additional storage is mounted somewhere other than /home/data

like image 804
Hassan Baig Avatar asked Oct 19 '25 02:10

Hassan Baig


1 Answers

For now, only S series VMs(such as Ds, FS) could add SSD disk. You could attach SSD disk to a classic VM on new Azure Portal. Please refer to these steps:

1.Create a new classic storage account(Premium). If you have Premium storage account, you could not create it.

enter image description here

2.Attach SSD disk on new Azure Portal.

enter image description here

3.Type:Select Premium (SSD) Location Select your storage account

enter image description here

Once the new data disk is attached, you'll need to create a filesystem and mount the disk. Assuming you're using ext4 filesystem, here's how to proceed:

sudo mkfs.ext4 /dev/sdc
mkdir -p /home/data
mount /dev/sdc /home/data
df -h            #to view the attached disk

You could obviously mount it to a location different than /home/data as well.

Next, to ensure the data drive gets remounted in the event of a system reboot, do the following:

sudo -i blkid #get uuid for the relevant disk just added
sudo nano /etc/fstab

And then add the following at the end of the file:

UUID=<uuid>  /home/data  ext4  defaults,nofail  1 2

E.g. it could be

UUID=753a5b1b-4461-74d5-f6e3-27e9ff3b6c56  /home/data  ext4  defaults,nofail  1 2

Note that /home/data is the drive you mounted the disk to, so change it as you like.

For a complete reference, go to: https://learn.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-classic-attach-disk#initialize-a-new-data-disk-in-linux

like image 92
Shui shengbao Avatar answered Oct 21 '25 16:10

Shui shengbao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!