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

Yves Jacolin yjacolin at free.fr
Tue Aug 2 01:28:09 PDT 2016


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
>>>

Any idea?

Y.



More information about the gdal-dev mailing list