"Find-or-insert" using a single query
Consider the task: you need to read a row, and if it doesn't exist, insert it (and read what's just inserted). Using a single query.
Consider the task: you need to read a row, and if it doesn't exist, insert it (and read what's just inserted). Using a single query.
In some cases, we need to observe some values in Postgres or the environment it's running on (OS, FS, etc.), and:
Heavyweight locks, both relation- and row-level, are acquired by a query and always held until the end of the transaction this query belongs to.
Benchmarking is a huge topic. Here, we cover minimal steps that are required for a Postgres benchmark to be informative, useful, and correct.
This post describes how to quickly compile Postgres on Ubuntu 22.04.
Identify and handle long-running transactions that can impact OLTP system performance
Postgres provides the ability to enable data checksums, which is a good way to protect from certain types of corruption (not all of them).
In a few hours, I'm presenting my "Seamless Postgres query optimization" tutorial at DjangoCon US, so it's a good time to talk about transitioning from…
Let's discuss today how to find and clean up redundant indexes.
Find and safely clean up unused PostgreSQL indexes with SQL queries, replica checks, and zero-downtime drop steps.
There are various approaches to formatting SQL. There are two major ones:
For psql's \echo command, using colors and basic text formatting such as bold or underlined can be done through the use of ANSI color codes.
Generate realistic test data in PostgreSQL using generate_series, random(), timestamps, pseudowords, and Faker.
Two key principles of helping others (it can be internal help to your teammates, or external consulting, doesn't matter):
Sometimes this happens, when you're attempting to edit a query in psql using the \e command:
The rules below are quite simple (but, often due to organizational reasons, not trivial to implement).
Modern Postgres provides more than 300 settings (a.k.a. GUC variables – "grand unified configuration").
If you, like me, work with Postgres mostly in psql, you might want to be able to plot a simple graph not leaving psql.
In a fast-growing project, one of the important optimization vectors is reduction of the amount of WAL (Write Ahead Log) generated.
Diagnose and speed up slow PostgreSQL stops and restarts caused by long-running transactions, shutdown checkpoints, or lagging archive_command.
Troubleshoot slow PostgreSQL startup and crash recovery: inspect WAL REDO progress, check max_wal_size and checkpoint_timeout, and avoid unsafe restarts.
Today we'll discuss how to understand what exactly a Postgres backend is doing inside CPU on a Linux machine (in-CPU analysis).
Here are general recommendations for basic tuning of Linux to run Postgres under heavy OLTP (web/mobile apps) workloads.
This howto is for users who use or need to use Postgres, but are not experienced in using Docker.
In Day 12: How to find query examples for problematic pg_stat_statements records it was mentioned that query normalization can be done using lib_pgquery.
Understand subtransactions, savepoints, and their impact on database performance
When working with metadata – data about data – in Postgres, these reference docs are worth using:
There are two big branches of query optimization:
Index maintenance is inevitable in a larger project. The sooner the process is established the better for performance.
Everyone knows that each additional index is going to slow down writes (INSERT, UPDATE – unless it's HOT).
In my tool postgres_dba, the setup instructions have this:
The 80/20 rule (a.k.a. Pareto principle) is often enough to achieve a good level of performance for OLTP workloads – it is recommended, in most cases, to…
Today, we'll discuss tuples and their locations in pages – this is quite entry-level material but useful in many cases.