My blog built with Hugo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.3 KiB

title: "PostgreSQL Installation on Debian"
date: 2019-12-21T11:12:04Z
draft: false
thumbnail: v1575980873/2019/PostgreSQL.jpg
categories: [SysAdmin]
tags: [PostgreSQL, Ubuntu, VPS]
readmore: Read the tutorial
tableofcontents: true
summarize: true
update: true
- /postgresql-installation-on-ubuntu/
On the way to install Nextcloud we've already completed the [initial setup of our VPS](/debian-server-initial-setup/) and the [installation of a webserver (Nginx)](/nginx-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.
## Why PostgreSQL
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.
## Install PostgreSQL
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](
## Tune PostgreSQL
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
## What's next?
Now that we've installed a webserver and a database management system, all that's missing so we can install Nextcloud is [PHP](/php-installation-on-debian/).
{{< call-for-contribution >}}
[^1]: [Nextcloud system requirements](