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:

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 --recv-keys 8B48AD6246925553
apt-key adv --keyserver --recv-keys 7638D0442B90D010
echo 'deb 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] jessie-backports main" | sudo tee /etc/apt/sources.list.d/backports.list
gpg --keyserver --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 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 jessie main contrib non-free rpi
deb stretch main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src jessie main contrib non-free rpi
#deb stretch stable
pi@LoRaGateway:~ $ cat /etc/apt/sources.list.d/raspi.list
deb stretch main ui
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src 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