Step 5 (update): Installing PostgreSQL on my Raspberry Pi 1 and 2

Update on 25/Jun/2015
We have added the links to the compiled deb packages.
Skip to this section if you only want to download and install them.

This article is an updated version of our previous post where we explained how to install PostgreSQL on the Raspberry Pi.

Many exciting things have happened since then, but the main ones are that PostgreSQL is now at version 9.4 with plenty of improvements and, finally, a new model of our beloved credit-card-sized computer, the Raspberry Pi 2, was released.

Now, let’s cut to the chase and start installing PostgreSQL on it. Just to make things easier, the whole procedure listed here is supposed to work on both models of the Raspberry Pi (1 and 2).

Two alternatives

The first thing you have to do is choose which version of PostgreSQL to install and this is pretty straight forward: to compile or not to compile.


Well, on the current Raspbian Linux release (2015-05-05), which is the distribution recommended by the Raspberry Pi Foundation and the one we are using for this process, the only PostgreSQL present on the Raspbian repository is the version 9.1. If you dont mind about using a previous version, you can install it as you install any other Debian package through apt-get.

But, if you want the latest version of PostgreSQL, which is the 9.4 at the time we are writing this, you have to downloaded it from the PostgreSQL Apt Repository and compile it. Don’t worry, this sounds harder than it actually is and we have you covered.

To help you decide, the recommended PostgreSQL version to be used is always the latest, due to various improvements and new features included in every new release.

The installation details of both options are listed below:

PostgreSQL 9.1 from the Raspbian repository

Go to the terminal and type the command:

sudo apt-get install postgresql-9.1

That’s it. No, seriously, you are done! But then, what was the fun on that?

PostgreSQL 9.4 from the PostgreSQL Apt Repository

As the previous method, open a terminal and type the following commands. You can also copy-and-paste it to avoid any typing mistakes.

  1. Add the PostgreSQL Apt Repository (source)
echo "deb-src wheezy-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
  1. Import the repository signing key
wget -qO - | sudo apt-key add -
  1. Update the package list and upgrade the system
sudo apt-get update
sudo apt-get upgrade
  1. Install necessary tools
sudo apt-get install build-essential fakeroot
  1. Install all the dependencies needed
sudo apt-get build-dep postgresql-9.4
sudo apt-get build-dep postgresql-common
sudo apt-get build-dep postgresql-client-common
sudo apt-get build-dep pgdg-keyring
  1. Compile packages

    Do not run the compilation as root. The second line, which compiles postgresql-9.4, will take a long time to finish, so, it is recommended to use a remote session with screen or tmux. If you don’t know how to use them, just repeat the instruction in case any disconnection happens.
cd /tmp
apt-get source --compile postgresql-9.4
apt-get source --compile postgresql-common
apt-get source --compile postgresql-client-common
apt-get source --compile pgdg-keyring
  1. Create local repository
sudo mkdir /var/local/repository
echo "deb [ trusted=yes ] file:///var/local/repository ./" | sudo tee /etc/apt/sources.list.d/my_own_repo.list
cd /var/local/repository
sudo mv /tmp/*.deb .
dpkg-scanpackages ./ | sudo tee Packages > /dev/null && sudo gzip -f Packages
  1. Update package list
sudo apt-get update
  1. Finally, PostgreSQL-9.4 can be installed
sudo apt-get install postgresql-9.4

Feeling good? It was not that hard, was it? Now you have the latest version of the world’s most advanced open source database installed and ready to fly on your Raspberry Pi.

Download the deb packages

Ok, now that you know how to compile PostgreSQL and install it by yourself, I can show you a shortcut. Don’t get me wrong, the knowledge you have acquired compiling PostgreSQL by hand is well worth, but if you don’t want to wait for the compilation to finish, we have already compiled the packages for you and uploaded them to our Dropbox folder.

Just to be clear, if you want to download our compiled packages, you don’t have to follow any of the instructions explained on the previous sections. Could I have told you this before? Yes, of course I could, but then you wouldn’t have learned how to compile PostgreSQL, would you?

You just have to type the following in the terminal:

sudo mkdir /var/local/repository
cd /var/local/repository
sudo wget -O postgresql-9.4.4-raspbian.tgz
sudo tar -xvzf postgresql-9.4.4-raspbian.tgz
echo "deb [ trusted=yes ] file:///var/local/repository ./" | sudo tee /etc/apt/sources.list.d/my_own_repo.list
sudo apt-get update
sudo apt-get install postgresql-9.4

Done! We will update the Dropbox link on future PostgreSQL releases.

Independently of which method you choose, during the installation the user “postgres” is created with its home directory located in /var/lib/postgresql/. Usually on Raspbian Linux (the same for Debian and Ubuntu) PostgreSQL configuration files are stored in /etc/postgresql/9.4/main/, and data directory is stored in /usr/local/var/postgres/. Now it is possible to start/stop/restart the postmaster (the main process of a PostgreSQL server) using the command:

sudo service postgresql start|stop|restart

While tweaking the configuration file parameters, keep in mind that most of the changes should require a postmaster restart.

Thanks for all your comments and questions sent on the previous article. We hope this updated version solves the problems you were having to install PostgreSQL and, if it doesn’t, feel free to comment and send new questions here as well.

Last updated 2015-06-17 13:49:42 CEST

54 thoughts on “Step 5 (update): Installing PostgreSQL on my Raspberry Pi 1 and 2

  1. Pingback: Step 5: installing PostgreSQL on my Raspberry PI | Raspberry PG

      • Hi, Regis. The compilation has to be done with the normal user pi. On step 6 of the instructions above there is a warning asking: “Do not run the compilation as root.”. Also, there is no reason to create another user, as the user pi is automatically created when you install Raspbian. If you want you can create another user, of course, as in any other Linux distribution, but there is no need, as everything can be done with the pi user. The steps where root is needed are initiated with the sudo command.

        I’ve used the same instructions listed above to compile the packages that were uploaded to Dropbox.

        Tell me if you are having any problems to install the packages.

    • You are welcome, Mark. And we will compile on the Raspberry Pi the new PostgreSQL version (9.5) when it’s released and put on Dropbox as well, so stay tuned!

      About the need of doing tar -xvzf on the file downloaded from Dropbox, it is a needed step because the .tgz file you downloaded is where all the compiled packages are compressed in, so you have to decompress it using tar. It is one of the steps listed on the procedures above, so no problems there.

      • Hi there,

        Thanks for this tut. Was wondering when you were planning to put a compile for postgres 9.5 now that it’s released!
        Would be very helpful!

        • We are preparing a new post about upgrading to PostgreSQL 9.5. Meanwhile, if you want to compile the new postgres release, the same procedure listed on this blog works. You just have to change every “postgresql-9.4″ to “postgresql-9.5″ instead. And if you are using jessie instead of wheezy, change “wheezy-pgdg” to “jessie-pgdg”. Doing these changes, the compilation should work just fine.

          • Thanks so much for your work! What is the latest with 9.5? I tried the download changing 9.4.4 to 9.5, but “had issues”. This is on a pi3

    • Oh, Mark, now I see it. I usually don’t use the dash (-) on tar command, but it is supposed to work either way. The reason for sometimes use or not use the dash (-) is historical. In this post there is a good explanation: Unix & Linux Stack Exchange

      I’ve changed the post and included the dash to avoid any other problems. Thanks again for pointing that out.

  2. Thanks for the dropbox compiled release !
    When i tried to follow the first part of your guide ( i would like to use 9.4) i raised an error and the installation failed :-(

    • Hi. Ric. In which step did the error occur? What was the error? Did it give any error message? Give some details about what happened and we can sort it out.

      Do you want to compile the packages yourself and are following the “PostgreSQL 9.4 from the PostgreSQL Apt Repository” steps or you just want to install PostgreSQL 9.4 and are trying to download the deb packages from Dropbox? If you just want to install PostgreSQL without having to compile it, following the instructions to install it using the packages on Dropbox is a lot faster.

  3. Suggestions? Using deb packages. All prior steps performed successfully. Last step for installation fails on dependencies.

    [email protected]:/var/local/repository$ sudo apt-get install postgresql-9.4
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    postgresql-9.4 : Depends: postgresql-client-9.4 but it is not going to be installed
    Depends: postgresql-common (>= 142~) but 134wheezy4 is to be installed
    Recommends: postgresql-contrib-9.4 but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.
    [email protected]:/var/local/repository$

    • For what I understood you have downloaded the packages from the Dropbox folder. Did you execute in order all the steps listed? Have you updated the system (sudo apt-get update) before trying to install PostgreSQL?

      If yes, please list here the files you have under /var/local/repository with “ls /var/local/repository/” and also what you have inside the /etc/apt/sources.list.d/my_own_repo.list file with “cat /etc/apt/sources.list.d/my_own_repo.list“.

      • Yes, as I said: “Using deb packages. All prior steps performed successfully.” including sudo apt-get update.

        [email protected]:/var/local/repository$ ls -1 /var/local/repository

        [email protected]:/var/local/repository$ cat /etc/apt/sources.list.d/my_own_repo.list
        deb [ trusted=yes ] file:///var/local/repository ./


        • OK, I got it now. I had a modified /etc/apt/sources.list and some other files in /etc/apt/sources.list.d/ from previous projects. Deleted the extraneous stuff and now it is working fine.

          Thank you.

  4. Hi Rubens, thanks for the great support, works perfectly.

    Maybe you can help with this last step. Everything’s working on my linux machine, created a database, added some tables. Everything’s ok so far.

    But then I try to run a php website on my windows machine, the website opens, but I can’t access my postgres database.

    “phpinfo();” tells me:

    Configuration File (php.ini) Path /etc/php5/apache2
    Loaded Configuration File /etc/php5/apache2/php.ini
    Scan this dir for additional .ini files /etc/php5/apache2/conf.d
    Additional .ini files parsed /etc/php5/apache2/conf.d/10-pdo.ini
    PHP API 20100412
    PHP Extension 20100525

    PHP Extension Build API20100525,NTS

    I’ve changed postgres.conf with: listen_addresses = ‘*’ (and restarted postgres server)

    # IPv4 local connections:
    host all all trust
    # IPv6 local connections:
    host all all ::1/128 trust
    (and restarted postgres server)

    ‘netstat -na’ tells me:
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0* LISTEN

    I don’t know which part is not working. Should I have edited the ‘./configure’ before compilation? And if so, what should that be?

    If you can help me, would be great. (…I mean really great)

    • Congratulations Ed for successfully installing PostgreSQL. It’s nice that you are using it for your projects. Now, about connecting PHP to PostgreSQL, to allow remote connections into your database you have to basically do 3 things:

      1. On postgres.conf set listen_addresses = ‘*’. You have already done this. Good.

      2. On pg_hga.conf set from where the incoming connections will be accepted. As I don’t know your network settings, one way to solve this is accepting connections from anywhere, which would be like:

      host all all md5

      The key point here is the part, which allows any connection to be accepted. Because of this we also set the authentication method to md5, which will ask for a password for every connection made. You can find other options for setting pg_hba.conf here:

      3. The last thing to do is just create a password for the postgres user. To do this login to your Raspberry Pi as the normal user pi and enter the following on the terminal:

      sudo -iu postgres psql -c "\password postgres"

      Type the new password for the postgres user and confirm it. Make sure you remember it. If you have created another user inside your database you have to create a password for it as well in case you want to connect with it.

      I am planning to write another post about how to connect to PostgreSQL after installing it, but right now you can find these other posts helpful as well:

      You don’t have to change anything in ‘./configure’ before compilation. What happens is that PostgreSQL really takes security seriously and does not allow any remote connection right after is installed. In other words, only local connections are allowed, so any remote connection has to be set as we did above.

      Let me know if this has worked out for you.

      • Hi Rubens,

        Thanks for your reply. After a while I had to find out I didn’t install the correct library… (embarrassing smiley over here).
        Unfortunately my Pi gave up, so I’m continuing Postgres on windows. Will make a clean start with the Pi later. Thanks again.


  5. Hi, I followed the steps here, and have 9.3 installed:

    How can I now upgrade to 9.4?

    When I try the directions above I get this error… so now I am worried about having to uninstall 9.3 which was compiled from source… pls help…:

    Setting up postgresql-9.4 (9.4.4-1.pgdg70+1) …
    [....] Starting PostgreSQL 9.4 database server: main[....] The PostgreSQL server failed to start. Please check the log output: 2015-08-22 00:37:47 PDT [23944-1] LOG: could not bind IPv4 socket: Cannot assign requested address 2015-08-22 00:37:47 PDT [23944-2] HINT: Is another postmaster already running on port 5433? If not, wait a few seconds and retry. 2015-08-22 00:37:47 PDT [23944-3] LOG: could not create IPv6 socket: Address family not supported by protocol 2015-08-22 00:37:47 PDT [23944-4] WARNING: could not create listen socket for “localhost” 2015-08-22 00:[FAIL PDT [23944-5] FATAL: could not create any TCP/IP sockets … failed!
    invoke-rc.d: initscript postgresql, action “start” failed.
    dpkg: error processing postgresql-9.4 (–configure):
    subprocess installed post-installation script returned error exit status 1
    dpkg: dependency problems prevent configuration of postgresql-contrib-9.4:
    postgresql-contrib-9.4 depends on postgresql-9.4 (= 9.4.4-1.pgdg70+1); however:
    Package postgresql-9.4 is not configured yet.

    dpkg: error processing postgresql-contrib-9.4 (–configure):
    dependency problems – leaving unconfigured
    Errors were encountered while processing:
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    • Hi John,

      The instructions elaborated on this post, as well as on the first one, are indicated for new installs, not for upgrades. But, just to mention, on Raspbian and any other Debian derivative, it’s possible to have different PostgreSQL major versions installed and working side by side, as 9.3 and 9.4 in your case. Before continuing, you have to decide what you want to do:

      - keep both major versions installed and working together
      - upgrade to the new major version (9.4) and keep your data, in case you have important data to keep

      If you don’t have any important data to keep and want to start a new database from zero, the easiest thing to do would be uninstall both PostgreSQL on your Raspberry Pi and redo the procedure listed on this post, making sure that all the files mentioned don’t have any extra information on them.

      If you want to upgrade version keeping your existent data, there are mainly 3 ways of upgrading a PostgreSQL major version (e.g. 9.3 to 9.4). It is pretty straightforward, as long as the preparation and execution are followed in order, but the point is that Upgrading is a complete new blog post by itself, and if I elaborate the procedure here it will, probably, generate more questions from users here on the comments, which doesn’t have a good layout to answer many questions. I’m planning of doing a post about upgrading on PostgreSQL, but for now I think the following places can help, after you decide what you want to do:

      - easy and complete step by step set of instructions to upgrade:

      - option using pg_upgrade:

      - independently of what you want to do, reading the PostgreSQL docs will give you a better understanding of the process and your options:

      Just a tip about the error message you are having: PostgreSQL uses the port 5432 by default. To have different versions installed, they have to be set to use different ports, for example 9.3 on port 5432 and 9.4 on port 5433. You are receiving a message telling you that there is already a database using the port 5433. Search for “port =” on /etc/postgresql/_version_/main/postgresql.conf on both versions and confirm they aren’t using the same port.

      Hope this can help you.

  6. Please help. I keep getting the following error when running ‘sudo apt-get update’:

    W: GPG error: experimental Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 8B48AD6246925553 NO_PUBKEY 7638D0442B90D010

  7. Excellent article. Installed without any hiccups… thanks for your diligent work.

    Can you explain or point me to information on how I configure postgres after the install. On a CENTOS system I had to edit postgresql.conf to specify IP address and Port to listen to… and I had to edit pg_hba.conf to allow remote access. Could you advise if I need to do the same for the Raspian Install?

    • Hi marvcode,

      Thanks for your comment and congratulations for starting on PostgreSQL.
      About your question, PostgreSQL is really concerned about security and only allows local connections after it is installed, thus you have to configure it to allow remote connections. This is the same behavior on any Linux distribution (any OS, actually), so you have to configure it on Raspbian as you did on CentOS. You can find more details on a previous answer or, as always, on PostgreSQL documentation.

  8. Thanks, the install went well, though it did ask if these packages could be installed without verification (which I did). Is this normal, or should they have been authenticated somehow?

    • Hi Robert,

      Yes, it is normal to be warned or asked by your Linux distribution when installing packages from non official places, as it is in this case where you are installing the packages that we have uploaded to Dropbox. These packages are not officially recognized by Raspbian, or course. For security reasons your system has to ask you if you are sure on installing them, so it is always up to you on these cases and the recommendation is to only do the installation when you are completely sure that the packages are safe. We are in the process of creating our own repository with security keys, which will avoid these kind of warnings on your system.

  9. I’ve just noticed that “sudo apt-get install postgresql” now retrieves version 9.4 – that might help some people.

  10. I am actually trying to install the postgresql-client on raspbian so that I can connect the raspberry pi to a Windows Server 2008 box that is running the Postgres Server and display data from the Windows Server on the Raspberry through PHP (auto refreshed website showing database information).

    I’ve installed the following packages.

    postgresql-client postgresql
    php5 libapache2-mod-php5 php5-mysql
    unixodbc unixodbc-dev

    So that I can retrieve data from the database located on the Windows Server and display this data on a Kiosk that is powered by my Raspberry Pi 2 running raspbian jessie.

    I have been completely unsuccessful in my attempts at this project. I know it is possible as I have seen it done somewhere else.

    All packages above install successfully.

    I cannot get the psql client to connect to server.
    I cannot configure odbc.ini and odbcinst.ini for unixodbc as there is no driver that I can find in my install packages for postgresql. Other sites refer to drivers named or but they do not exist on my pi after I install postgres? I have even installed mlocate and updated the db so that I can search for these drivers on my pi to configure for unixodbc, but they simply don’t exist. If you download the client installer from pervasive, the drivers are in that tar package, but obviously I can’t compile a 32bit package on the raspberry as it is arm.

    I can’t even get psql to even do a simple connection to my windows box within the raspbian terminal. When I try and connect, it will either throw an error or nothing at all. When the nothing happens, no one on my network can access the database until I kill the command on the raspberry, then the database performs normal immediately following the kill command. (I have to reboot wheezy to finally kill the connection attempt. Jessie will let me break the connection attempt with Control-C.)

    Any help or direction is greatly appreciated.

    • I realized my problem, but still don’t have a solution and this forum is more about PostgreSQL than Pervasive, but I wanted to post my findings.

      I made the assumption that Pervasive SQL (PSQL) and PostgreSQL (PSQL) were the same. But even though both install packages have directories labeled PSQL, they are in fact not compatible with each other.

      • Thanks for getting back, Paul. I was actually trying to figure out your problem, but now everything makes sense :-) . PostgreSQL and Pervasive PSQL are completely and absolutely different things. Just for starters PostgreSQL is 100% open source, in opposite to Pervasive SQL that is proprietary software. Unfortunately I cannot help you with Pervasive, but if you start on some PostgreSQL projects feel free to send your questions.

      • Hi Paul,

        Have you found a solution to connect to a Pervasive SQL server from a raspberry Pi? I have the same problem now, I can’t seem to find a solution.

        All help or pointers highly appreciated!


  11. Pingback: Compiling Postgis 2.2.0 on Raspian error doesn't install postgis extension | Question and Answer

  12. Hi guys, awesome posts, I’ve used this site for setting up my raspberrypi2 with wheezy previouly and it worked wonderfully, but now that I got the raspberrypi2 with jessie, I’m getting an error in one of the tests at the end of the compilation. I followed each step carefully and the result is this:

    t/ ..
    ok 1 – pg_ctl –help exit code 0
    ok 2 – pg_ctl –help goes to stdout
    ok 3 – pg_ctl –help nothing to stderr
    ok 4 – pg_ctl –version exit code 0
    ok 5 – pg_ctl –version goes to stdout
    ok 6 – pg_ctl –version nothing to stderr
    ok 7 – pg_ctl with invalid option nonzero exit code
    ok 8 – pg_ctl with invalid option prints error message
    ok 9 – pg_ctl initdb
    ok 10 – configure authentication
    ok 11 – pg_ctl start -w
    not ok 12 – second pg_ctl start succeeds

    # Failed test ‘second pg_ctl start succeeds’
    # at /tmp/postgresql-9.4-9.4.5/build/../src/test/perl/ line 204.
    ok 13 – pg_ctl stop -w
    ok 14 – second pg_ctl stop fails
    ok 15 – pg_ctl restart with server not running
    ok 16 – pg_ctl restart with server running
    # Looks like you failed 1 test of 16.
    Dubious, test returned 1 (wstat 256, 0×100)
    Failed 1/16 subtests
    t/ ……
    ok 1 – pg_ctl status with server not running
    ok 2 – pg_ctl status with server running

    Test Summary Report
    t/ (Wstat: 256 Tests: 16 Failed: 1)
    Failed test: 12
    Non-zero exit status: 1
    Files=2, Tests=18, 80 wallclock secs ( 0.23 usr 0.04 sys + 24.45 cusr 5.66 csy s = 30.38 CPU)
    Result: FAIL
    Makefile:42: recipe for target ‘check’ failed
    make[4]: *** [check] Error 1
    make[4]: Leaving directory ‘/tmp/postgresql-9.4-9.4.5/build/src/bin/pg_ctl’
    Makefile:25: recipe for target ‘check-pg_ctl-recurse’ failed
    make[3]: *** [check-pg_ctl-recurse] Error 2
    make[3]: Leaving directory ‘/tmp/postgresql-9.4-9.4.5/build/src/bin’
    GNUmakefile:69: recipe for target ‘check-world-src/bin-recurse’ failed
    make[2]: *** [check-world-src/bin-recurse] Error 2
    make[2]: Leaving directory ‘/tmp/postgresql-9.4-9.4.5/build’
    debian/rules:182: recipe for target ‘override_dh_auto_test’ failed
    make[1]: *** [override_dh_auto_test] Error 1
    make[1]: Leaving directory ‘/tmp/postgresql-9.4-9.4.5′
    debian/rules:101: recipe for target ‘build’ failed
    make: *** [build] Error 2
    dpkg-buildpackage: error: debian/rules build gave error exit status 2
    Build command ‘cd postgresql-9.4-9.4.5 && dpkg-buildpackage -b -uc’ failed.
    E: Child process failed

    Any ideas if this will affect the usage of my db?

    Thanks again!

    • Hi Johan. With the output you’ve sent it’s not possible to have a clear idea of what is going wrong. What is this test you are doing? Are you running this after the PostgreSQL compilation and installation process has been complete? Are you doing this on a fresh Raspbian Jessie install? Is there a PostgreSQL already installed on the SDcard?

      Have in mind that the procedure listed on this post is for compiling and installing PostgreSQL 9.4 on the Raspbian Wheezy. If you are using the new Raspbian Jessie on your Raspberry Pi there is no need to compile PostgreSQL 9.4 as Jessie has it already on its repository, therefore a simple “sudo apt-get install postgresql-9.4″ should be enough to install PostgreSQL 9.4. Of course you can still compile it from the PostgreSQL Apt repository if you want, but you have to change the line on the related instruction “1. Add the PostgreSQL Apt Repository (source)” from:

      echo "deb-src wheezy-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list


      echo "deb-src jessie-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list

      To answer your question, if you have PostgreSQL already installed and working on your Raspberry Pi, the error that you have reported is not suppose to affect your db, as nothing has been reinstalled, apparently.

  13. Hi there, I installed postgresql 9.4 following your excellent instructions, then ran into the problem detailed in the log below. Short version: I need to compile some native extensions and the ruby gem install program for pg 0.18.4 choked on this. Apparently I need header files from the development version. Could you advise me on how to proceed? Thanks so much!

    Installing pg 0.18.4 with native extensions

    Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/pi/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20160215-18178-1vgceb2.rb extconf.rb
    checking for pg_config… yes
    Using config values from /usr/bin/pg_config
    You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
    You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
    checking for libpq-fe.h… no
    Can’t find the ‘libpq-fe.h header
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of necessary
    libraries and/or headers. Check the mkmf.log file for more details. You may
    need configuration options.

    • My goal is to compile C programs that use PostgreSQL.

      sudo apt-get install didn’t do it.

      I secretly hoped it wouldn’t, because then I could compile PostgreSQL from source. I get _exactly_ the PostgreSQL that works for me.

      It worked first time.
      libpq and libpq-fe.h were there.

      I used git to download PostgreSQL to get the latest, greatest version.

      The compile ran at a good clip. I was able to see the module names. On my Intel box, they scroll by so fast I can’t see them.

      After installation, I had to do some thingies from the command line, like
      ln -s /usr/local/pgsql/bin/psql /usr/local/bin/pgsql
      to make it available in the PATH

      Here’s my script, plus chatter:
      [[email protected] Downloads]$ cat my_PostgreSQL


      echo $LINENO ‘Run’ $pgm
      echo $LINENO ‘In directory’ `pwd`
      pushd .
      set -e
      echo $LINENO ‘sudo apt-get install readline-dev’
      echo $LINENO ‘sudo apt-get install libssl-dev’
      echo $LINENO ‘sudo apt-get install bison’
      echo $LINENO ‘sudo apt-get install flex’
      echo $LINENO ‘After successful compile, put it in your $PATH:’
      echo $LINENO ‘sudo ln -s /usr/local/pgsql/bin/psql /usr/local/bin/psql’
      echo $LINENO ‘Check whether it is the right one: which psql’
      sleep 4

      read -p ‘make clean? [yN]: ‘

      if [[ "$REPLY" == "y" ]]

      echo $LINENO ‘make_clean =’ $make_clean’.’

      sleep 4

      if [[ -d "$dir" ]]
      cd “$dir”
      echo $LINENO ‘Changed to directory’ “$dir” ‘for git pull.’
      git pull
      mkdir “$dir”
      echo $LINENO ‘Created directory’ “$dir” ‘for git clone.’
      git clone git:// “$dir”
      cd “$dir”
      echo $LINENO ‘Changed to directory’ “$dir”

      ./configure –help >

      ./configure \
      –enable-calendar \
      –enable-mbstring \
      –enable-pdo \
      –with-apxs2=/usr/local/apache2/bin/apxs \
      –with-gd \
      –with-mhash \
      –with-mysql \
      –with-mysqli \
      –with-openssl \
      –with-pdo-mysql \
      –with-pdo-pgsql \
      –with-pdo-sqlite \
      –with-pear \
      –with-pgsql \
      –with-sqlite \

      if [[ "$make_clean" == "y" ]]
      echo $LINENO ‘making clean.’
      make clean
      echo $LINENO ‘Skipping make clean.’

      sudo make install

      echo $LINENO ‘Making contributed modules’
      sleep 7
      cd contrib
      make all
      sudo make install

      tput sgr0


      echo $LINENO ‘Ran’ $pgm
      [[email protected] Downloads]$

      Yes, it’s wordy…but it works.

  14. Thanks Rubens !
    Tried now with RPI3 and PostgreSQL 9.5 and it works fine…. :) Wooow
    I would like to try install Postgis extension. Any ideia ?

Leave a Reply to Theodore (Ted) M. Rolle, Jr. Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>