Postgresql – Postgres tablespace on mounted usb

postgresqltablespaces

I've got postgres 9.1 running on raspbian installed with apt-get.
I've got NTFS usb HDD mounted in /mnt/usb.
What I'd like to achieve is to create a tablespace pointing to /mnt/usb/postgres so I invoke:

CREATE TABLESPACE usbwd LOCATION '/mnt/usb/postgres';

and I get:

could not set permissions on directory "/mnt/usb/postgres": Operation
not permitted

which is understandable since the manual states that the target directory has to be empty (it is in my case) and owned by postgres linux user. That's what I have problem with and

sudo chown postgres:postgres /mnt/usb/postgres

changes nothing, meaning the ownership does not change. The /mnt/usb/postgres is owned by pi user, and I need to have it owned by postgres user. The /mnt/usb is also owned by pi user.
What am I missing ?

Best Answer

PostgreSQL won't run off NTFS on Linux. Format the drive as ext4.

Frankly, putting a database on a USB key on a tablespace isn't usually a great idea. The tablespace is unreadable without the rest of the database, and the rest of the database is useless without the tablespace. So you're creating a fragile system with two points of failure.

It's a much better idea to instead move the whole PostgreSQL data directory onto the USB drive.