Install PostgreSQL on a Raspberry Pi

Erro while updating,

After I followed the steps to install POSTGRESQL, am unable to update Raspberry pi, I encountered this problem all the time.

Please help me to resolve this issue.

Am Installing Loraser, Lora app server on Raspberry pi 3

That is probably because the PostgreSQL apt repository does not provide ARM builds. Please check the Raspbian repository or the Debian jessie-backports repository: https://backports.debian.org/Instructions/

What you need is at least PostgreSQL 9.5+

I made some notes earlier which I have’t tested again, but you could try these (and please let us know what works and what needs to be changed):

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010
echo 'deb http://httpredir.debian.org/debian jessie-backports main contrib non-free' | sudo tee -a /etc/apt/sources.list.d/jessie-backports.list

apt-get -t jessie-backports -y install postgresql-9.6
systemctl enable postgresql@9.6-main

What actually worked for me:

sudo echo "deb [check-valid-until=no] http://archive.debian.org/debian jessie-backports main" | sudo tee /etc/apt/sources.list.d/backports.list
gpg --keyserver pgpkeys.mit.edu --recv-key  8B48AD6246925553      
gpg -a --export 8B48AD6246925553 | sudo apt-key add -

sudo apt-get update

sudo apt-get -t jessie-backports -y install postgresql-9.6
sudo systemctl enable postgresql@9.6-main

Just facing an issue: Error: initdb failed

Problems seems to be that psql is for the wring architecture:

pi@LoRaGateway:~ $ psql --version
Illegal instruction

pi@LoRaGateway:~ $ dpkg -S /usr/bin/psql
postgresql-client-common: /usr/bin/psql
pi@LoRaGateway:~ $ sudo apt list --installed | grep sql

WARNING: apt does not have a stable CLI interface yet. Use with caution in scripts.

libsqlite3-0/oldoldstable,now 3.8.7.1-1+deb8u4 armhf [installed]
postgresql-9.6/jessie-backports,now 9.6.6-0+deb9u1~bpo8+1 armhf [installed]
postgresql-client-9.6/jessie-backports,now 9.6.6-0+deb9u1~bpo8+1 armhf [installed,automatic]
postgresql-client-common/jessie-backports,now 181+deb9u1~bpo8+1 all [installed,automatic]
postgresql-common/jessie-backports,now 181+deb9u1~bpo8+1 all [installed,automatic]
postgresql-contrib-9.6/jessie-backports,now 9.6.6-0+deb9u1~bpo8+1 armhf [installed,automatic]

Any idea how to fix this?

Have you tried the PostgreSQL package that is included in the Rasbian Buster version (lastest Raspbian version).

Buster has postgres 11 wich needs another binutils version as shipped with jessie.

pi@LoRaGateway:~ $ sudo apt-get install postgresql-11
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:
 libc6-dev : Breaks: binutils (< 2.26) but 2.25-5+deb8u1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

What worked was using stretch:

pi@LoRaGateway:~ $ cat /etc/apt/sources.list
#deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi
#deb https://download.docker.com/linux/raspbian/ stretch stable
pi@LoRaGateway:~ $ cat /etc/apt/sources.list.d/raspi.list
deb http://archive.raspberrypi.org/debian/ stretch main ui
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspberrypi.org/debian/ jessie main ui
sudo apt-get update
sudo apt-get install postgresql-9.6

Works like a charm. I did not do apt-get upgrade yet.

Is there a need to stay with Jessie? Why not upgrade your Rasbian to Buster :slight_smile:

Currently the main reason is that the update takes quiet long on the PI 2 and we get the pre installed gateways. As long as I do not need to, I prefer to save time. Especially where the whole setup runs offline in this case :slight_smile:

For a fresh setup I would install the latest version.

1 Like