I just installed Ubuntu Server 22.04.1 on a Raspberry Pi 4 in order to use it as a postgreslql server.
Unfortunately, for compatibility reasons, I can't use a current postgresql version, but needed to install a 10.x version.
The only way to get such an old version installed was by using the postgresql10 snap package.
So far it works. I can start it and create databases and tables with psql.
But now I need to do 2 more things:
- Run postgresql when system is booted
- Make it accessable over the (local) network
I searched a lot about how to do that, but I can't figure out how to do it in my case. All examples I can find are targeted to apt installations.
What I tried so far:
- How I installed:
sudo snap install core
sudo snap install postgresql10
adduser postgres
sudo su postgres
postgresql10.initialize newlocale en_US UTF-8
postgresql10.initialize initdb en_US UTF-8
postgresql10.pgctl -D /home/postgres/snap/postgresql10/common/data start
After that, postgresql is running and ps lists a couple of postgresql processes.
snap info lists the following commands, which are working:
postgres@Pi4DBServer:/etc$ snap info postgresql10
name: postgresql10
summary: PostgreSQL is a powerful, open source object-relational database system.
publisher: Command Prompt, Inc. (cmd✓)
store-url: https://snapcraft.io/postgresql10
license: unset
description: |
PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years
of active development and a proven architecture that has earned it a strong reputation for
reliability, data integrity, and correctness.
commands:
- postgresql10.clusterdb
- postgresql10.createdb
- postgresql10.createuser
- postgresql10.dropdb
- postgresql10.dropuser
- postgresql10.ecpg
- postgresql10.initdb
- postgresql10.initialize
- postgresql10.oid2name
- postgresql10.pgarchivecleanup
- postgresql10.pgbasebackup
- postgresql10.pgbench
- postgresql10.pgconfig
- postgresql10.pgcontroldata
- postgresql10.pgctl
- postgresql10.pgdump
- postgresql10.pgdumpall
- postgresql10.pgisready
- postgresql10.pgreceivewal
- postgresql10.pgrecvlogical
- postgresql10.pgresetwal
- postgresql10.pgrestore
- postgresql10.pgrewind
- postgresql10.pgtestfsync
- postgresql10.pgtesttiming
- postgresql10.pgupgrade
- postgresql10.pgwaldump
- postgresql10.postgres
- postgresql10.postmaster
- postgresql10.psql
- postgresql10.reindexdb
- postgresql10.vacuumdb
- postgresql10.vacuumlo
snap-id: W7TagWOq55vJphD3Ek4ZUtQytGRMeQqK
tracking: latest/stable
refresh-date: today at 13:53 CEST
channels:
latest/stable: 10.4 2018-05-11 (46) 38MB -
latest/candidate: ↑
latest/beta: ↑
latest/edge: ↑
installed: 10.4 (46) 38MB -
But after rebooting the system I have to manually start it again. And if I try to connect to the database from another machine with pgAdmin I get an "connection to server failed" error.
- What I tried to make it run after system boot
Put it into /etc/rc.local like this:
#!/bin/bash
su postgres -c "postgresql10.pgctl -D /home/postgres/snap/postgresql10/common/data start"
exit 0
And called chmod a+x
on it.
-> Nothing happend
Then tried using systemctl:
When just trying to call sudo systemctl start/enable postgresql.service
it gives an error that Unit postgresql.service has not been found.
So I created a file "postgresql10.service" in "/etc/systemd/system" with the following content:
[Unit]
Description="Postgresql 10 Startup"
[Service]
ExecStart=su postgres -c "postgresql10.pgctl -D /home/postgres/snap/postgresql10/common/data start"
Type=simple
[Install]
WantedBy=multi-user.target
Then called sudo systemctl enable postgresql10.service
. Finishes without console output (Which I consider to be successful), but after reboot no postgreslql processes are running.
Also called sudo systemd-analyze verify postgresql10.service
and sudo systemctl daemon-reload
after enabling. Both finish without output, but seem to have no effect.
When I call sudo systemctl start postgresql10.service
it starts some postgresql processes, but trying to use postgresql10.psql says "could not connect to server: No such file or directory ..."
- Making it accessable over the network
I followed the step described here: https://tecadmin.net/postgresql-allow-remote-connections/
Added this line to postgresql.conf:
listen_addresses = '*'
And those 2 to pg_hba.conf:
host all all 0.0.0.0/0 md5
host all all :/0 md5
But when stopped and started again, postgresql refuses to start with the following message:
pi@Pi4DBServer:~$ sudo su postgres -c "postgresql10.pgctl -D /home/postgres/snap/postgresql10/common/data start"
waiting for server to start....2022-10-27 16:06:05.080 CEST [1220] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-10-27 16:06:05.080 CEST [1220] LOG: listening on IPv6 address "::", port 5432
2022-10-27 16:06:05.089 CEST [1220] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-10-27 16:06:05.156 CEST [1220] LOG: specifying both host name and CIDR mask is invalid: ":/0"
2022-10-27 16:06:05.156 CEST [1220] CONTEXT: line 95 of configuration file "/home/postgres/snap/postgresql10/common/data/pg_hba.conf"
2022-10-27 16:06:05.156 CEST [1220] FATAL: could not load pg_hba.conf
2022-10-27 16:06:05.162 CEST [1220] LOG: database system is shut down
stopped waiting
pg_ctl: could not start server
Examine the log output.
Now I removed the second line (The one with ":/0") from "pg_hba.conf" and it was able to start, but when I try connecting with pgAdmin I get an error saying "FATAL: No pg_hba.conf entry for host"
So now I'm stuck, I have no clue what to try next on both issues...
Or if there is another possibility to get an 10.x Server running on Raspberry Pi (Which is actually all I wanted to do)
Please help