Report this

What is the reason for this report?

I'm having strange behaviour of managed database with postgis extension

Posted on May 30, 2022

We are trying to setup a managed database to be used as a datasource for QGIS a Spatial GUI for Geologic data.

We manage to setup a database on a droplet under linux and installed postgres manually. On that system we get very good results. We can connect and import data from different sources to the database through the GUI.

We want to have a managed database in production. But we haven’t bean able to get a smooth running service in place.

The errors start when trying to import data. Since QGIS is open source it uses GDAL library to do this.

Our approach to narrow down the error was as follows. We used the tool ogr2ogr to achieve more verbose error output while doing the import.

with this command line tool we where able to import the data into the managed postgres cluster. But!!

We no are not able to access the data through pgadmin4

We get the following error message when trying to select through the imported table:

The application has lost the database connection:
⁃ If the connection was idle it may have been forcibly disconnected.
⁃ The application server or database server may have been restarted.
⁃ The user session may have timed out.
Do you want to continue and establish a new session

Even though the application has not lost the connection.

When I write a custom select where I do not query for the geom column it will go through. If I then add the geom column to my query it will work properly.

My guess is that there is something not entirely enabled for the user trying to access the database.

With the postgis extension only working half way through this service is not an option for us.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

I might be wrong, but this feels less like a PostGIS bug and more like a difference between a self managed Postgres install and the constraints of a managed service.

On DigitalOcean Managed PostgreSQL you don’t have superuser access, and some PostGIS or GDAL related code paths can behave differently than on a Droplet. That can explain why simple queries work, but GUI tools like QGIS or pgAdmin run into connection issues when inspecting geometry or metadata.

I’d double check that the PostGIS version matches what your client tools expect and that the user has full privileges on the schema and geometry tables. Tools like QGIS often issue more complex queries than a basic SELECT, which can expose limits or timeouts on managed databases.

Since the same setup works fine on a Droplet, this is likely a managed service limitation. At this point, opening a support ticket with a minimal repro is probably the fastest way to confirm what’s going on.

Heya,

This doesn’t sound like “PostGIS only half enabled” so much as pgAdmin struggling with how it renders geometry.

pgAdmin’s “View/Edit Data” and even some query result grids can choke on geometry columns (especially if they’re large or returned as binary/EWKB), and when that happens you often get the generic “lost connection” message even though the database is fine. PostGIS itself even calls out that pgAdmin isn’t a reliable way to inspect geometry payloads.

A quick way to confirm is to avoid returning raw geom and instead return a representation pgAdmin can handle, e.g.:

SELECT id, ST_AsText(geom) AS geom_wkt FROM your_table LIMIT 50;

or just keep the LIMIT low and don’t use “select *” in the grid.

Also make sure PostGIS is actually enabled in the same database you imported into (CREATE EXTENSION postgis;), and that you’re querying with a user that has normal schema/table privileges. But given your custom query works when you include geom, this is very likely a client/UI issue, not a permissions issue.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.