-1

I have an Azure VM running Postgres on Unix, supplied by Bitnami: PostgreSQL 9.6.2-0 (Ubuntu 14.04)

The DB works fine and I am populating it, but after some time, the DB reaches about 25GB in size and then my code (populating the DB) crashes...

psycopg2.OperationalError: could not extend file "base/16450/79079": No space left on device
HINT:  Check free disk space.

I thought it would be a simple resize of my VM. Nope. The VM now has a HDD size of 400GB. Plenty of space.

I then tried my code and again, at 25GB, boom. No space.

The next thing I did was log into the VM via SSH and check the disks with df -h:

enter image description here

As can be seen above, /dev/sda1 is 30GB in size, of which 29GB is used. I suspect my Postgres is using this HDD... set automatically when I used the Bitnami Azure template.

You can see the 400GB HDD that I have set via the Azure portal: /dev/sdb1.

What can I do? I need a lot more data to go into my Postgres DB... and there is no visible way to change the size of /dev/sda1 via the portal.

Update

As requested, here is the contents of fstab before modification (default): enter image description here

I changed /mnt to /opt/bitnami/postgresql/data (according to the path: https://stackoverflow.com/a/8237512/596841). When I updated, saved, quit and rebooted the server, it went back to the default (as seen above).

pookie
  • 151
  • 1
  • 7

2 Answers2

0

The easiest thing to do would be to mount /dev/sdb1 where your data lives. How to find where data lives here: (https://stackoverflow.com/questions/1137060/where-does-postgresql-store-the-database)

So once you know that stop your database and move the data to your /mnt directory.

Then you will place the larger drive where it needs to be for postgres to see it.

umount /dev/sdb1
mount /dev/sdb1 /original/path/to/data

Now you will likely need to update your /etc/fstab from /mnt to /original/path/to/data so that it will persist across reboots.

You can also use LVM and do this: https://kb.vmware.com/selfservice/search.do?cmd=displayKC&docType=kc&docTypeID=DT_KB_1_1&externalId=1006371

I personally think the mount method is the easiest.

Eddie Dunn
  • 463
  • 2
  • 9
  • hmm, I did this, replacing `/original/path/to/data` with `/opt/bitnami/postgresql/data` (as explained in the 1st answer in the link you provided. I then updated the fstab as you explained. I restarted the machine, and ran the `df -h` command, but everything looks the same. I expected sda1 to not be using all the disk space. – pookie May 09 '17 at 13:12
  • Did you first stop the db server and move the contents of /opt/bitnami/postgresql/data to /mnt? – Eddie Dunn May 09 '17 at 13:13
  • I checked my fstab file after saving and quitting, and it was all good... after a server reboot, the fstab has reverted to its original /mnt – pookie May 09 '17 at 13:14
  • No, I just ran the commands as you said - sorry, I'm not familiar with this, so I need step-by-step :) – pookie May 09 '17 at 13:15
  • Can you post the contents of /etc/fstab before and after reboot? – Eddie Dunn May 09 '17 at 13:23
  • Okay, updated post. – pookie May 09 '17 at 13:28
  • OK you still need to move the contents of /opt/bitnami/postgresql/data to /mnt. You can figure out how to use mv right? :) Anyway once you have done that you can just delete the (now empty) /opt/bitnami/postgresql/data and then run ln -s /mnt /opt/bitnami/postgresql/data This might be a little out of your knowledge if you are uneasy moving files. This is turning into multiple issues. – Eddie Dunn May 09 '17 at 13:32
0

The VM now has a HDD size of 400GB

/dev/sdb1 is the temporary storage, this temporary storage must not be used to store data that you are not willing to lose. (reboot will lose temporary data)

I need a lot more data to go into my Postgres DB

We can use Azure portal to add a new disk to this VM, then mount this disk to this VM.

Add a new disk via Azure portal: enter image description here enter image description here

Mount /dev/sdc to Azure VM:

root@jasonvm:/home/jason# fdisk -l  #list all disks

Disk /dev/sdc: 429.5 GB, 429496729600 bytes   #we can find this new disk
255 heads, 63 sectors/track, 52216 cylinders, total 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Then use this command to mount this disk to Azure VM:

root@jasonvm:/home/jason# mkfs.ext4 /dev/sdc
root@jasonvm:/home/jason# mkdir -p /mnt/point1
root@jasonvm:/home/jason# mount /dev/sdc /mnt/point1
root@jasonvm:/home/jason# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  1.7G   12K  1.7G   1% /dev
tmpfs          tmpfs     344M  348K  344M   1% /run
/dev/sda1      ext4       30G  873M   28G   4% /
none           tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
none           tmpfs     5.0M     0  5.0M   0% /run/lock
none           tmpfs     1.7G     0  1.7G   0% /run/shm
none           tmpfs     100M     0  100M   0% /run/user
/dev/sdb1      ext4       50G   52M   47G   1% /mnt
/dev/sdc       ext4      394G   71M  374G   1% /mnt/point1
root@jasonvm:/home/jason# blkid    # list UUID
/dev/sr0: LABEL="rd_rdfe_stable.161107-1031" TYPE="udf" 
/dev/sda1: LABEL="cloudimg-rootfs" UUID="ce8fdc9c-fa56-49db-b69d-8c11634cbb7a" TYPE="ext4" 
/dev/sdb1: UUID="b0531bb0-dadf-4e20-a968-bd177989f7b8" TYPE="ext4" 
/dev/sdc: UUID="46c75dcc-51c8-4d53-8535-d4fc7bf3a5cb" TYPE="ext4" 
root@jasonvm:/home/jason# vi /etc/fstab   # add UUID to fstab, 
# CLOUD_IMG: This file was created/modified by the Cloud Image build process
UUID=ce8fdc9c-fa56-49db-b69d-8c11634cbb7a       /        ext4   defaults,discard        0 0
/dev/disk/cloud/azure_resource-part1    /mnt    auto    defaults,nobootwait,comment=cloudconfig 0       2
UUID=46c75dcc-51c8-4d53-8535-d4fc7bf3a5cb       /mnt/point1     ext4    defaults,nofail 0 0

Note:
we should add this disk to /etc/fstab, in this way, after reboot this VM we will not lost connection to this disk.

After mount new disk to Azure VM, then modify data_directory, we can follow those steps:

Editing the data_directory in postgresql.conf to point to the new location (e.g. /mnt/point1/postgresql/9.3/main)

Transferring contents of PG's data directory to /mnt/point1 via sudo rsync -av /opt/bitnami/postgresql/data /mnt/point1

Restarting posgtesql.

Jason Ye
  • 2,399
  • 1
  • 8
  • 10
  • 1
    Bitnami Developer here. I agree with the answer but note that Bitnami PostrgreSQL location is in `/opt/bitnami/postgresql`. So the original data folder is in `/opt/bitnami/postgresql/data`. – Juan May 10 '17 at 08:31
  • ok, I have update my answer, please check it, thanks. – Jason Ye May 10 '17 at 08:35
  • @pookie does it helpful? if yes, please accept it as an answer so that other community members will be benefited. – Jason Ye May 22 '17 at 04:54