---
title: "django.contrib.postgres"
version: 3.2
locale: zh-hans
source: https://docs.djangoproject.com/zh-hans/3.2/ref/contrib/postgres/
canonical: https://djangodocs.dev/zh-hans/3.2/ref/contrib/postgres/
---
# `django.contrib.postgres`

PostgreSQL 有许多 Django 支持的数据库所不具备的特性。这个可选的模块包含了一些 PostgreSQL 特有数据类型的模型字段和表单字段。

> **Note**
>
> Django 是，并将继续是一个与数据库无关的网络框架。我们鼓励那些为 Django 社区编写可重用的应用程序的人，在可行的情况下编写数据库无关的代码。然而，我们也认识到，在现实世界中，使用 Django 编写的项目不一定是数据库无关的。事实上，一旦一个项目达到一定的规模，改变底层数据存储已经是一个重大的挑战，很可能需要通过一些方式改变代码库来处理数据存储之间的差异。
>
> Django 提供了对一些数据类型的支持，这些数据类型只能在 PostgreSQL 中使用。除了 PostgreSQL 在支持的数据库中拥有最丰富的功能，所以它的用户可以获得最大的收益之外，没有任何根本的原因（例如）不存在 `contrib.mysql` 模块。

- [PostgreSQL 特有聚合函数](/zh-hans/3.2/ref/contrib/postgres/aggregates/)

  - [通用聚合函数](/zh-hans/3.2/ref/contrib/postgres/aggregates/#general-purpose-aggregation-functions)
  - [统计的聚合功能](/zh-hans/3.2/ref/contrib/postgres/aggregates/#aggregate-functions-for-statistics)
  - [使用实例：](/zh-hans/3.2/ref/contrib/postgres/aggregates/#usage-examples)
- [PostgreSQL 特有数据库约束](/zh-hans/3.2/ref/contrib/postgres/constraints/)

  - [`ExclusionConstraint`](/zh-hans/3.2/ref/contrib/postgres/constraints/#exclusionconstraint)
- [PostgreSQL 特有模型字段](/zh-hans/3.2/ref/contrib/postgres/fields/)

  - [对这些字段进行索引](/zh-hans/3.2/ref/contrib/postgres/fields/#indexing-these-fields)
  - [`ArrayField`](/zh-hans/3.2/ref/contrib/postgres/fields/#arrayfield)
  - [`CIText` 字段](/zh-hans/3.2/ref/contrib/postgres/fields/#citext-fields)
  - [`HStoreField`](/zh-hans/3.2/ref/contrib/postgres/fields/#hstorefield)
  - [`JSONField`](/zh-hans/3.2/ref/contrib/postgres/fields/#jsonfield)
  - [范围字段](/zh-hans/3.2/ref/contrib/postgres/fields/#range-fields)
- [PostgreSQL 特有表单字段和部件](/zh-hans/3.2/ref/contrib/postgres/forms/)

  - [字段](/zh-hans/3.2/ref/contrib/postgres/forms/#fields)
  - [部件](/zh-hans/3.2/ref/contrib/postgres/forms/#widgets)
- [PostgreSQL 特有数据库函数](/zh-hans/3.2/ref/contrib/postgres/functions/)

  - [`RandomUUID`](/zh-hans/3.2/ref/contrib/postgres/functions/#randomuuid)
  - [`TransactionNow`](/zh-hans/3.2/ref/contrib/postgres/functions/#transactionnow)
- [PostgreSQL 特有模型索引](/zh-hans/3.2/ref/contrib/postgres/indexes/)

  - [`BloomIndex`](/zh-hans/3.2/ref/contrib/postgres/indexes/#bloomindex)
  - [`BrinIndex`](/zh-hans/3.2/ref/contrib/postgres/indexes/#brinindex)
  - [`BTreeIndex`](/zh-hans/3.2/ref/contrib/postgres/indexes/#btreeindex)
  - [`GinIndex`](/zh-hans/3.2/ref/contrib/postgres/indexes/#ginindex)
  - [`GistIndex`](/zh-hans/3.2/ref/contrib/postgres/indexes/#gistindex)
  - [`HashIndex`](/zh-hans/3.2/ref/contrib/postgres/indexes/#hashindex)
  - [`SpGistIndex`](/zh-hans/3.2/ref/contrib/postgres/indexes/#spgistindex)
  - [`OpClass()` 表达式](/zh-hans/3.2/ref/contrib/postgres/indexes/#opclass-expressions)
- [PostgreSQL 特有查找](/zh-hans/3.2/ref/contrib/postgres/lookups/)

  - [三元相似度](/zh-hans/3.2/ref/contrib/postgres/lookups/#trigram-similarity)
  - [`Unaccent`](/zh-hans/3.2/ref/contrib/postgres/lookups/#unaccent)
- [数据库迁移操作](/zh-hans/3.2/ref/contrib/postgres/operations/)

  - [使用迁移创建扩展](/zh-hans/3.2/ref/contrib/postgres/operations/#creating-extension-using-migrations)
  - [`CreateExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#createextension)
  - [`BloomExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#bloomextension)
  - [`BtreeGinExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#btreeginextension)
  - [`BtreeGistExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#btreegistextension)
  - [`CITextExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#citextextension)
  - [`CryptoExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#cryptoextension)
  - [`HStoreExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#hstoreextension)
  - [`TrigramExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#trigramextension)
  - [`UnaccentExtension`](/zh-hans/3.2/ref/contrib/postgres/operations/#unaccentextension)
  - [使用迁移来管理整理](/zh-hans/3.2/ref/contrib/postgres/operations/#managing-collations-using-migrations)
  - [并发索引操作](/zh-hans/3.2/ref/contrib/postgres/operations/#concurrent-index-operations)
- [全文搜索](/zh-hans/3.2/ref/contrib/postgres/search/)

  - [`search` 查找](/zh-hans/3.2/ref/contrib/postgres/search/#the-search-lookup)
  - [`SearchVector`](/zh-hans/3.2/ref/contrib/postgres/search/#searchvector)
  - [`SearchQuery`](/zh-hans/3.2/ref/contrib/postgres/search/#searchquery)
  - [`SearchRank`](/zh-hans/3.2/ref/contrib/postgres/search/#searchrank)
  - [`SearchHeadline`](/zh-hans/3.2/ref/contrib/postgres/search/#searchheadline)
  - [更改搜索配置](/zh-hans/3.2/ref/contrib/postgres/search/#changing-the-search-configuration)
  - [加权查询](/zh-hans/3.2/ref/contrib/postgres/search/#weighting-queries)
  - [性能](/zh-hans/3.2/ref/contrib/postgres/search/#performance)
  - [三元相似度](/zh-hans/3.2/ref/contrib/postgres/search/#trigram-similarity)
- [验证器](/zh-hans/3.2/ref/contrib/postgres/validators/)

  - [`KeysValidator`](/zh-hans/3.2/ref/contrib/postgres/validators/#keysvalidator)
  - [范围验证器](/zh-hans/3.2/ref/contrib/postgres/validators/#range-validators)
