# Django 5.2.9 documentation

# `django.contrib.postgres`

PostgreSQL has a number of features which are not shared by the other databases Django supports. This optional module contains model fields and form fields for a number of PostgreSQL specific data types.

Note

Django is, and will continue to be, a database-agnostic web framework. We would encourage those writing reusable applications for the Django community to write database-agnostic code where practical. However, we recognize that real world projects written using Django need not be database-agnostic. In fact, once a project reaches a given size changing the underlying data store is already a significant challenge and is likely to require changing the code base in some ways to handle differences between the data stores.

Django provides support for a number of data types which will only work with PostgreSQL. There is no fundamental reason why (for example) a `contrib.mysql` module does not exist, except that PostgreSQL has the richest feature set of the supported databases so its users have the most to gain.

- PostgreSQL specific aggregation functions
  - General-purpose aggregation functions
  - Aggregate functions for statistics
  - Usage examples
- PostgreSQL specific database constraints
  - `ExclusionConstraint`
- PostgreSQL specific query expressions
  - `ArraySubquery()` expressions
- PostgreSQL specific model fields
  - Indexing these fields
  - `ArrayField`
  - `HStoreField`
  - Range Fields
- PostgreSQL specific form fields and widgets
  - Fields
  - Widgets
- PostgreSQL specific database functions
  - `RandomUUID`
  - `TransactionNow`
- PostgreSQL specific model indexes
  - `BloomIndex`
  - `BrinIndex`
  - `BTreeIndex`
  - `GinIndex`
  - `GistIndex`
  - `HashIndex`
  - `SpGistIndex`
  - `OpClass()` expressions
- PostgreSQL specific lookups
  - Trigram similarity
  - `Unaccent`
- Database migration operations
  - Creating extension using migrations
  - `CreateExtension`
  - `BloomExtension`
  - `BtreeGinExtension`
  - `BtreeGistExtension`
  - `CITextExtension`
  - `CryptoExtension`
  - `HStoreExtension`
  - `TrigramExtension`
  - `UnaccentExtension`
  - Managing collations using migrations
  - Concurrent index operations
  - Adding constraints without enforcing validation
- Full text search
  - The `search` lookup
  - `SearchVector`
  - `SearchQuery`
  - `SearchRank`
  - `SearchHeadline`
  - Changing the search configuration
  - Weighting queries
  - `Lexeme`
  - Performance
  - Trigram similarity
- Validators
  - `KeysValidator`
  - Range validators