Skip to content

Connecting to PostGIS

Mundi can connect to pre-existing PostGIS databases and can create visualization layers from PostGIS tables via custom queries, generate Wiki-like documentation of your database schema, and execute queries to answer questions about the data.

1. Click the ‘Load PostGIS’ button in the layer list

Section titled “1. Click the ‘Load PostGIS’ button in the layer list”

Click the Add PostGIS button

You should prefer read-only users for security.

PostGIS Connection Dialog

If someone else hosts your database, you should ask them for these details.

You can also connect to the same PostGIS database that you normally use from QGIS as long as it’s not hosted locally.

Connecting from QGIS

This allows you to work with the same spatial data across both Mundi and QGIS environments.

Give the database some time to load. During this time, Mundi is generating wiki-like documentation about your database schema.

postgis connection is loading

Once it’s loaded, it will appear in your project’s database list, with an AI generated name and table count.

AI generated database name

You can hover over the database name and click on it to view the generated wiki page.

AI generated wiki documentation for PostGIS database

The wiki page is generated by an AI model that sees your database schema, example data, foreign key relationships, etc. It includes diagrams explaining the how different tables relate to eachother:

PostGIS table foreign key relationships

Once connected, you can ask Kue, the AI assistant in Mundi, to create new map layers that source spatial data from the connected PostGIS database.

Kue request to add new layer

This creates a dynamic layer in Mundi that continuously pulls data from your PostGIS database:

Mundi dynamic PostGIS layer served from database

We recommend that users create read-only database users for Mundi to use. This read-only user should only have access to the tables that you intend to use Mundi to analyze.

Here is how you might go about creating this user:

CREATE USER mundi_readonly WITH PASSWORD '...';
GRANT SELECT ON spatial_table_1, polygon_table_2 TO mundi_readonly;

Opened connections to third-party PostGIS databases from Mundi are always opened as read-only, so there are only additional risks to allowing the user write access.

Options when self-hosting Mundi open source

Section titled “Options when self-hosting Mundi open source”

You can set the environment variable POSTGIS_LOCALHOST_POLICY to one of the following values:

  • disallow prevents users from connecting to loopback addresses, which can help prevent unauthorized access and connections to databases running on the host machine
  • rewrite which is useful for connecting to PostgreSQL running on the host machine. This tells Docker to redirect localhost to the host machine, instead of the Docker container
  • allow to allow connections to localhost databases. Because Docker localhost is different from your computer’s localhost, this rarely makes sense

If your PostGIS database fails to connect, hover over the connection error to see the full error message.

PostGIS connection error message in Mundi

If you’ve looked into the below issues and can’t connect, you can ask in our community Discord.

If you normally connect to your database from QGIS or similar using localhost or 127.0.0.1, the database is running on your local computer and will not be accessible from Mundi cloud (or any other cloud service).

Mundi detected a localhost database address

You would need to create a replica of your PostgreSQL database on a cloud provider and provide us that connection string instead to connect Mundi to your data.

If the connection times out (Mundi defaults to 10 second limit), it’s likely that the database is not accessible from the internet, either due to a firewall or the database is on your local network. In order to be accessible, the database must be pinned to a public static IPv4 address allowing ingress and egress traffic.