Skip to content

Setup PostgreSQL on Arch Linux

Sven Lohrmann edited this page Sep 3, 2019 · 9 revisions

Setup PostgreSQL

Installation

Install the postgresql package:

$ sudo pacman -S postgresql

Create a new database cluster:

$ sudo -u postgres -i initdb --locale $LANG -E UTF8 -D /var/lib/postgres/data

Start and enable postgresql.service:

$ sudo systemctl start postgresql.service
$ sudo systemctl enable postgresql.service

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 /var/lib/postgres/data/postgresql.conf change the line with listen_addresses to

listen_addresses = '*'

Then append the following line to /var/lib/postgres/data/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

Install dependencies

In order to use PostgreSQL with the FilamentManager you need to manually install the psycopg2 package as an additional dependency to your virtualenv. If you followed the guide from the OctoPrint wiki your virtualenv is located under ~/OctoPrint/venv, otherwise modify the path accordingly.

$ ~/OctoPrint/venv/bin/pip install psycopg2

If you ran into issues ensure postgresql-libs is installed.

$ sudo pacman -S postgresql-libs

Plugin settings

After restarting your OctoPrint instance you can now configure the PostgreSQL settings. You can find them in the plugin settings dialog under the Database tab. Enter your user credentials, database name, etc. like shown below.

database config

Finally you can test your connection by clicking Test connection. If the button turns green everything is OK and ready to go. Restart OctoPrint again and you are done.