在 PostgreSQL 中存储图像的最佳方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19748848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to store images in PostgreSQL
提问by Sam Carleton
I am working on a web site that will start off with hundreds of thousands of images in it to hopefully hundreds of millions. Most of the images won't exceed 300K in physical size. What is the best way to store these in PostgreSQL? One thing I know for sure is that the system will be using schemas, partitions, and tablespaces to manage storage.
我正在开发一个网站,该网站将从数十万张图片到数亿张图片开始。大多数图像的物理大小不会超过 300K。将这些存储在 PostgreSQL 中的最佳方式是什么?我确信的一件事是系统将使用模式、分区和表空间来管理存储。
回答by AndreaBoc
If the images do not exceed 300Kb, the easiest way is to use a bytea field. The images are saved in the database: a simple backup will include the images.
如果图像不超过 300Kb,最简单的方法是使用 bytea 字段。图像保存在数据库中:一个简单的备份将包括图像。
Or, PostgreSQL can handle large objects: http://www.postgresql.org/docs/9.3/static/largeobjects.htmlwith which the images will be stored externally to the database.
或者,PostgreSQL 可以处理大对象:http: //www.postgresql.org/docs/9.3/static/largeobjects.html图像将存储在数据库外部。
Alternatively, you can leave the images in the file system, save in a text field the path and use two stored functions (for example in pl/python) that allow you to write and read the external file to store and retrieve images.
或者,您可以将图像保留在文件系统中,将路径保存在文本字段中并使用两个存储函数(例如在 pl/python 中),允许您写入和读取外部文件以存储和检索图像。