# \#book-high-performance-postgresql-for-rails

**URL:** https://forum.devtalk.com/tag/book-high-performance-postgresql-for-rails/2961.md

[Latest](https://forum.devtalk.com/latest.md) · [Categories](https://forum.devtalk.com/categories.md) · [Tags](https://forum.devtalk.com/tags.md)

---

## [High Performance PostgreSQL for Rails: Suggest installing Postgres.app using Homebrew (page 7)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-suggest-installing-postgres-app-using-homebrew-page-7/229420)

<div class="topic-metadata">

**Author:** [@douglasshuang](https://forum.devtalk.com/u/douglasshuang)\
**Replies:** 1\
**Last updated:** [7 April 2026 19:39 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-suggest-installing-postgres-app-using-homebrew-page-7/229420 "2026-04-07T19:39:28Z")

</div>

Hi @andatki, Happy New Year! Just getting back into the book after a long pause and decided to restart from the beginning. Postgres.app is available on Homebrew as the cask postgres-unofficial: ❯ brew info --cask post…

---

## [High Performance PostgreSQL for Rails: Off-by-one length bug in \`SCRUB\_EMAIL\` (page 52)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-off-by-one-length-bug-in-scrub-email-page-52/237173)

<div class="topic-metadata">

**Author:** [@douglasshuang](https://forum.devtalk.com/u/douglasshuang)\
**Replies:** 1\
**Last updated:** [7 April 2026 19:34 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-off-by-one-length-bug-in-scrub-email-page-52/237173 "2026-04-07T19:34:42Z")

</div>

Hi @andatki, This is a follow-up to my previous error report, High Performance PostgreSQL for Rails: Confusing \`SUBSTR\` arguments in \`SCRUB\_EMAIL\` (page 52). The + 1 after GREATEST(…) was necessary when we were passing …

---

## [High Performance PostgreSQL for Rails: Explanation regarding the use of includes with a limit (Page 124)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-explanation-regarding-the-use-of-includes-with-a-limit-page-124/161023)

<div class="topic-metadata">

**Author:** [@viktorianer](https://forum.devtalk.com/u/viktorianer)\
**Replies:** 1\
**Last updated:** [12 July 2025 03:26 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-explanation-regarding-the-use-of-includes-with-a-limit-page-124/161023 "2025-07-12T03:26:22Z")

</div>

Dear Andrew, @andatki I found the explanation regarding the use of .includes() with a limit in the context of vehicle reservations to be quite insightful. However, I believe the discussion on performance implications c…

---

## [High Performance PostgreSQL for Rails: \`CHECK\` constraint can't stand in for \`UNIQUE\` constraint (Pages 76–77)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-check-constraint-cant-stand-in-for-unique-constraint-pages-76-77/184952)

<div class="topic-metadata">

**Author:** [@douglasshuang](https://forum.devtalk.com/u/douglasshuang)\
**Replies:** 3\
**Last updated:** [6 May 2025 14:16 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-check-constraint-cant-stand-in-for-unique-constraint-pages-76-77/184952 "2025-05-06T14:16:36Z")

</div>

@andatki The book states: How can we safely add UNIQUE and NOT NULL constraints to tables, though, and make sure that all rows are eventually checked for compatibility with the constraint? To do that, we can again us…

---

## [High Performance PostgreSQL for Rails: Off-by-one bug in \`SCRUB\_BATCHES\` procedure (page 65)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-off-by-one-bug-in-scrub-batches-procedure-page-65/183819)

<div class="topic-metadata">

**Author:** [@douglasshuang](https://forum.devtalk.com/u/douglasshuang)\
**Replies:** 2\
**Last updated:** [5 May 2025 13:51 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-off-by-one-bug-in-scrub-batches-procedure-page-65/183819 "2025-05-05T13:51:35Z")

</div>

@andatki The SCRUB\_BATCHES procedure has an off-by-one bug that causes it to skip one row after each batch. Here is output showing the incorrect behavior: owner@localhost:5432 rideshare\_development# CALL SCRUB\_BATCHES(…

---

## [High Performance PostgreSQL for Rails: Confusing \`SUBSTR\` arguments in \`SCRUB\_EMAIL\` (page 52)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-confusing-substr-arguments-in-scrub-email-page-52/179546)

<div class="topic-metadata">

**Author:** [@douglasshuang](https://forum.devtalk.com/u/douglasshuang)\
**Replies:** 2\
**Last updated:** [5 May 2025 13:49 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-confusing-substr-arguments-in-scrub-email-page-52/179546 "2025-05-05T13:49:56Z")

</div>

I’m having trouble understanding the intent of the start and count arguments to SUBSTR in the SCRUB\_EMAIL function. I understand that we want to return the first five or more characters from the MD5 value. The PostgreSQ…

---

## [High Performance PostgreSQL for Rails: Errata on page 177, First Printing](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-errata-on-page-177-first-printing/160934)

<div class="topic-metadata">

**Author:** [@martinstreicher](https://forum.devtalk.com/u/martinstreicher)\
**Replies:** 1\
**Last updated:** [2 May 2025 20:25 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-errata-on-page-177-first-printing/160934 "2025-05-02T20:25:32Z")

</div>

Please use the following format for the title of this thread (then simply delete/replace this text with the content for the thread): Title: High Performance PostgreSQL for Rails (p. 177) Example: Typo on page Page 177…

---

## [High Performance PostgreSQL for Rails: Chapter 11 Boosting Performance With Partitioning](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-chapter-11-boosting-performance-with-partitioning/172736)

<div class="topic-metadata">

**Author:** [@AndyGauge](https://forum.devtalk.com/u/AndyGauge)\
**Replies:** 2\
**Last updated:** [2 May 2025 20:23 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-chapter-11-boosting-performance-with-partitioning/172736 "2025-05-02T20:23:36Z")

</div>

Title: High Performance PostgreSQL for Rails: Archiving mentions deleted\_at column (p338) The sql command DELETE FROM trip\_positions WHERE created\_at \< (NOW() - INTERVAL ‘90 days’); has a where clause that references t…

---

## [High Performance PostgreSQL for Rails: Storing Transformations in Generated Columns (page 85)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-storing-transformations-in-generated-columns-page-85/171265)

<div class="topic-metadata">

**Author:** [@sanctusgee](https://forum.devtalk.com/u/sanctusgee)\
**Replies:** 2\
**Last updated:** [2 May 2025 20:16 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-storing-transformations-in-generated-columns-page-85/171265 "2025-05-02T20:16:47Z")

</div>

@andatki The correct migration code for ruby/migration\_snippet\_virtual\_column.rb is class AlterTempCustomers \< ActiveRecord::Migration\[7.1\] def change add\_column 'temp.customers', :email\_downcased,…

---

## [High Performance PostgreSQL for Rails: AddCheckConstraintTripsCompletedAt p. 75 (paper book P1.0)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-addcheckconstrainttripscompletedat-p-75-paper-book-p1-0/169459)

<div class="topic-metadata">

**Author:** [@cleaver-party](https://forum.devtalk.com/u/cleaver-party)\
**Replies:** 2\
**Last updated:** [2 May 2025 20:07 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-addcheckconstrainttripscompletedat-p-75-paper-book-p1-0/169459 "2025-05-02T20:07:32Z")

</div>

Hello @andatki , I ran into a problem with the migration suggested p. 75: class AddCheckConstraintTripsCompletedAt \< ActiveRecord::Migration\[7.0\] def change add\_check\_constraint :trips, "completed\_at \> crea…

---

## [High Performance PostgreSQL for Rails: Data Scan Definition (Chapter 8, page 145)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-data-scan-definition-chapter-8-page-145/174692)

<div class="topic-metadata">

**Author:** [@yagosansz](https://forum.devtalk.com/u/yagosansz)\
**Replies:** 1\
**Last updated:** [2 May 2025 16:19 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-data-scan-definition-chapter-8-page-145/174692 "2025-05-02T16:19:54Z")

</div>

Hello @andatki, On Chapter 8, page 145, in the Generating Data for Experiments section, one of the paragraphs stars with the following: "When does it flip from sequential scans to index scans?..” I believe this should …

---

## [High Performance PostgreSQL for Rails: \`NOT NULL\` constraint not part of domain as stated (page 90)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-not-null-constraint-not-part-of-domain-as-stated-page-90/188136)

<div class="topic-metadata">

**Author:** [@douglasshuang](https://forum.devtalk.com/u/douglasshuang)\
**Replies:** 1\
**Last updated:** [2 May 2025 16:01 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-not-null-constraint-not-part-of-domain-as-stated-page-90/188136 "2025-05-02T16:01:44Z")

</div>

The book states the following: The main difference for domains compared with enums is that the NOT NULL constraint portion is part of the domain. This is incorrect. The domain has a CHECK constraint for valid non-NUL…

---

## [High Performance PostgreSQL for Rails (PragProg)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-pragprog/122423)

<div class="topic-metadata">

**Author:** [@PragmaticBookshelf](https://forum.devtalk.com/u/PragmaticBookshelf)\
**Replies:** 7\
**Last updated:** [9 August 2024 03:05 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-pragprog/122423 "2024-08-09T03:05:17Z")

</div>

Build fast, scalable PostgreSQL and Rails apps. Solve data growth, quality, and reliability challenges, for workloads from consumer Internet to enterprise SaaS. Andrew Atkinson @andatki edited by Don N. Hagist @dha…

---

## [High Performance PostgreSQL for Rails: Clone and Replace using creation DDL statements (page 58-60)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-clone-and-replace-using-creation-ddl-statements-page-58-60/160767)

<div class="topic-metadata">

**Author:** [@viktorianer](https://forum.devtalk.com/u/viktorianer)\
**Replies:** 3\
**Last updated:** [25 July 2024 05:19 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-clone-and-replace-using-creation-ddl-statements-page-58-60/160767 "2024-07-25T05:19:50Z")

</div>

@andatki I have encountered a couple of issues in the sections explaining the cloning of tables without constraints, copying all rows, and recreating constraints using creation DDL statements. I believe these areas coul…

---

## [High Performance PostgreSQL for Rails: Contains non-printing unicode characters](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-contains-non-printing-unicode-characters/160254)

<div class="topic-metadata">

**Author:** [@viktorianer](https://forum.devtalk.com/u/viktorianer)\
**Replies:** 4\
**Last updated:** [28 June 2024 01:46 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-contains-non-printing-unicode-characters/160254 "2024-06-28T01:46:50Z")

</div>

I found it challenging to use code examples from this book, particularly because the queries containing non-printing Unicode characters. E.g., epub book: rideshare\_development=\> REINDEX ​INDEX​ index\_users\_on\_email; ER…

---

## [High Performance PostgreSQL for Rails: creating index (p. 60)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-creating-index-p-60/157588)

<div class="topic-metadata">

**Author:** [@abr](https://forum.devtalk.com/u/abr)\
**Replies:** 2\
**Last updated:** [28 June 2024 01:48 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-creating-index-p-60/157588 "2024-06-28T01:48:32Z")

</div>

Hi, I’m reading chapter 3 (B8.0), in particular the part about cloning sequences and indexes to the scrubbed tables. This part confused me: Let’s take a look at the UNIQUE index on the users.email column. To create th…

---

## [High Performance PostgreSQL for Rails: strange wording (p 81):](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-strange-wording-p-81/157589)

<div class="topic-metadata">

**Author:** [@abr](https://forum.devtalk.com/u/abr)\
**Replies:** 1\
**Last updated:** [3 June 2024 02:01 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-strange-wording-p-81/157589 "2024-06-03T02:01:29Z")

</div>

Active Record supports multiple validations becoming listed out for an attribute. It took me a couple of tries to understand this, maybe it would make more sense to replace “becoming” with “being”?

---

## [High Performance PostgreSQL for Rails: users count inconsistency (page 56)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-users-count-inconsistency-page-56/143431)

<div class="topic-metadata">

**Author:** [@BraisonCrece](https://forum.devtalk.com/u/BraisonCrece)\
**Replies:** 5\
**Last updated:** [12 April 2024 02:53 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-users-count-inconsistency-page-56/143431 "2024-04-12T02:53:44Z")

</div>

Hi @andatki! First of all, thank you so much for this amazing book! :muscle: I’ve found something that can cause a bit of confusion. After seeding the data in order and running the bulk\_load script, the reader will hav…

---

## [High Performance PostgreSQL for Rails: reverse search does not work in psql (Page 42)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-reverse-search-does-not-work-in-psql-page-42/148278)

<div class="topic-metadata">

**Author:** [@tothpeter08](https://forum.devtalk.com/u/tothpeter08)\
**Replies:** 1\
**Last updated:** [12 April 2024 02:22 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-reverse-search-does-not-work-in-psql-page-42/148278 "2024-04-12T02:22:11Z")

</div>

@andatki “If you’ve used the history command in your terminal, psql supports a similar “reverse search” by typing “ctrl-r”. Type ctrl-r, then SEL to match any SELECT statements you’ve run before.” → It doesn’t work fo…

---

## [High Performance PostgreSQL for Rails: bin/rails db:reset does not work with docker (Page 58)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-bin-rails-db-reset-does-not-work-with-docker-page-58/148279)

<div class="topic-metadata">

**Author:** [@tothpeter08](https://forum.devtalk.com/u/tothpeter08)\
**Replies:** 1\
**Last updated:** [12 April 2024 02:18 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-bin-rails-db-reset-does-not-work-with-docker-page-58/148279 "2024-04-12T02:18:45Z")

</div>

@andatki bin/rails db:reset doesn’t work if there is no socket file locally which is the case if I’m running Postgres from a Docker container on OSX. sh db/setup\_test\_database.sh → “psql: error: connection to server on…

---

## [High Performance PostgreSQL for Rails: wrong migration code sample (page 115)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-wrong-migration-code-sample-page-115/148277)

<div class="topic-metadata">

**Author:** [@tothpeter08](https://forum.devtalk.com/u/tothpeter08)\
**Replies:** 2\
**Last updated:** [12 April 2024 02:14 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-wrong-migration-code-sample-page-115/148277 "2024-04-12T02:14:43Z")

</div>

@andatki class AddTripRatingCheckConstraint \< ActiveRecord::Migration\[7.0\] def change add\_check\_constraint :users, "rating \>= 1 AND rating \<= 5", name: "rating\_check" end end ad…

---

## [High Performance PostgreSQL for Rails: Minor typo in vacuum command (p. 176)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-minor-typo-in-vacuum-command-p-176/146790)

<div class="topic-metadata">

**Author:** [@daniela](https://forum.devtalk.com/u/daniela)\
**Replies:** 2\
**Last updated:** [12 April 2024 02:13 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-minor-typo-in-vacuum-command-p-176/146790 "2024-04-12T02:13:56Z")

</div>

@andatki Minor typo - extra U: “To free up the space, you’ll need to VACUUUM FULL users;…” Fix: To free up the space, you’ll need to VACUUM FULL users;.

---

## [High Performance PostgreSQL for Rails: How to show autovacuum\_vacuum\_scale\_factor per table (p. 171)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-how-to-show-autovacuum-vacuum-scale-factor-per-table-p-171/146791)

<div class="topic-metadata">

**Author:** [@daniela](https://forum.devtalk.com/u/daniela)\
**Replies:** 2\
**Last updated:** [16 March 2024 18:12 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-how-to-show-autovacuum-vacuum-scale-factor-per-table-p-171/146791 "2024-03-16T18:12:19Z")

</div>

@andatki On page 171, it shows how to change the autovacuum scale factor for a particular table, eg: ALTER TABLE trips SET (autovacuum\_vacuum\_scale\_factor = 0.01); It’s also possible to show from in a psql console wha…

---

## [High Performance PostgreSQL for Rails: Do you run clusters on your MacBook?](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-do-you-run-clusters-on-your-macbook/125550)

<div class="topic-metadata">

**Author:** [@andatki](https://forum.devtalk.com/u/andatki)\
**Replies:** 1\
**Last updated:** [31 December 2023 06:08 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-do-you-run-clusters-on-your-macbook/125550 "2023-12-31T06:08:51Z")

</div>

Title: High Performance PostgreSQL for Rails @aapsql @andatki A reader wrote this by email. Re-posting here: Do you run clusters on your MacBook? I use macOS, yes. In the book, readers will install local (updating …

---

## [High Performance PostgreSQL for Rails: Suggest discard instead of acts\_as\_paranoid (page 102)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-suggest-discard-instead-of-acts-as-paranoid-page-102/132409)

<div class="topic-metadata">

**Author:** [@fidalgo](https://forum.devtalk.com/u/fidalgo)\
**Replies:** 2\
**Last updated:** [13 December 2023 05:57 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-suggest-discard-instead-of-acts-as-paranoid-page-102/132409 "2023-12-13T05:57:17Z")

</div>

@andatki In the book, you make a reference to acts\_as\_paranoid, but given the simplicity and popularity: Category: Active Record Soft Delete - The Ruby Toolbox I would suggest you to mention discard instead. Also, acts\_…

---

## [High Performance PostgreSQL for Rails: Issue with bulk\_load.sh](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-issue-with-bulk-load-sh/133506)

<div class="topic-metadata">

**Author:** [@yann](https://forum.devtalk.com/u/yann)\
**Replies:** 3\
**Last updated:** [28 November 2023 05:04 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-issue-with-bulk-load-sh/133506 "2023-11-28T05:04:05Z")

</div>

Hi and thank you for this fantastic book, I ran in the following error while trying to run db/scripts/bulk\_load.sh: Bulk loading 10\_000\_000 Drivers and Riders Raising the statement\_timeout ERROR: syntax error at or ne…

---

## [High Performance PostgreSQL for Rails: Using Advisory Locks (page 195)](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-using-advisory-locks-page-195/132408)

<div class="topic-metadata">

**Author:** [@fidalgo](https://forum.devtalk.com/u/fidalgo)\
**Replies:** 1\
**Last updated:** [18 November 2023 03:02 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-using-advisory-locks-page-195/132408 "2023-11-18T03:02:00Z")

</div>

@andatki In this page, you mention: The Transaction Pooling Mode for PgBouncer cannot be used with Advisory Locks Can you expand a title further on this? PgBouncer is like a first resource when people run out of databa…

---

## [High Performance PostgreSQL for Rails:](https://forum.devtalk.com/t/high-performance-postgresql-for-rails/131724)

<div class="topic-metadata">

**Author:** [@ka8725](https://forum.devtalk.com/u/ka8725)\
**Replies:** 2\
**Last updated:** [12 November 2023 21:31 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails/131724 "2023-11-12T21:31:25Z")

</div>

@andatki High Performance PostgreSQL for Rails - wrong code example The code description does not match the code snippet.

---

## [High Performance PostgreSQL for Rails: "Is this useful for non Rails users?"](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-is-this-useful-for-non-rails-users/129629)

<div class="topic-metadata">

**Author:** [@andatki](https://forum.devtalk.com/u/andatki)\
**Replies:** 0\
**Last updated:** [25 October 2023 02:24 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-is-this-useful-for-non-rails-users/129629 "2023-10-25T02:24:22Z")

</div>

Roshan asked: Is this useful for non Rails users? As the author, I’m biased, but I think so. While all of the application code examples are in Ruby and Active Record, there are many types of code or configuration thr…

---

## [High Performance PostgreSQL for Rails: page 26/27](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-page-26-27/124823)

<div class="topic-metadata">

**Author:** [@pzac](https://forum.devtalk.com/u/pzac)\
**Replies:** 6\
**Last updated:** [27 September 2023 00:12 UTC](https://forum.devtalk.com/t/high-performance-postgresql-for-rails-page-26-27/124823 "2023-09-27T00:12:01Z")

</div>

@andatki Hi, page 26 says Data cannot be split across pages. But two paragraphs later Data may not fit in a single page, may be split across pages

[Next page](https://forum.devtalk.com/tag/book-high-performance-postgresql-for-rails/2961.md?match_all_tags=true&page=1&tags%5B%5D=book-high-performance-postgresql-for-rails)
