Part of Datorkirurgen AB – IT experts across Sweden

PostgreSQL on Linux for businesses: installation, vacuum, indexes, backups and upgrades between versions. We help you in Stockholm and across Sweden.

When PostgreSQL is the right choice

PostgreSQL is one of the most advanced free databases. It handles complex queries, large amounts of data and advanced data types such as JSON and geographic data. Therefore, many developers choose it for new systems and analysis tools. Moreover, PostgreSQL on Linux is well proven, since most large installations run exactly there. We work with the database on Debian, Ubuntu, AlmaLinux and in the cloud.

A new major version comes roughly once a year, and each version receives updates for five years. Version 19 was released in November 2026 and, among other things, adds the REPACK command, which reclaims space in tables without blocking reads and writes. We usually install from the PostgreSQL project’s own package repositories. In that way, we get the version we want, instead of the one the distribution happens to include. In addition, it gives better control during upgrades. At the same time, several versions can exist on the same server during a transition period, which makes the move between versions considerably safer.

PostgreSQL on Linux compared with MariaDB for different types of assignments
PostgreSQL on Linux compared with MariaDB for different types of assignments. This is how Linux Service, part of Datorkirurgen AB, works for businesses in Gothenburg and Malmö.

Installation and basic settings

After the installation, we set up the memory. We often set shared_buffers to a quarter of the server’s memory, and effective_cache_size to roughly three quarters. In addition, we adjust work_mem, which controls the memory for sorting and joins. However, a value that is too high can cause problems when many queries run at the same time. Therefore, we choose values according to the real load.

The file pg_hba.conf controls access. There we decide which users may connect, from which addresses and with which method. We always use encrypted passwords with scram-sha-256. The database only listens on the addresses that are needed, and as a result it is not visible to the internet. Moreover, each program gets its own role with restricted permissions.

PostgreSQL on Linux: memory settings adapted to the size of the server
PostgreSQL on Linux: memory settings adapted to the size of the server. Do you need help with Linux? Linux Service helps you in Uppsala, on site or remotely.

Vacuum and autovacuum

PostgreSQL writes new versions of rows instead of changing them in place. Old versions remain until vacuum cleans them up. If the clean-up cannot keep up, the tables grow, and then the queries become slower. Autovacuum handles this automatically, but the default settings do not always suit large tables. Therefore, we adjust the thresholds for the tables that change the most.

We follow up with the views pg_stat_user_tables and pg_stat_activity. There we see when vacuum last ran and whether something blocks it. For example, a transaction that has been open for several hours can prevent all clean-up. We find and fix such problems before they affect the users. It is one of the most common reasons why a PostgreSQL database becomes slow over time.

Checklist for maintaining a PostgreSQL database
Checklist for maintaining a PostgreSQL database. An example from our work for clients in Täby, Danderyd and Lidingö.

Slow queries and indexes

The extension pg_stat_statements collects statistics about all queries. There we see which queries take the most time in total, and that is usually where the improvement lies. With EXPLAIN ANALYZE, we see how the database actually runs a query. If it reads the whole table when it only needs a few rows, an index is often missing. In that case, we add the right index and measure again.

We also look for indexes that are never used, because they take up space and make writes slower. In addition, if you have many connections from a web application, PgBouncer can help, since it reuses connections. The result is a database that handles more traffic on the same hardware. See also MariaDB on Linux if you have both databases.

Analysis of a slow query with EXPLAIN ANALYZE and a new index
Analysis of a slow query with EXPLAIN ANALYZE and a new index. Linux Service, part of Datorkirurgen AB, helps businesses in Nacka and Södermalm with servers, scripts and databases.

Backups and upgrades

For backups, we use pg_dump for individual databases and pg_basebackup or pgBackRest for whole clusters. Moreover, with continuous archiving of the transaction log, we can restore to an exact point in time. That is invaluable if someone accidentally deletes data in the middle of the day. We test the restore regularly, just as with all other backups.

We carry out upgrades between major versions with pg_upgrade, which is fast even for large databases. First, we test on a copy and check that all extensions exist in the new version. After that, we carry out the upgrade in a maintenance window. Finally, we run ANALYZE, so that the database gets new statistics immediately. During the first few days, we also follow the performance extra closely, since the query plans sometimes change with a new version.

Contact Linux Service about PostgreSQL on Linux

Linux Service is part of Datorkirurgen AB and has more than 30 years of experience of Linux and databases. We install, optimise and upgrade PostgreSQL on Linux for businesses across Sweden. Official information is available in the PostgreSQL documentation.

Therefore, contact us when the database has become slow or when an upgrade is approaching. We carry out a review and propose actions. We work remotely, and you always receive a short report. Moreover, we can take over the ongoing operation.

Frequently asked questions about PostgreSQL on Linux

Questions about PostgreSQL on Linux

PostgreSQL: settings and maintenance

More about backups and upgrades

Website developed by Datorkirurgen AB · Privacy policy