Skip to content

Setup PostgreSQL on Raspbian (Stretch)

OllisGit edited this page Oct 12, 2020 · 5 revisions

Setup PostgreSQL

Installation

Install the postgresql package:

$ sudo apt install postgresql

Create new user and database

Switch to the postgres user:

$ sudo -u postgres -i

Create user octoprint:

[postgres]$ createuser --interactive -P

Enter name of role to add: octoprint
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n

Create database octoprint_filamentmanager:

[postgres]$ createdb -O octoprint octoprint_filamentmanager

Configure PostgreSQL for local network

Per default PostgreSQL only accepts connections from localhost. To make the database server available in your network you have to modify two config files.

In the /etc/postgresql/9.6/main/postgresql.conf change the line with listen_addresses to

listen_addresses = '*'

Then append the following line to /etc/postgresql/9.6/main/pg_hba.conf

host octoprint_filamentmanager octoprint 192.168.178.0/24 md5

Adapt the IP address to your network, e.g. if your server has the IP 192.168.0.25 use 192.168.0.0/24 instead. This allows all clients in your network to access the database. For more information see https://en.wikipedia.org/wiki/Subnetwork

The final step is to restart the PostgreSQL service:

$ sudo systemctl restart postgresql.service

Configure FilamentManager

Follow the instructions from the Arch Linux setup guide.

If you encounter issues during the installation of the psycopg2 package make sure you have all required dependencies installed.

$ sudo apt-get update
$ sudo apt-get install python-dev libpq-dev
Clone this wiki locally