0

I'm following this tutorial that explains how to move a PostgreSQL data folder location. Basically, I just need to copy the files inside /var/lib/postgresql to a different location... Something like:

sudo rsync -av /var/lib/postgresql /mnt/volume

And then inside the file /etc/postgresql/9.5/main/postgresql.conf I change the line data_directory = '/mnt/volume/postgresql/12/main'...

This solution works perfectly fine, the only condition is that the copied folder needs to have postgres:postgres permissions recursively.

The problem starts when I use VirtualBox with a shared folder location between the host and the guest, let's say my shared folder location is in /home/SharedFolder and I have PostgreSQL installed in my virtual machine. These VirtualBox shared folders always appear inside the guest with root:vboxsf permissions, those permissions won't change with chmod or chown and that makes it impossible for me to create a new folder on this shared folder with postgres:postgres permissions. I've tried adding postgres to the groups vboxsf and root (I know, that's not recommended), but it doesn't work as well. It just works when all the folders inside /home/SharedFolder/postgres have postgres:postgres permissions. Is there any workaround to that problem? How can I change the data folder location of PostgreSQL when I can't control the permissions of its destination folder (in this case, the VirtualBox shared folder location)?

3
  • NFS ? Ie turn the host into an NFS server and export that to the virtual machine. Commented Feb 2, 2022 at 23:08
  • @StefanSkoglund In my case, I'd like to share this virtual machine with different people. So expecting them to make their host system an NFS server wouldn't be an ideal solution for me. I wanted a solution where I can solve it with guest configurations (with the only one host configuration being the shared folder)...
    – raylight
    Commented Feb 2, 2022 at 23:17
  • My from-the-back reaction is this: how are you gonna share the folders ? NFS/SMB ? You can't share a folder in itself. One other method is using the host as a SAN system ie sharing the device using iSCSI for example. Commented Feb 4, 2022 at 23:04

1 Answer 1

0

I ended up finding a solution by mounting the shared folder directly on /etc/fstab, we can force permissions to stay as we want from there. Basically, I've shared a folder with no automount activated on the host:

enter image description here

Then I added the following line in /etc/fstab guest file:

postgresql /home/path/guest/postgresql/ vboxsf uid=postgres,gid=postgres 0 0

And finally I've changed the data_directory variable inside /etc/postgresql/12/main/postgresql.conf to:

data_directory = '/home/path/guest/postgresql/12/main'

As long as the data inside postgresql is a copy of the original postgresql folder it'll work fine.

3
  • NOW you delegated the device itself to the virtual machine! You didn't share the system using NFS but you insted in ESXi terms constructed a VMDK for the app and then included that VMDK in the virtual machine (which is basically comparable with in an ESXi host running iSCSI/FC/(or NFS) and importing that storage as a device in the virtual machine. Commented Feb 4, 2022 at 23:07
  • This is comparable with moving a diskpack from an SMD drive in one system to another SMD drive in another system! Commented Feb 4, 2022 at 23:08
  • @StefanSkoglund The main issue on this question was not about sharing the folder... The main issue was that when I automatically mount a shared folder with VirtualBox it forces the folder's permission to root:vboxsf. We can solve this problem by manually mounting the folder, since we can choose its permissions while mounting it.
    – raylight
    Commented Feb 7, 2022 at 15:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .