Tag: postgresql
New target_session_attrs settings for high availability and scaling in PostgreSQL v14
© Laurenz Albe 2021 PostgreSQL commit ee28cacf61 has added new options for the target_session_attrs connection parameter. This article explores how the new options can be used to simplify high availability and horizontal scaling solutions. What is target_session_attrs? The PostgreSQL client shared library libpq has support for connection strings to more than one database server: In […]
PostgreSQL: Getting started on Ubuntu
To make it easier for our readers to install PostgreSQL on Ubuntu, we have compiled a quick guide to getting started. Don’t worry, it’s not too hard. You will learn: How to download PostgreSQL How to install PostgreSQL on Ubuntu How to create a database instance How to ensure the service is running Creating your […]
Estimating connection pool size with PostgreSQL database statistics
© Laurenz Albe 2021 PostgreSQL v14 has new connection statistics in pg_stat_database. In this article, I want to explore one application for them: estimating the correct size for a connection pool. New connection statistics in v14 Commit 960869da080 introduced some new statistics to pg_stat_database: session_time: total time spent by sessions in the database active_time: time […]
PostgreSQL: How to write a trigger
Just like in most databases, in PostgreSQL a trigger is a way to automatically respond to events. Maybe you want to run a function if data is inserted into a table. Maybe you want to audit the deletion of data, or simply respond to some UPDATE statement. That is exactly what a trigger is good […]
PostgreSQL: CREATE STATISTICS – advanced query optimization
PostgreSQL query optimization with CREATE STATISTICS is an important topic. Usually, the PostgreSQL optimizer (query planner) does an excellent job. This is not only true for OLTP but also for data warehousing. However, in some cases the optimizer simply lacks the information to do its job properly. One of these situations has to do with […]
“Catchment areas” with PostgreSQL and PostGIS
Recently a colleague in our sales department asked me for a way to partition an area of interest spatially. He wanted to approximate customer potential and optimize our sales strategies respective trips. Furthermore he wanted the resulting regions to be created around international airports first, and then intersected by potential customer locations, in order to […]
Patroni Environment Setup: PostgreSQL High Availability for Windows
PostgreSQL High-Availability has been one of the most dominant topics in the field for a long time. While there are many different approaches out there, Patroni seems to have become one of the most dominant solutions currently in use out there. Many database clusters are running on Linux. However, we have seen some demand for […]
PostgreSQL: What is a checkpoint?
Checkpoints are a core concept in PostgreSQL. However, many people don’t know what they actually are, nor do they understand how to tune checkpoints to reach maximum efficiency. This post will explain both checkpoints and checkpoint tuning, and will hopefully shed some light on these vital database internals. How PostgreSQL writes data Before we talk […]
pg_timetable: asynchronous chain execution
Intro I wrote about the new pg_timetable 3 major release not so long ago. Three essential features were highlighted: new session locking implementation; new jackc/pgx Golang library used; exclusive chain execution. Meanwhile, two minor releases have come out, and the current version is v3.2. It focuses on the completely new and fantastic feature asynchronous control […]
The shibboleth of PostgreSQL
© Laurenz Albe 2020 After all the technical articles I have written, I thought it would be nice to write about PostgreSQL sociology for a change. Language and community A community like PostgreSQL has no clearly defined borders. There is no membership certificate; you belong to it if you feel that you belong. That said, […]
PostgreSQL exclusive cron jobs using pg_timetable scheduler
I wrote about the new pg_timetable 3 major release not so long ago. Two essential features were highlighted: – new session locking implementation – new jackc/pgx Golang library used Today I want to reveal one more advanced feature! Fasten your seat belts! First, we need to distinguish exclusive client session mode from exclusive chain execution […]
Is UPDATE the same as DELETE + INSERT in PostgreSQL?
© Laurenz Albe 2020 Introduction We know that PostgreSQL does not update a table row in place. Rather, it writes a new version of the row (the PostgreSQL term for a row version is “tuple”) and leaves the old row version in place to serve concurrent read requests. VACUUM later removes these “dead tuples”. If […]