PostgreSQL Installation on Debian
We’ll now proceed with the installation of PostgreSQL, a relational database management system.
I’m currently using Debian 11, but these instructions may be equally valid for other versions of Debian and Ubuntu.
PostgreSQL isn’t the obvious choice to use with Nextcloud. In fact, the officially recommended database management system by Nextcloud is MySQL or MariaDB.1
I choosed PostgreSQL mainly because I planned to run other applications, in the same server, that are only compatible with it. My goal was to have a simple as possible setup, avoiding run multiple database systems simultaneously.
Either way, PostgreSQL has its advantages like an extensive SQL compliance, data integrity and being open source and community driven.
But maybe it isn’t the right choice for you and for a more informed decision you can, for example, read this comparison between SQLite vs MySQL vs PostgreSQL. I found it really usefull.
Debian’s default repositories contain PostgreSQL packages, so we can install these using the
apt packaging system.
First, refresh the local package index:
# sudo apt update
Then, install the PostgreSQL package along with a
-contrib package that adds some additional utilities and functionality:
# sudo apt install postgresql postgresql-contrib
To learn the basics about using PostgreSQL you can start by reading this tutorial on Digital Ocean.
One of the downsides of PostgreSQL is its memory performance, so besides optional is highly recommended tune its settings depending on the hardware at your disposale.
To do so, we can visit PGTune, fill the form with our system informations and get a list of settings to add/modify in
postgresql.conf. This file can be found in
/etc/postgresql/<version_number>/main folder. In my case, as I’m using the version 13 of PostgreSQL, I use the following command to edit it:
# sudo nano /etc/postgresql/13/main/postgresql.conf
Then is a matter of search for each one of the parameters in the list and modify or add it to match the values generated by PGTune.
Save the changes and just restart the PostgreSQL service:
# sudo systemctl restart postgresql
Now that we’ve installed a webserver and a database management system, all that’s missing so we can install Nextcloud is PHP.