用于在数据库中存储不同文件的数据类型

时间:2022-02-05 08:03:02

Im trying to make a database accept different files in a postgres database table. The files I want to support are of different mime-types. I want to support pdf, word, plain text, and power point. The problem is that i don't know what datatype to choose. The documentation to pgadmin (the tool im using) is very (let´s say) unsatisfactory. Thanks

我试图让一个数据库接受postgres数据库表中的不同文件。我想要支持的文件是不同的mime类型。我想支持pdf,word,纯文本和power point。问题是我不知道选择什么数据类型。 pgadmin(我正在使用的工具)的文档非常(假设)令人不满意。谢谢

2 个解决方案

#1


4  

While you can store the file contents in the database, consider storing the file path instead and using the file system to store the file.

虽然可以将文件内容存储在数据库中,但请考虑存储文件路径,并使用文件系统存储文件。

In the IT world "you can do anything with anything", but that doesn't mean you should.

在IT世界中,“你可以做任何事情”,但这并不意味着你应该做。

In this case, you're trying to use a database as a file system, which it can do, but databases are not as efficient or practical as file systems for storing file contents (typically "large" data). It will:

在这种情况下,您尝试将数据库用作文件系统,但它可以做,但数据库不如存储文件内容(通常是“大”数据)的文件系统那样高效或实用。它会:

  • make your backups longer and larger
  • 使您的备份更长,更大
  • slow your insert queries down (more I/O)
  • 减慢插入查询速度(更多I / O)
  • make your log files larger (slower and fill more often)
  • 使您的日志文件更大(更慢,更频繁地填充)
  • make accessing the files slower (query vs simple disk I/O)
  • 使访问文件更慢(查询与简单的磁盘I / O)
  • require you to go via the database to access the files (hassle, can't use browser etc)
  • 要求你通过数据库访问文件(麻烦,不能使用浏览器等)
  • etc
  • 等等

#2


3  

You can use bytea type in PostgreSQL.

您可以在PostgreSQL中使用bytea类型。

#1


4  

While you can store the file contents in the database, consider storing the file path instead and using the file system to store the file.

虽然可以将文件内容存储在数据库中,但请考虑存储文件路径,并使用文件系统存储文件。

In the IT world "you can do anything with anything", but that doesn't mean you should.

在IT世界中,“你可以做任何事情”,但这并不意味着你应该做。

In this case, you're trying to use a database as a file system, which it can do, but databases are not as efficient or practical as file systems for storing file contents (typically "large" data). It will:

在这种情况下,您尝试将数据库用作文件系统,但它可以做,但数据库不如存储文件内容(通常是“大”数据)的文件系统那样高效或实用。它会:

  • make your backups longer and larger
  • 使您的备份更长,更大
  • slow your insert queries down (more I/O)
  • 减慢插入查询速度(更多I / O)
  • make your log files larger (slower and fill more often)
  • 使您的日志文件更大(更慢,更频繁地填充)
  • make accessing the files slower (query vs simple disk I/O)
  • 使访问文件更慢(查询与简单的磁盘I / O)
  • require you to go via the database to access the files (hassle, can't use browser etc)
  • 要求你通过数据库访问文件(麻烦,不能使用浏览器等)
  • etc
  • 等等

#2


3  

You can use bytea type in PostgreSQL.

您可以在PostgreSQL中使用bytea类型。