How to Install PostgreSQL 12 on Linux Mint 19 Tara (19.1 Tessa, 19.2 Tina, 19.3 Tricia)
Update 23-12-2020: PostgreSQL 13 installation on Linux Mint 20 Ulyana available here.
The PostgreSQL Global Development Group had announced the release of PostgreSQL 12 a while ago. Let's install it on our Linux Mint 19 (19 Tara, 19.1 Tessa, 19.2 Tina, 19.3 Tricia).
The installation process is still the same as previous version (more detail here), but I'm going to write it again here.
Note: if you are an experienced Linux user, or a PostgreSQL DBA, this is not the post for you, even though your remarks and constructive criticism are very welcome – in case you see something either incorrect or missing, please do let me know inside the comments below.
Installation steps for PostgreSQL 12 on Linux Mint 19 (19 Tara, 19.1 Tessa, 19.2 Tina, 19.3 Tricia)
As usual, PostgreSQL's latest version 12 is not available directly using the Advanced Packaging Tool (APT) or the Linux Mint Software Manager.
Fortunately, the PostgreSQL Global Development Group (PGDG) maintain an apt repository of PostgreSQL packages for Debian and Ubuntu-derived Linux distros, located at http://apt.postgresql.org/pub/repos/apt/
Before we can install PostgreSQL, we have to add the package source for the distro we are currently using. In this case, I have been using Linux Mint 19 Tara, which is derived from (and therefore should be compatible with) Ubuntu 18.04 ("Bionic Beaver") release. We'll understand why this matters in a short while.
What's currently supported:
- Debian 8 (jessie), 9 (stretch), 10 (buster), 11 (bullseye, amd64/ppc64 only), and unstable (sid)
- Ubuntu 16.04 (xenial), 18.04 (bionic), 19.04 (disco; amd64 only), 19.10 (eoan, amd64 only)
- Architectures: amd64 (64-bit x86), i386 (32-bit x86), ppc64el (little-endian 64-bit POWER)
- PostgreSQL 9.4, 9.5, 9.6, 10, 11, 12
- Server extensions such as Slony-I, various PL languages, and datatypes
- Applications like pgadmin3, pgadmin4, omnidb, pgbouncer, and pgpool-II
Add the PostgreSQL Package Source for Your Linux Distribution
We need to create a sources file reflecting the proper PostgreSQL source for our specific distro. As noted above, in my case I'll need the source appropriate for the "Bionic" release of Ubuntu. We can accomplish this from the terminal to add the file (make sure to use sudo
in all of the following steps):
Add the PGDG APT source file
Create a file at /etc/apt/sources.list.d/postgresql.list
with the following command:
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > \
/etc/apt/sources.list.d/postgresql.list'
Add the PostgreSQL Package Repository Key
Next, add the package repository key:
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Update, Upgrade, and Install PostgreSQL
Update system package source. Once this task is done, we proceed with upgrade packages to the latest versions.
$ sudo apt update
$ sudo apt upgrade
Please note that this can be a long process, depends on your internet connection and how frequent you're upgrading your packages. Also please note that you may be prompted at several points to make some choices about configuration items. Specifically, you may informed that this that or the other configuration file has been changed, and asked if you want to keep your original version, or replace with the package maintainer’s version. Select "Y" to accept the package maintainer’s version in these cases.
Next step is installing PostgreSQL 12:
$ sudo apt install postgresql-12
After pressing "Enter" you will be asked whether to continue with installation or not.
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.15.0-66 linux-headers-4.15.0-66-generic linux-image-4.15.0-66-generic linux-modules-4.15.0-66-generic
linux-modules-extra-4.15.0-66-generic python3-flask-htmlmin python3-htmlmin
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
postgresql-client-12
Suggested packages:
postgresql-doc-12
Recommended packages:
sysstat
The following NEW packages will be installed:
postgresql-12 postgresql-client-12
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
Need to get 15,8 MB of archives.
After this operation, 51,2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Press "Y" and then "Enter". It will then download all necessary files and continue with installation.
Configuring Postgres for Use
The postgres user
While PostgreSQL become installed, a system user account named postgres
was also created with an identical user account in postgres. By default, the postgres
user account isn't configured with a password, so it isn't viable to log into the server the use of the postgres user account without first creating a password for it. This postgres
account has an all-access pass on your PostgreSQL database server, permission-wise. The postgres
user account has similarities to the sa
account in SQL server.
The postgres database
PostgreSQL is installed with a default database postgres
. For the most part, we use the postgres
database for administration functions, and create new databases on the PostgreSQL server to suit our needs.
The psql Command Line Utility
PostgreSQL consists of psql
, a command line application for managing your databases and server. While a GUI-based software such as pgadmin3
is often less complicated to use in the daily task, the command line utilty psql
is always handy. psql
gives total control of your postgres system from the terminal, together with the ability to execute SQL queries.
We will use psql
to perform our preliminary configuration and to create an initial database super user.
Create super user account
In this step we will super-user account to deals with our database in the daily task.
To do this, we will get access to the postgres
account through your machine root
user. Then we'll use that postgres
account to create a brand new super-user account for your PostgreSQL installation which can be regulated more efficiently. As an example we will use adjie as our new PostgreSQL super-user account.
$ sudo su -
[sudo] password for adjie:
# su - postgres
$ psql
postgres=# CREATE USER adjie postgres-# WITH SUPERUSER CREATEDB CREATEROLE postgres-# PASSWORD 'your-preferred-password';
Notice in the above we can enter multiple lines of command in SQL shell. The SQL is not executed until semi-colon followed enter is found. Which means, the semi-colon will make the shell execute entered commands. After pressing "Enter" it will respond with something like this:
CREATE ROLE
postgres=#
Which means we've successfully created this new superuser account.
Login using our newly created account
Let's verify that everything is working correctly. Try to log in with psql
using our new super-user account and create a quick test database:
$ psql postgres
psql (12.1 (Ubuntu 12.1-1.pgdg18.04+1))
Type "help" for help.
postgres=#
Note in the above terminal session, we specified the postgres
default database when we logged in, since there aren’t yet any other databases to connect to.
Create test database
Next test is to create test database test_database
using our new super-user account:
postgres=# CREATE DATABASE test_database WITH OWNER adjie;
CREATE DATABASE
postgres=# \connect test_database;
You are now connected to database "test_database" as user "adjie".
test_database=#
If everything works as shown, then congratulations. Now you have a working installation of PostgreSQL 12 on Linux Mint 19 (19 Tara, 19.1 Tessa, 19.2 Tina, 19.3 Tricia).
Optional step
If you would like to manipulate your database in graphical mode, then pgadmin4 is the way to go. Install pgadmin4 by issuing this command:
$ sudo apt-get install pgadmin4
After pressing "Enter" you will be asked whether to continue with installation or not, something like this:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
alembic fonts-font-awesome fonts-glewlwyd fonts-open-sans libjs-jquery
libjs-sphinxdoc libjs-underscore pgadmin4-common python-babel-localedata
python3-alembic python3-asn1crypto python3-babel python3-blinker
python3-click python3-colorama python3-cryptography python3-dateutil
python3-flask python3-flask-babelex python3-flask-gravatar
python3-flask-htmlmin python3-flask-login python3-flask-mail
python3-flask-migrate python3-flask-paranoid python3-flask-principal
python3-flask-security python3-flask-sqlalchemy python3-flaskext.wtf
python3-htmlmin python3-itsdangerous python3-jinja2 python3-paramiko
python3-passlib python3-psycopg2 python3-pyasn1 python3-simplejson
python3-sqlalchemy python3-sqlparse python3-sshtunnel python3-werkzeug
python3-wtforms
Suggested packages:
pgadmin4-doc python3-editor python-blinker-doc python-cryptography-doc
python3-cryptography-vectors python-flask-doc python-flask-login-doc
python-jinja2-doc python3-gssapi python-psycopg2-doc python-sqlalchemy-doc
python3-pymysql python3-fdb python-sqlparse-doc ipython3 python3-lxml
python3-termcolor python3-watchdog python-werkzeug-doc python3-django
python3-django-localflavor
Recommended packages:
javascript-common python3-openssl
The following NEW packages will be installed:
alembic fonts-font-awesome fonts-glewlwyd fonts-open-sans libjs-jquery
libjs-sphinxdoc libjs-underscore pgadmin4 pgadmin4-common
python-babel-localedata python3-alembic python3-asn1crypto python3-babel
python3-blinker python3-click python3-colorama python3-cryptography
python3-dateutil python3-flask python3-flask-babelex python3-flask-gravatar
python3-flask-htmlmin python3-flask-login python3-flask-mail
python3-flask-migrate python3-flask-paranoid python3-flask-principal
python3-flask-security python3-flask-sqlalchemy python3-flaskext.wtf
python3-htmlmin python3-itsdangerous python3-jinja2 python3-paramiko
python3-passlib python3-psycopg2 python3-pyasn1 python3-simplejson
python3-sqlalchemy python3-sqlparse python3-sshtunnel python3-werkzeug
python3-wtforms
0 upgraded, 43 newly installed, 0 to remove and 0 not upgraded.
Need to get 10,8 MB of archives.
After this operation, 62,5 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Press "Y" and then "Enter". It will then download all necessary files and continue with installation.
Final Words
I hope that you now know how to install PostgreSQL 12 on Linux Mint 19 (19 Tara, 19.1 Tessa, 19.2 Tina, 19.3 Tricia). If you run into any issues or have any feedback feel free to drop a comment below.
Just one problem can't solve...,
elipe@felipe-Latitude-E6230:~$ sudo apt install postgresql-12
Leyendo lista de paquetes... Hecho
Creando árbol de dependencias
Leyendo la información de estado... Hecho
No se pudieron instalar algunos paquetes. Esto puede significar que
usted pidió una situación imposible o, si está usando la distribución
inestable, que algunos paquetes necesarios aún no se han creado o se
han sacado de «Incoming».
La siguiente información puede ayudar a resolver la situación:
Los siguientes paquetes tienen dependencias incumplidas:
postgresql-12 : Depende: libicu60 (>= 60.1-1~) pero no es instalable
Recomienda: sysstat pero no va a instalarse
E: No se pudieron corregir los problemas, usted ha retenido paquetes rotos.
And for the instalation of PGAdmin4:
felipe@felipe-Latitude-E6230:~$ sudo apt-get install pgadmin4
Leyendo lista de paquetes... Hecho
Creando árbol de dependencias
Leyendo la información de estado... Hecho
No se pudieron instalar algunos paquetes. Esto puede significar que
usted pidió una situación imposible o, si está usando la distribución
inestable, que algunos paquetes necesarios aún no se han creado o se
han sacado de «Incoming».
La siguiente información puede ayudar a resolver la situación:
Los siguientes paquetes tienen dependencias incumplidas:
pgadmin4 : Depende: pgadmin4-common (= 4.25-1.pgdg18.04+1) pero no va a instalarse
Depende: libpython3.6 (>= 3.6.5) pero no es instalable
E: No se pudieron corregir los problemas, usted ha retenido paquetes rotos.
The thing is I'm using Mint 20.04, why is this happening?
Hello Felipe,
It seems that your system missed some dependencies. Also, if you meant Ubuntu 20.04, I have it covered here: https://r00t4bl3.com/post/how-to-install-postgresql-12-on-ubuntu-20-04-focal-fossa
Thanks