Skip to main content
Test Double company logo
Services
Services Overview
Holistic software investment consulting
Software Delivery
Accelerate quality software development
Product Management
Launch modern product orgs
Legacy Modernization
Renovate legacy software systems
DevOps
Scale infrastructure smoothly
Upgrade Rails
Update Rails versions seamlessly
Technical Recruitment
Build tech & product teams
Technical Assessments
Uncover root causes & improvements
Case Studies
Solutions
Accelerate Quality Software
Software Delivery, DevOps, & Product Delivery
Maximize Software Investments
Product Performance, Product Scaling, & Technical Assessments
Future-Proof Innovative Software
Legacy Modernization, Product Transformation, Upgrade Rails, Technical Recruitment
About
About
What's a test double?
Approach
Meeting you where you are
Founder's Story
The origin of our mission
Culture
Culture & Careers
Double Agents decoded
Great Causes
Great code for great causes
EDI
Equity, diversity & inclusion
Insights
All Insights
Hot takes and tips for all things software
Leadership
Bold opinions and insights for tech leaders
Developer
Essential coding tutorials and tools
Product Manager
Practical advice for real-world challenges
Say Hello
Test Double logo
Menu
Services
BackGrid of dots icon
Services Overview
Holistic software investment consulting
Software Delivery
Accelerate quality software development
Product Management
Launch modern product orgs
Legacy Modernization
Renovate legacy software systems
Cycle icon
DevOps
Scale infrastructure smoothly
Upgrade Rails
Update Rails versions seamlessly
Technical Recruitment
Build tech & product teams
Technical Assessments
Uncover root causes & improvements
Case Studies
Solutions
Solutions
Accelerate Quality Software
Software Delivery, DevOps, & Product Delivery
Maximize Software Investments
Product Performance, Product Scaling, & Technical Assessments
Future-Proof Innovative Software
Legacy Modernization, Product Transformation, Upgrade Rails, Technical Recruitment
About
About
About
What's a test double?
Approach
Meeting you where you are
Founder's Story
The origin of our mission
Culture
Culture
Culture & Careers
Double Agents decoded
Great Causes
Great code for great causes
EDI
Equity, diversity & inclusion
Insights
Insights
All Insights
Hot takes and tips for all things software
Leadership
Bold opinions and insights for tech leaders
Developer
Essential coding tutorials and tools
Product Manager
Practical advice for real-world challenges
Say hello
Developers
Developers
Developers
Software tooling & tips

How to completely uninstall and reinstall Homebrew Postgres

Is Postgres erroring with "could not read block 39" or "bad address"? If you installed Postgres via Homebrew on a Mac, here's the quickest way to wipe the slate clean with a fresh install
Justin Searls
|
January 27, 2021
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Lately, I’m finding that Postgres is becoming more and more vital to my development workflow. My days of leaning on an ORM like Rails' ActiveRecord in order to get away with treating the database as a dumb hash are long behind me.

As a result, even though I’ve optimized my development setup for quickly wiping and reinitializing my entire Mac, lately I’ve found myself needing to frequently clear out any trace of my Postgres installation. In particular, and while I absolutely adore my M1 Mac, a few people have noticed that—for whatever reason—Postgres can experience some data corruption issues when run under Rosetta. Specifically, I’ve been seeing a lot of errors that look like this lately:

PG::InternalError: ERROR:
  could not read block 138 in file "base/645837/646529":
    Bad address:

Even though the errors are erratic and typically disappear when I try the query again, that doesn’t do much to inspire confidence that whatever I’m working on isn’t going to blow up in production. The “right” thing to do would be to dig in and figure out what’s causing this. Maybe Rosetta isn’t enabled in every context? Maybe there’s a bug in architecture-specific code inside Postgres? Maybe the otherwise flawless Rosetta team missed a spot?

Unfortunately, I don’t have the time or expertise to perform a root cause analysis of why my local Postgres installation is borked—I just want to make the hurting stop. So, I stuck to what I know: firing off a drive-by tweet and then nuking my installation and starting over.

Completely uninstalling a Homebrew installation of Postgres

Okay, so now that you’ve read my life story, we can get to the recipe.

Here are a few quick steps to uninstall Postgres, verify you deleted everything, and then reinstall it.

It should go without saying, but beware: running these commands will delete all your local Postgres databases. With that warning out of the way, here are the lines to blindly copy and paste into your terminal:

$ brew uninstall postgres
$ rm -rf /usr/local/var/postgres
$ rm /usr/local/var/log/postgres.log
$ rm -f ~/.psqlrc ~/.psql_history

It might seem like brew uninstall postgres should be sufficient, but it alone won’t actually delete any of your data (which will be left behind in /usr/local).

But did that remove everything?

Want to make sure you didn’t miss anything? Feel free to kick the tires a bit more.

If you want to make sure there are no other Postgres-adjacent Homebrew formulae still installed:

$ sudo find / -name "*postgres*" -o -name "*psql*"

[Note: By the way, are you ever annoyed when you accidentally paste a leading $ character from a code snippet into your terminal? Consider adding an executable on your PATH like this one that will effectively turn $ into a no-op that’s safe to paste.]

You can also search your entire system for file name matches:

$ sudo find / -name "*postgres*" -o -name "*psql*"

Because the above command scans your entire disk, don’t be surprised if the it triggers permission pop-ups for Terminal.app app to access your Desktop, Documents, Contacts, Photos, etc.

Re-installing Postgres

If you’re as paranoid as I am, you’ve probably already restarted your computer several times while reading this post. But in case you haven’t yet, it might be a good time to reboot your machine. Come back here once you’re ready to experience that fresh database feeling.

First, to make sure you’re getting the latest and greatest of everything, make sure Homebrew is fully updated:

$ brew update

Then give Homebrew a chance to diagnose any problems:

$ brew doctor

If you’re not familiar with brew doctor, the name of the game is to keep doing what it tells you and re-running it until it exits cleanly with the simple message:

$ brew doctor
> Your system is ready to brew.

Now, to actually install Postgres and ensure that it’s running:

$ brew install postgres
$ brew services start postgresql

Several Postgres commands and apps will assume that there exists a database of the same name as your user account, so it’s best to create one straight away:

$ createdb `whoami`

If all those commands succeeded, you should be ready to roll with a clean, not-yet-corrupted Postgres installation. I look forward to seeing you again the next time it manages to get gunked up!

Software secrets, straight to you

Join the Test Double Dispatch for hot takes, industry trends, tooling tips, and tricks to level up your coding—delivered monthly.

Sign up now

Related Insights

🔗
How to fake time in a Postgres database
🔗
16 things software developers believe, per a Justin Searls survey
🔗
The looming demise of the 10x developer

Explore our insights

See all insights
Leadership
Leadership
Leadership
Audentes Fortuna Iuvat: being bold amidst uncertainty

What should businesses do in the face of uncertainty? This is not the first time leaders are dealing with strange economic environments, and it won’t be the last.

by
Ed Frank
Developers
Developers
Developers
LLMallard: the low-key AI chat bot you secretly need

The most perfect dev workflow for taking advantage of deeply powerful AI tooling that’s hyper efficient on token usage with minimal API calls—and the perfect pair programming partner.

by
Daniel Huss
Leadership
Leadership
Leadership
Why we coach the system, not just the team

Slow delivery isn’t usually about your people—it’s about your system. Shifting focus to incremental improvements in the system helps change not just processes but behaviors for lasting change.

by
Doc Norton
Letter art spelling out NEAT

Join the conversation

Technology is a means to an end: answers to very human questions. That’s why we created a community for developers and product managers.

Explore the community
Test Double Executive Leadership Team

Learn about our team

Like what we have to say about building great software and great teams?

Get to know us
No items found.
Test Double company logo
Improving the way the world builds software.
What we do
Services OverviewSoftware DeliveryProduct ManagementLegacy ModernizationDevOpsUpgrade RailsTechnical RecruitmentTechnical Assessments
Who WE ARE
About UsCulture & CareersGreat CausesEDIOur TeamContact UsNews & AwardsN.E.A.T.
Resources
Case StudiesAll InsightsLeadership InsightsDeveloper InsightsProduct InsightsPairing & Office Hours
NEWSLETTER
Sign up hear about our latest innovations.
Your email has been added!
Oops! Something went wrong while submitting the form.
Standard Ruby badge
614.349.4279hello@testdouble.com
Privacy Policy
© 2020 Test Double. All Rights Reserved.

Software secrets, straight to you

Join the Test Double Dispatch for hot takes, industry trends, tooling tips, and tricks to level up your coding—delivered monthly.

Sign up now