• YouTube
  • LinkedIn
  • Google

Como diminuir o tamanho de discos virtuais VMDK –; part 1

Where I work we have a few database servers PostgreSQL in different virtual machines running on a VMWare Server. So far so good, It wasn't a detail that was bothering me. All of them using old versions as 8.1 and 8.2, While the current version is the 9.3.
I sought to know and found out that there are version 9.3 for Centos 6.5 that's what we're using for the new servers and decided then unify the three servers in one.

Se você que leu até aqui e pensou “;Unify servers?? That Buro! give zero for him!; know that it was thought and our reality is an appropriate solution.

That said, and with the dilemma resolved, I set out to create a VM using the Vagrant.

The Vagrant is an excellent tool to help us Devops. With the use of it can create machines that can be easily shared among the members of a team. I won't go into the details of its use, just to inform you that I used a Box of Centos 6.5 Basic.

Until here everything was going very well. Set up the VM and installed the software that would use, including PostgreSQL 9.3.

When I went to migrate the production base started some problems. The PGDATA directory, that's where PostgreSQL stores the data in tables, I was with more than 40 GB. Do a dumpall and a Restore on-the-fly was not an option and decided to extract the whole Bank to later restore the VM.

That part went well. The restoration was successful (After some hassles, of course) and the server was already running.

To my surprise, There was this server many tables that were other backup the same base or that were created for testing and the actual size of the base would be much smaller if I exclude. That's what I did. Removed several tables, I deleted some stuff and the size of the base fell to about 20% the previous size. Besides, with the compressed dump file, This same file unpacked, the use of space has grown very. After deleting these files, There were no more than 8 GB of 200 GB reserved dedicated disk for PostgreSQL. How do we know, the VIRTUALIZER is able to manage the disk so that it only grows if the placeholder is effectively occupied and how it happened, the Virtual disk had already grown to 70 GB.

Disco Com partição dedicada para Dados do PostgreSQL

Secondary disk of the Virtual machine with the PostgreSQL DBMS databases

It would be a problem to transfer this size all safely to any media or via network and in addition to that we needed to keep the disk space as reduced as possible to migrate other servers, due to limitations of the physical machine. As most of this VMDK was blank, There had to be a way to reduce its size.
If the type of the disk VDI, the application VBoxManage would handle, making the compression of the white space at the end of the partition, but this record is of type VMDK for being the most compatible between different Virtualizadores.

The only way I knew to be possible was cloning the disk. As the Linux guy Here the company had asked about the partition structure I decided to also change the structure (and the size) from disk to the desired format and so I decided to clone the installation also.

Disco Primário da VM

Primary disk of the Virtual machine with the Centos operating system files 6.5

Follow the recipe that I used.

First I would reduce the size of the disk used by the database. The first step is to create the disk that will be the clone.

NOTE: In the case of the machine I was using, There was only one IDE controller. Then there is the need to add another controller if you want to add the two discs at once. I'm taking including only one disc at a time attached to the Secondary IDE Slave because I believe that most cases would fit in this.

The following figure shows the Add button hard drive.

Inserting new record in VM

VirtualBox: Configurando Máquina Virtual –; Adding new disk VMDK

After clicking on it will be requested to choose if you want to create a new or an existing one. In our case we must choose Create new record.

VirtualBox - Disk type to be added in the VM

The next step is to define what type of desired allocation. Choose dynamically allocated. Further explain the advantages of this choice.

Selecting the type of allocation

Selecting the type of allocation

After, will be asked about the type of hard disk file to be created. In our case, We're always talking about VMDK, so choose this option.

NOTE: Use the VDI type creates files smaller and more compatible with VirtualBox, but it is not readable by VMWare, for example. As in my case the destination will be a VMWare Server, It is important to choose the most compatible format with him, that the list below is the VMDK.

Option to check hard disk VMDK file

Choosing the type of hard disk file

Set the name and the size of the disk. As we are talking about cloning and physical size reduction, keep in mind that the size should be at least higher than the amount of actual data on disk to be cloned. Do not bother to create a very large and there is no disk space on your computer. How to choose dynamic allocation in the previous item, the space is dynamically allocated, IE, the disk only grows when data is effectively taking up space.

Virtual Box - Name and file size of hard drive

Defining virtual disk's physical size and your name

Ready! Our target disk is created and is displayed as in the image below. Notice the sizes reported. A newly created, empty VMDK disk will take about 25 MB (a VDI only 2 MB).

New disk created

New disk created


Go to the part 2 This tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.