[gdal-dev] Closing connection in Python gdal (too many clients already)

Yves Jacolin yjacolin at free.fr
Tue Aug 2 02:02:59 PDT 2016


On Tuesday, August 02, 2016 10:50:15 Even Rouault wrote:
> On Tuesday 02 August 2016 10:28:09 Yves Jacolin wrote:
> > Bonjour Even,
> > 
> > On Tuesday, August 02, 2016 9:42:56 Even Rouault wrote:
> > > Salut Yves,
> > > 
> > > > I am using gdal 2.1.1 in python.
> > > > 
> > > > When I import several layers into postgis I get a FATAL error :
> > > > 'sorry,
> > > > too
> > > > many clients already'. It seems I don't close the connection after
> > > > each
> > > > import.
> > > > 
> > > > I open the connection with dstDS = gdal.OpenEx(connectionString). how
> > > > can
> > > > I
> > > > close the connexion? I can't find any method
> > > 
> > > You just need to drop any reference to the dataset, so, assuming it is
> > > not
> > > assigned to another variable, with dstDS = None or del dstDS.
> > > 
> > > See the "Saving and closing datasets/datasources" section at
> > > https://trac.osgeo.org/gdal/wiki/PythonGotchas
> > > 
> > > Note: assuming you import layers from the same database, it will be (a
> > > tiny
> > > bit) more efficient if you re-use the same dataset object.
> > 
> > I tried both `del dstDS` and `dstDS = None`, but I still have the problem.
> > I tried also to open just one connexion (see code below), but the problem
> > is still there. I guess this is an other issue. Could the OGR import is
> > still active when I import another file?
> > 
> > 
> > dstDS = gdal.OpenEx(connectionString)
> > 
> > for id in idList:
> >     srcDS = gdal.OpenEx('/tmp/file_' + str(id) + '.geojson')
> >     
> >     gdal.VectorTranslate(
> >     
> >      dstDS,
> >      srcDS,
> >      format = 'PostgreSQL',
> >      layerName='myLayer'
> >    
> >    )
> >    del srcDS
> > 
> > del dstDS
> 
> Ah indeed, it is a different issue.
> 
> gdal.VectorTranslate() doesn't currently properly handle the situation where
> you pass a dstDS object but not specify accessMode to be 'append', 'update'
> or 'overwrite'. So try adding accessMode = 'append' as an extra argument to
> gdal.VectorTranslate() (if the intent is to append to the same layer) Could
> you open a ticket about that ? (in your situation where accessMode is not
> specified but dstDS is specified, accessMode = 'update' should be the
> default behaviour)
> 
> And you should also open dstDS with
> 
> dstDS = gdal.OpenEx(connectionString, gdal.OF_UPDATE | gdal.OF_VECTOR)
> 
> Even
Thanks Even! It works now.

Here is theticket, https://trac.osgeo.org/gdal/ticket/6612. I hope my 
information is enough (I copy past you comment as it seems more helpful).

Y.


More information about the gdal-dev mailing list