Fix PostgreSQL error: Stale postmaster.pid file on macOS

Database Management Database Management
macOS macOS
PostgreSQL PostgreSQL

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

Stale postmaster.pid file.

or

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

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.

Did You Enjoy the Tutorial?

Consider sending some love to Freddie the creator.

Comments (0)

You need to be logged in to comment..

Topics Mentioned in this Tutorial

Database Management
2
0
5
Data Management is a process that comprises all disciplines related to managing data as a resource. It applies to both physical and digital data, however, in this day and age most database management refers to later. Database management has become more vital to every day business and the world we live in today. With well managed data, business, industry and the public can derive valuable information that can be used in decision making and prediction. When managing data its important to have an overall knowledge of the underlaying database and its structure. The process also involves ...
macOS
3
0
2
MacOS (Macintosh Operating System) is an operating system create by Apple for their line of laptops and desktop computers. MacOS features a sleek design with a global menu, dock and multi tasking features combined with the security and stability that so many has come to love. The operating system was first introduced in 1984 as Macintosh System Software, which later became System Software 2,3,4,5 and 6 the Mac OS 8,9. Then moved on to the OS X convention between 2001-2015 and now has settle with the current naming convention for the foreseeable future....
PostgreSQL
4
0
7
PostgreSQL, also known as Postgres, is a relational database management system (RDBMS) that is free and open-source. The software is widely popular for storing relation data for web-base applications. PostgreSQL emphasise extensibility and technical standards compliance. Which make the database used for a wide variety of web services with many concurrent users. PostgreSQL can be deployed on a single machine or spread out on clusters among different data centers....