29

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

Martin F
  • 8,948
  • 36
  • 58
djq
  • 16,297
  • 31
  • 110
  • 182

7 Answers7

24

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

alidman
  • 108
  • 3
Andrea Cremaschi
  • 537
  • 5
  • 10
5

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.

Glorfindel
  • 1,096
  • 2
  • 9
  • 14
Ragi Yaser Burhum
  • 15,339
  • 2
  • 59
  • 76
4

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

thayer
  • 141
  • 7
dmci
  • 4,882
  • 2
  • 19
  • 31
  • Seems I get "PostgreSQL support: yes" in ./configure output, but trying to ogr2ogr -f PostgreSQL gives ERROR 1: Unable to find driver 'PostgreSQL'. Also, no PostgreSQL in ogrinfo --formats – adamczi Nov 14 '18 at 00:53
  • have you run ldconfig after the installation? – dmci Nov 14 '18 at 08:44
  • 1
    See the edit to the answer about installing postgresql-server-dev,, that should handle the error. – thayer Nov 27 '19 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 Jan 23 '20 at 03:27
3

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.

Michael
  • 31
  • 1
2

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.

user259060
  • 131
  • 2
1

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.

RyanKDalton
  • 23,068
  • 17
  • 110
  • 178
0

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

Luís de Sousa
  • 3,935
  • 1
  • 29
  • 61