← Lessons

quiz vs the machine

Platinum1850

Databases

Extensions And Postgis

How the extension system bolts on new types and operators, with PostGIS as the flagship example.

6 min read · advanced · beat Platinum to climb

A database you can extend

Postgres is built to be extended. An extension is a packaged bundle of new data types, functions, operators, and index support that you install into a database with a single command. This keeps the core lean while letting specialized capabilities ship separately.

What an extension can add

  • New data types with their own storage and operators.
  • New functions and operators the planner can use.
  • New index support, so custom types can be indexed with GiST or GIN.

Because operators integrate with the planner, an extension type can be queried as naturally as a built in one.

PostGIS as the flagship

PostGIS turns Postgres into a full geospatial database. It adds geometry and geography types and a large library of spatial functions.

  • It stores points, lines, and polygons in dedicated types.
  • It answers questions like distance, containment, and intersection.
  • It uses GiST indexes to make spatial searches over millions of shapes fast.

Other popular extensions include one for trigram text similarity, one for cryptographic functions, and the foreign data wrapper machinery for querying remote sources.

Key idea

Extensions package new types, functions, operators, and index support into the database, and PostGIS uses that machinery to add geometry types and GiST indexed spatial queries that make Postgres a geospatial engine.

Check yourself

Answer to earn rating on the learn ladder.

1. What does an extension package add to Postgres?

2. Which index type does PostGIS use for fast spatial searches?

3. Why can an extension type be queried as naturally as a built in one?