After installing PostgreSQL 9.4 and PostGIS following An Almost Idiot's guide to installing PostgreSQL, PostGIS, and pgRouting, on my CentOS 6.7 64-bit except replacing 9.3 references with equivalent 9.4 reference, I then proceeded to install ogr_fdw. To my disappointment, there are no binaries yet for that, which is not surprising, considering there aren't generally any binaries for any OS, except the windows ones I built which I will be packaging with PostGIS 2.2 windows bundle. Getting out of my windows comfort zone, I proceeded to build those on CentOS. Mainly because I have a client on CentOS where ogr_fdw I think is a perfect fit for his workflow and wanted to see how difficult of a feat this would be. I'll go over the steps I used for building and stumbling blocks I ran into in this article with hope it will be of benefit to those who find themselves in a similar situation.
UPDATE pgdg yum now has ogr_fdw as an offering. If you are on PostgreSQL 9.4, you can now install with : yum install ogr_fdw94
I should add I also experimented with building stuff from PGXN registry on my CentOS box, and one big peeve I have about that, is that for less than trivial extensions, you've got to go searching for the dependencies yourself. Not like some other extension systems like Node (NPM) and Python Pip that just install these things for you or warn you if they can't. At the very least it would be nice if it gave such a message rather than often cryptic ones. I know I'm spoiled, but I can dream. I'll save using PGXN for another article.
I'll start off with a couple of stumbling blocks you may have if you are new to compiling stuff on Linux. Most Linux/Unix folks can skip these sections, since they probably are already setup.
Everytime I spin up a Linux VM, it for some reason never has these things installed.
You need gcc-c++ and git
As with all platforms where you intend to compile stuff like PostGIS and PostgreSQL extensions, you need a functioning gcc-c++. You know you don't have one when you get messages like: No way to build binaries
sudo yum install gcc-c++
Should fix that
ogr_fdw not currently in pgxn, got to get from git repo
If you don't have git client already installed, just run this:
sudo yum install git
You need GDAL Develop and PostgreSQL develop
When you install PostGIS / PostgreSQL via Yum, it installs all needed to run PostGIS, which includes GDAL, but not necessarily GDAL development or PostgreSQL develop package. So if you do this:
chmod -R 777 /sources #this is needed for installcheck to work to give postgres daemon access
git clone -b master https://github.com/pramsey/pgsql-ogr-fdw.git pgsql_ogr_fdw
export PATH=/usr/pgsql-9.4/bin:$PATH # this is needed because pg_config is not in path
make && make install
The make installcheck part is very finicky because the postgres service account needs rights to read the data folder to reference the test dbf and on top of that you need to be a superuser
to build the foreign. So don't be too upset if your installcheck yields failure instead of:
(using postmaster on Unix socket, default port)
============== dropping database "contrib_regression" ==============
============== creating database "contrib_regression" ==============
============== running regression test queries ==============
test ogr_fdw ... ok
All 1 tests passed.
Using ogr_fdw in a database
Well first you install the extension in your database with a
CREATE EXTENSION postgis; --only needed if you want to connect to a spatial datasource
CREATE EXTENSION ogr_fdw;
My next test will be to experiment with UnixODBC to see if I can connect my windows SQL Server install to my CentOS PostgreSQL install.
For windows users, reading this. I've had a change of heart, and will be putting CURL support back in and with SSL support. I managed to get my curl binaries to use the packaged
EDB ssleasy32 and libeay32.dll by making sure I compile against the same version (and no higher).