Postgresql – storing file paths in table

database-designpostgresql

I'm working on a project which requires millions of images to be stored for their relative rows.

I have decided to store the images on the file system and store the image's path in a separate table which has a foreign key to the row which the images belong to.

Since I will be storing millions of images, I'm a bit concerned about keeping track of these images. I will have to add a few computers/hdds to store the images. From what I have read I should be using a distributed file system. Am I correct?

Are there any best conventions I should follow before I start implementing this? I'm thinking about storing the images and giving them a UUID name, and to store the UUID as the path of the image. Then my application ill contact the rest of the path.

Best Answer

I have decided to store the images on the file system and store the image's path in a separate table which has a foreign key to the row which the images belong to.

Why not just store the paths on the images table? Why have a 1:1 relationship?

Since I will be storing millions of images, I'm a bit concerned about keeping track of these images. I will have to add a few computers/hdds to store the images. From what I have read I should be using a distributed file system. Am I correct?

You likely do not need a distributed file system. I wouldn't bother with that. Just start an ZFS array up.

Are there any best conventions I should follow before I start implementing this? I'm thinking about storing the images and giving them a UUID name, and to store the UUID as the path of the image. Then my application ill contact the rest of the path.

I wouldn't do that. You're only talking millions. Just use an int. If you want to store something useful on the row, I would store the sha256 of the image.