在PostgreSQL中存储图像的最佳方法 [英] Best way to store images in PostgreSQL

查看:240
本文介绍了在PostgreSQL中存储图像的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站上,该网站的开头将包含成千上万张图片,希望达到数亿张。大部分图片的物理尺寸不会超过300K。在PostgreSQL中存储这些的最佳方法是什么?我肯定知道的一件事是,系统将使用架构,分区和表空间来管理存储。

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.

推荐答案

图像不超过300Kb,最简单的方法是使用BYtea字段。
图像保存在数据库中:一个简单的备份将包括这些图像。

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.

或者,PostgreSQL可以处理大对象:
http://www.postgresql.org/docs/9.3/static/largeobjects.html
,通过这些
图像将存储在数据库的外部。

Or, PostgreSQL can handle large objects: http://www.postgresql.org/docs/9.3/static/largeobjects.html with which the images will be stored externally to the database.

或者,您可以将图像保留在文件系统中,将路径保存在文本字段中,并使用两个存储的函数(例如,在pl / python中),这些函数可用于编写和读取外部文件以存储和检索图像。

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.

这篇关于在PostgreSQL中存储图像的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆