Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix stale postmaster.pid file on Postgres?

I went to view a postgres schema on my local (MacOS 11) database, and was not able to view my schemas. Connection Refused in DBeaver!

connection refused DBeaver

So I opened my postgres desktop application, and got the warning message, "Stale postmaster.pid file"

How can I fix this?

stale Postmaster.pid postgres 12 dashboard screenshot

like image 471
dustbuster Avatar asked Mar 18 '21 15:03

dustbuster


People also ask

What is postmaster pid file in Postgres?

PostgreSQL puts a file named postmaster. pid in the data directory to store the process id of the PostgreSQL server process. If PostgreSQL crashes, this file can contain an old pid that confuses PostgreSQL. You can fix this issue by deleting the postmaster.

Where is Postgres postmaster pid?

The postmaster PID file resides on the data directory when the cluster is up and running.

Where is postmaster pid Mac?

In Mac Sierra you can find postmaster. pid inside /Users/<user_name>/Library/Application Support/Postgres/var-9.6 .

Where is Postgres installed on Mac?

The actual database files will be under /usr/local/var/postgres after you create the database.


2 Answers

The problem is that the postmaster.pid file needs to be removed manually and regenerated by postgres, and these are the steps to do it. (Keep in mind the version might change, var-12, might be var-13 etc)

  1. Open your terminal, and cd into the postgres directory: cd /Users/<user_name>/Library/Application\ Support/Postgres
  2. Make sure you're in the right place, ls you should see something like var-12 or var-<version #>
  3. Verify the file is there, ls var-12 (keep in mind the var-XX is equivalent to your PGSQL version)
  4. Verify the Postgres server is not running by viewing desktop app

Version might change so could be var-12, var-13, etc etc depending on age of this article.

Library/Application Support/Postgres ➜ ls var-12 PG_VERSION           pg_hba.conf          pg_replslot          pg_subtrans          postgresql.auto.conf base                 pg_ident.conf        pg_serial            pg_tblspc            postgresql.conf global               pg_logical           pg_snapshots         pg_twophase          postgresql.log pg_commit_ts         pg_multixact         pg_stat              pg_wal               postmaster.opts pg_dynshmem          pg_notify            pg_stat_tmp          pg_xact              postmaster.pid <---- 
  1. Then remove postmaster.pid, rm var-12/postmaster.pid
  2. or rm var-<PG version #>/postmaster.pid
  3. Go back to your console, start your postgres server, and it should be functioning again, and you should have full access to your schemas.
like image 153
dustbuster Avatar answered Sep 17 '22 13:09

dustbuster


In my case I used the code rm var-13/postmaster.pid and solved.

like image 23
Jonatha Costa Lima Avatar answered Sep 20 '22 13:09

Jonatha Costa Lima