I'm trying to use ogr2ogr to upload a shapefile to a remote PostGres installation. When I ran this command:
celenius:~ celenius$ ogr2ogr -f PostgreSQL PG:"host=255.34.00.00 user=postgres dbname=mydb password=***" Dropbox/data/roads.shp;
I got the following error message:
Unable to find driver `PostgreSQL'.
The following drivers are available:
-> `ESRI Shapefile'
-> `MapInfo File'
-> `UK .NTF'
...
-> `SVG'
-> `CouchDB'
-> `Idrisi'
-> `ARCGEN'
-> `SEGUKOOA'
-> `SEGY'
(I omitted some of the drivers as they are not relevant). Is there a way that I can update ogr2ogr to include PostgreSQL? I'm using a Mac with OS 10.7.4
7 Answers 7
Using Homebrew you should:
brew install gdal --with-postgresql
or with older versions of gdal:
brew install gdal --with-postgres
if you have already installed gdal with brew before but without postgresql support, just
brew uninstall gdal
-
2a small correction:
brew install gdal --with-postgresql
BenjaminGolder– BenjaminGolder2014年01月16日 22:02:56 +00:00Commented Jan 16, 2014 at 22:02 -
Will QGIS still work with the homebrew GDAL?Simbamangu– Simbamangu2014年04月16日 08:20:11 +00:00Commented Apr 16, 2014 at 8:20
-
1Well it used to work but something seems to be changed with dependencies.. see this Q&A: gis.stackexchange.com/questions/79251/…Andrea Cremaschi– Andrea Cremaschi2014年04月16日 12:14:18 +00:00Commented Apr 16, 2014 at 12:14
-
2How would you proceed on a windows machine? Ideally using a virtualenvRutgerH– RutgerH2016年12月07日 21:41:54 +00:00Commented Dec 7, 2016 at 21:41
-
2what is solution for windows please?Denis Stephanov– Denis Stephanov2017年02月21日 16:03:38 +00:00Commented Feb 21, 2017 at 16:03
Save yourself some pain and use the Kyngchaos packaged binaries/frameworks for OSX.GDAL-Complete is the one you are looking for.
Another option is to use HomeBrew.
-
AFAIK this is what I used. I didn't install it any other way.djq– djq2012年09月12日 21:48:37 +00:00Commented Sep 12, 2012 at 21:48
-
Does this file exist: /Library/Frameworks/GDAL.framework/Versions/Current/Libraries/libpq.dylib and what does the 'which ogrinfo' command return from the terminal?Ragi Yaser Burhum– Ragi Yaser Burhum2012年09月12日 23:05:22 +00:00Commented Sep 12, 2012 at 23:05
-
which ogrinfo
returns/usr/local/bin/ogrinfo
. I installed GDAL and others from KyngChaos before installing QGis.djq– djq2012年09月12日 23:24:15 +00:00Commented Sep 12, 2012 at 23:24 -
Does the libpq file I mentioned exist in that location?Ragi Yaser Burhum– Ragi Yaser Burhum2012年09月12日 23:37:28 +00:00Commented Sep 12, 2012 at 23:37
-
1If libpq.dylib is not there (the PostgreSQL client library), the OGR library will not load.Ragi Yaser Burhum– Ragi Yaser Burhum2012年09月14日 22:14:07 +00:00Commented Sep 14, 2012 at 22:14
assuming you've compiled gdal from source, just include --with-pg=/path/to/pg_config when you're configuring gdal.
./configure -with-pg=/path/to/pg_config ...
./make clean
./make
./make install
EDIT: Note that pg_config
should be in the same directory with your other PostgreSQL binaries, like psql
, etc.. Also note, this detail from user259060's answer below: you should verify that an appropriate postgresql-server-dev version is installed (e.g. on Ubuntu use apt list --installed | grep postgresql-server-dev
if not found use apt-cache search postgresql-server-dev
and install the corresponding package with sudo apt-get install postgresql-server-dev
).
-
Seems I get "PostgreSQL support: yes" in
./configure
output, but trying toogr2ogr -f PostgreSQL
givesERROR 1: Unable to find driver 'PostgreSQL'
. Also, noPostgreSQL
inogrinfo --formats
adamczi– adamczi2018年11月14日 00:53:40 +00:00Commented Nov 14, 2018 at 0:53 -
have you run ldconfig after the installation?dmci– dmci2018年11月14日 08:44:11 +00:00Commented Nov 14, 2018 at 8:44
-
1See the edit to the answer about installing postgresql-server-dev,, that should handle the error.thayer– thayer2019年11月27日 15:44:46 +00:00Commented Nov 27, 2019 at 15:44
-
I think two hyphens in front of with-pg? As in,
./configure --with-pg=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
Mark Egge– Mark Egge2020年01月23日 03:27:09 +00:00Commented Jan 23, 2020 at 3:27
I got this same message while on Windows.
It was complaining about the type of quotes (single vs. double) I was using around the connection string. Switching the quotes fixed the issue.
There is a possibility that you might see something like "PostgreSQL support: no", even though you have configured the source using "--with-pg=/path/to/pg_config"...in that case, run sudo apt-get install postgresql-server-dev-all and then retry.
From reading the ogr2ogr Vector formats doc, it looks like you need to install the PostgreSQL client library (libpq).
This similar question seems to give some insight into resolving a similar issue, just with Python bindings.
On Ubuntu 18.04 (and possibly other versions), a Postgres wrapper for OGR is available from the package postgresql-11-ogr-fdw
. This is for version 11 of Postgres, as it needs to match the version of the client.
For the list the different versions of this package, for the different versions of Postgres use the following:
aptitude search postgres | grep ogr-fdw
Explore related questions
See similar questions with these tags.