4

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

Hassan Baig
  • 15,055
  • 27
  • 102
  • 205
  • You're asking for data migration procedures? Might want to check with Postgresl documentation. As for mounting an SSD (premium) data disk: You'd need an `xS`-series VM for that (DS, GS, etc) - otherwise you can only mount standard storage disks. And if SSD is necessary, you'd need to migrate to a different VM SKU. This would be better suited for ServerFault, since it's not a programming question. – David Makogon Mar 18 '17 at 14:38
  • Hi, what is your VM size? Only S series VMs could mount SSD data. If your VM is not S series VM(such as DS) VM, you had better create a image and create a S series VM by using new Portal. But it need downtime. – Shui shengbao Mar 20 '17 at 01:20
  • @Walter-MSFT: my VM is a DS series VM. – Hassan Baig Mar 20 '17 at 08:03
  • @HassanBaig If your VM is Ds Series, you could add SSD data disk to your classic VMs, please refer to my answer. – Shui shengbao Mar 20 '17 at 08:36
  • @HassanBaig It is normal output when you create Linux file system. – Shui shengbao Mar 20 '17 at 09:01

2 Answers2

4

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

Hassan Baig
  • 15,055
  • 27
  • 102
  • 205
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
0

At first, try to migrate your classic VM to ARM VM. The migration step is as follows; https://learn.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-ps-migration-classic-resource-manager

Those steps seems long but not so difficult or painful. Migrating classic to ARM is optional but its strongly recommended as it gives more granual and flexible resource management including security configuration.

Then, (1) add additional disk to your VM and (2) setup mounted disk to your database storage.

(1) Add additional disk to your VM: It does not require downtime; https://learn.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-attach-disk-portal?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json

(2) Setup postgreSQL is out of Azure-related question, so I will omit the answer.

Youngjae
  • 24,352
  • 18
  • 113
  • 198