---
title: "Vector tiles from PostgreSQL | Guides | Self hosting | Map server"
description: "Serve spatial data from PostgreSQL as vector tiles."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Vector tiles from PostgreSQL

This article shows how to set up [MapTiler Server](https://www.maptiler.com/server/) to load spatial data from your PostgreSQL database, serve them as map tiles, and how to integrate these tiles into your map.

Applications for this functionality include the ability to serve real-time data or data which is updated frequently, as vector tiles on top of a customizable base map.

## Prerequisites

1.  a running PostgreSQL database with preinstalled PostGIS extension that is populated with some spatial data
2.  installed [MapTiler Server](https://www.maptiler.com/server/) instance
3.  optional: basic maps served from MapTiler Server instance which you can get from our [data starter pack](https://data.maptiler.com/server/)

## Vector tiles schema

A vector tiles schema describes the spatial data that is transformed from PostGIS into tiles. Schemas consist of three parts:

1.  connection properties
2.  layers definitions
3.  metadata

Each layer represents one SQL query, containing returned geometry. Selected geometries for x/y/z tile requests are merged and served as a zipped tile.

A schema is stored in a .yml file and is treated like any other supported tiles format (MBTiles, GeoPackage).

## Step-by-step tutorial

On the **Tiles** page, click on the **New Tiles** button.

![](./file_17796f2906.png)

Next, click on the **Create schema** button.

![](./file_390fdc761a.webp)

Then fill in the individual connection **properties** or at least one **connection string,** and then click **Connect**.

![](./file_63eb5e214c.png)

Select the geometry column(s) you want to serve as tile layer(s) and press **Continue**.

![](./file_914b25a9ec.webp)

Now, you should see a preview of the created layer(s). Here you can edit the tile’s properties, including zoom levels defining where the layer should be visible. Now press **Save**.

![](./file_45c06a974b.webp)

A dialog with a metadata form should open, where you should fill in the **name** of the created tiles and press **Save** again to create the schema.

![](./file_9dacb420f5.webp)

The new vector tiles schema will be displayed as a **.yml** file within the working directory, and tiles will be served from it. Open these tiles by clicking on the **Detail** button.

![](./file_13a5445852.png)

You can edit a selected schema with a click on the **Edit schema** button, or you can directly use it in your map by clicking on the **Add to Map** button.

Select one of your existing map styles to use as a **base map** behind the new tiles. As a result, a new map style will be created (the base map style will stay untouched). Fill in the new map’s name and press the **Save** button.

![](./file_4bff2dc6f7.webp)

Your new map using tiles from your PostGIS source should appear in the **Maps** section.

A style for the added PostGIS layers is generated, which you may want to edit. MapTiler Server does not yet include a GUI interface for style editing/customization, so you will have to edit the style.json manually to make changes.

![](./file_82946d0732.webp)

## Conclusion

That’s it! Now you know how to connect [MapTiler Server](https://www.maptiler.com/server/) to a PostgreSQL database with PostGIS and serve the data within as vector tiles. Get started now to serve real-time spatial data from PostgreSQL with MapTiler Server, fully integrated with your custom MapTiler basemaps.

## Useful links

[MapTiler Server](https://www.maptiler.com/server/)  
[Download MapTiler Server](https://www.maptiler.com/server/download/)  
[Add data to MapTiler Server](https://docs.maptiler.com/guides/on-prem/server/)
