Deep dive in the situation with prepared statements and partitioned tables in Postgres:
part 1 postgres.ai/blog/2025102...
part 2 postgres.ai/blog/2025102...
part 3 postgres.ai/blog/2025103...
@samokhvalov.bsky.social
Talk to me if you have issues with your Postgres databases: nik@postgres.ai // I stand with Ukraine // Postgres.AI & DBLab & Postgres.FM
Deep dive in the situation with prepared statements and partitioned tables in Postgres:
part 1 postgres.ai/blog/2025102...
part 2 postgres.ai/blog/2025102...
part 3 postgres.ai/blog/2025103...
this repo deserves more stars gitlab.com/postgres-ai/...
we aim to have most detailed and advanced monitoring for Postgres -- and it's FOSS because it's just a foundation of something bigger
(after 20 years with Postgres, next month will be the most exciting announcement of my career)
postgres_ai monitoring 0.11: VictoriaMetrics, lots of optimizations, new dashboards for table and index analysis, and more github.com/postgres-ai/...
31.10.2025 20:12 β π 1 π 0 π¬ 0 π 0postgres_ai monitoring 0.11: VictoriaMetrics, lots of optimizations, new dashboards for table and index analysis, and more github.com/postgres-ai/...
30.10.2025 21:26 β π 0 π 0 π¬ 0 π 1TIL during this hacking session: REFRESH MATERIALIZED VIEW CONCURRENTLY creates temp tables github.com/postgres/pos... β so, if you do it super frequently, it might contribute to system catalog bloat
29.10.2025 18:01 β π 1 π 0 π¬ 0 π 0created telegram group for everyone who is hacking postgres source code or considers to start it: t.me/postgres_hac...
29.10.2025 17:21 β π 0 π 0 π¬ 0 π 0live session of Postgres [vibe] hacking happening now -- join! www.youtube.com/watch?v=6cZv...
29.10.2025 16:46 β π 0 π 0 π¬ 1 π 1I'm on a trip until 2025-10-22, and have only limited time with laptop β #PostgresMarathon will be continued when I'm back
16.10.2025 04:33 β π 0 π 0 π¬ 0 π 0#PostgresMarathon 2-008: LWLock:LockManager and prepared statements postgres.ai/blog/2025101...
15.10.2025 13:16 β π 0 π 0 π¬ 0 π 0#PostgresMarathon 2-007: Should we worry about pg_blocking_pids()'s observer effect? postgres.ai/blog/2025101...
14.10.2025 00:31 β π 0 π 0 π¬ 0 π 0Got very much attracted by title "Boosting Planning Performance | Scaling Postgres 387",
was very curious (because I do want to learn more ways to boost planning performance), checked it out: www.youtube.com/watch?v=d7__...
...and ERROR: infinite recursion detected
Postgres hacking session LIVE www.youtube.com/watch?v=5lN7...
08.10.2025 17:08 β π 0 π 0 π¬ 0 π 0Key points to remember:
1. Heavyweight locks = same as just "locks"
- contention β fix your SQL/schema
- held until COMMIT/ROLLBACK
2. Lightweight locks = LWLocks:
- contention on them β lack of resources, misconfiguration, suboptimal workload patterns, or Postgres internal limitations
- we can observe pending and successful lock acquisition attempts using pg_locks (and joining it with pg_stat_activity on pid)
Lock Manager is a core component of Postgres responsible for managing heavyweight locks.
10/
- users can explicitly initiate a lock acquisition attempt
- attempts to acquire locks form a queue
- there are many types of locks and sophisticated rules of conflicts between them (see www.postgresql.org/docs/current...)
9/
- once acquired, they are held until the very end of transaction; IMPORTANT: acquired heavyweight locks can be released only when COMMIT or ROLLBACK happens, never before
- there is a deadlock detection mechanism β this is one of the jobs of Lock Manager
8/
Heavyweight locks:
- these locks need to coordinate concurrent access to various high-level resources including but not limited to: databases, tables, indexes, rows
7/
when we see a high number of active sessions in pg_stat_activity with wait_event_type = 'lwlock'. If we take into account particular wait event (column wait_event), we can see cases like 'LWLock:SubtransSLRU', 'LWLock:BufferMapping', 'LWLock:LockManager'
6/
- normally, we don't have a direct way to observe LWLocks (there is a setting "trace_lwlocks", which requires LOCK_DEBUG at compilation time, so it's only for hacking/debugging purposes), but we do talk of them a lot when Postgres suffers from an LWLock contention β
5/
- interesting fact from lmgr/README: "if a process has to wait for an LWLock, it blocks on a SysV semaphore so as to not consume CPU time" β we'll return to this later
- in general, very well optimized in modern Postgres versions; LWLock contention is observed only in heavily loaded systems
4/
Lightweight locks ("LWLocks"):
- internal mechanism to coordinate access to shared memory structures
- usually very short, so they are typically released really fast (although may take longer β for example, to protect I/O operations)
- can be exclusive (for writes) or shared (for read-only ops)
3/
- LockManager source code β src/backend/storage/lmgr (and first of all, README github.com/postgres/pos...)
- Egor Rogov's "PostgreSQL Internals", Part III "Locks"
2/
#PostgresMarathon 2-001
To warm up, let's talk about lightweight and heavyweight locks (or "regular locks" or just "locks").
I'm using these materials:
- PG docs (first of all, www.postgresql.org/docs/current...)
1/
- Ideally, in the end, all the info will be compiled into a big blog post to cover one big topic
Make sure you follow and share it with your followers.
The first topic will be: ** Lock Manager **
Let's go!
4/
- I'll be digging deeper (source code, case studies, complex experiments), and also educating myself, so we all understand all the details, and can return to these records later if needed
- You'll have a chance to participate and help me make sure there are no unknowns left
3/
- Every day, I'll be posting bits of info: from basics, to internals, to experiments and benchmarks and finally, practical pieces of advice (aka "howtos", which made up my first #PostgresMarathon in 2023 that lasted 3 months)
2/
#PostgresMarathon is back!
Make sure you follow me so we could learn some good stuff about Postgres together.
This time, I'll be doing it a bit differently:
- I'll choose one big Postgres topic that I'll be covering over a week or two
1/
;-)
04.10.2025 00:30 β π 0 π 0 π¬ 0 π 0Good stuff as well!
04.10.2025 00:30 β π 0 π 0 π¬ 0 π 0I don't understand this
04.10.2025 00:30 β π 0 π 0 π¬ 1 π 0