Fix PostgreSQL error: Stale postmaster.pid file on macOS

Fix PostgreSQL error: Stale postmaster.pid file on macOS

Sometimes when you mac shuts down unexpectedly while running a PostgreSQL database it can result in the following error:

Stale postmaster.pid file.

  • The data directory contains an old postmaster.pid file.
  • FATAL: lock file “postmaster.pid” already exists
  • Fix PostgreSQL error: Stale postmaster.pid file on macOS

The following tutorial will show you how to delete the postmaster.pid file so that you can restart your PostgreSQL service and run it as intended.

1: Open your terminal

You can find your terminal your applications folder, or use the launcher by clicking cmd + spacebar and search for "terminal".

2: Locate your Postgres directory

How you locate the Postgres directory and pid file will vary from situation to situation as it depends on how you installed PostgreSQL in the first place.

But most commonly your Postgress installation will be located here:

cd Library/Application\ Support/Postgres

3: Locate the postmaster.pid file

Make sure that you are in the right directory by typing ls in your terminal. This will list out all the files and directories of your current location.

If you are in the right place the terminal should show a folder name var-10 if you are running PostgreSQL 10. If you running PostgreSQL 11 the folder will be named var-11, you get the point.

Enter the folder with a cd.

cd var-10

Run an ls to list the folder contents.

var-10 ls

This should list the inner contents of the version specific postgres folder.

PG_VERSION           pg_notify            pg_wal
base                 pg_replslot          pg_xact
global               pg_serial            postgresql.auto.conf
pg_commit_ts         pg_snapshots         postgresql.conf
pg_dynshmem          pg_stat              postgresql.log
pg_hba.conf          pg_stat_tmp          postmaster.opts
pg_ident.conf        pg_subtrans          postmaster.pid
pg_logical           pg_tblspc
pg_multixact         pg_twophase

As you can see among the files you find the postmaster.pid, perfect.

4: Remove the postmaster.pid file

Go ahead and remove the postmaster.pid file by running a rm "filename"

rm postmaster.pid

When you have removed the stale postmaster.pid file you can restart PostgreSQL and everything should work as normal.

Freddie Freddie 4 years, 9 months ago 0
Login to Comment
No comments have been posted yet, be the first one to comment.
How to Install Deno on macOS
How to Install Deno on macOS
Deno is a simple, modern and secure runtime for JavaScript and TypeScript, by the creator of Node.js himself, Ryan Dahl. Deno uses the Chrome v8 engine and is built with Rust. The project just reach version 1.0 and got many people in the JavaScript community interested. In this tutori...
Create, Access and Use SSH Keys with macOS
Create, Access and Use SSH Keys with macOS
SSH or "Secure Shell" is a network protocol for operating networked services securely. It is typically used for remote command-line authentication and command execution. In this tutorial I will show you how you can create, access and use your SSH key for macOS. 1. Open Termi...
How to Create & Setup Dokku Applications & Databases
How to Create & Setup Dokku Applications & Databases
As I have mentioned many of times before, Dokku rocks! Dokku is a free and open-source project that helps you build and manage the lifecycle of your applications. Dokku does is it by leveraging the power of Docker and Heroku Buildpacks. It's perfect for solo developers or small teams ...