OGR (GDAL) provides a vector driver for "PostgreSQL" and data in the DB can be accessed with something like the following:
driver = ogr.GetDriverByName("PostgreSQL")
datasource = driver.Open("PG:host=localhost port=5432 user=postgres password=postgres")
layer = datasource.GetLayerByName("geo_table_name")
print(f"{layer.GetName()} has {layer.GetFeatureCount()} feature(s)")
This approach abstracts and obscures the database connection, and as a result we do not appear to have control over connection pooling.
I intend to use OGR PostgreSQL in an API and there could potentially be significant variation in the number of postgres datasource "connections", varying by load. I would like to know if there is an established pattern for managing database connections in OGR, if I am required to implement something myself, or if the idea itself is fundamentally flawed in some way.
Can OGR PostgreSQL connections come from a connection pool, or is there an established approach for ensuring the number of connection attempts does not grow unsustainably under load?