I'm running PostGIS on Cloud SQL for PostgreSQL 16 and experiencing significant performance issues with spatial operations compared to my local PostgreSQL environment. After investigation, I've found that the underlying geometry libraries are outdated:
Cloud SQL PostGIS:
Instance Type: 16 vCPU, 104GB RAM, 500GB SSD
PostGIS: 3.5.2
GEOS: 3.11.4
PROJ: 6.3.2
Local PostgreSQL (on less powerful hardware):
Hardware: Mac laptop with fewer resources than the cloud instance
PostGIS: 3.4.4
GEOS: 3.12.2
PROJ: 9.2.1
Performance Issue
The same spatial query runs 3-4x slower on Cloud SQL despite Cloud SQL having significantly more powerful hardware. My local machine is running with fewer CPU cores and less RAM, yet consistently outperforms the cloud instance. I've confirmed through EXPLAIN ANALYZE that each ST_Intersects operation takes approximately 6-7ms on Cloud SQL versus 2ms locally, which adds up significantly when processing thousands of operations.
Question
Is there a way to upgrade the GEOS and PROJ libraries on Cloud SQL to the latest versions? Or alternatively, is there a recommended approach for running PostgreSQL with the latest PostGIS libraries on GCP while maintaining a managed database experience?
I've already:
Updated PostGIS to version 3.5.2
Optimized database parameters
Ensured proper statistics and indexing
Verified the query plan is reasonable
Any guidance on getting access to newer versions of these spatial libraries in a GCP environment would be greatly appreciated.
Hi @blakgeek,
Welcome to Google Cloud Community!
It seems that the older versions of GEOS and PROJ installed on Cloud SQL are likely creating a bottleneck in performance compared to PostGresSQL running locally. Because Cloud SQL handles these libraries, directly upgrading them is not possible, but below are some action items that may help.
SELECT PostGIS_full_version();
ALTER EXTENSION postgis UPDATE TO 'latest_supported_version';
You may check the Cloud SQL extension documentation for their latest supported versions.If performance is still subpar, reach out to Google Cloud Support as they may offer other solutions.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.