Fedya Savchuk
Fedya Savchuk

Reputation: 157

Problem with Postgres: "pg_ctl: could not start server"

When I execute command:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

I get this error:

pg_ctl: another server might be running; trying to start server anyway
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output

My postgres started:

brew services start postgresql

Upvotes: 3

Views: 39998

Answers (5)

Laurenz Albe
Laurenz Albe

Reputation: 248030

You should proceed like this:

  1. Look at /usr/local/var/postgres/postmaster.pid. In the first line, you will find a process ID.

  2. Look if there is a process running with the process ID found in the first step.

    • If yes, check if it is a PostgreSQL process.

      • If yes, then your server is already running.

      • if not, remove postmaster.pid (but never, ever remove that file if the process ID belongs to a PostgreSQL process). Then start PostgreSQL like indicated in the next step.

    • If not, start PostgreSQL again like you did, but add -t 1000 to pg_ctl, so that it waits 1000 seconds for PostgreSQL to start up.

Upvotes: 7

Anupam
Anupam

Reputation: 15620

I had a different problem - so documenting it in case it helps someone. Another process (Chrome) had the same PID which was previously assigned to Posgres.

While following @Laurenz Albe's answer (which helped me figure this out), this is what happened:

  1. I ran cat /Users/<my-user>/Library/Application Support/Postgres/var-9.6/postmaster.pid (that's where the file was on my Mac)

  2. First line gave a process ID. I searched for it: ps -ef | grep <id-from-first-line-above>

  3. Chrome was running on that ID :)

  4. I quit Chrome (manually)

  5. Postgres started up fine (I am using the Postgres app)

Upvotes: 0

Safi50
Safi50

Reputation: 361

The error clearly highlights that there is already a postgreSQL server. So, first kill the existing server to free up that port using

Note: Change port number if your server is running on a port different than the default one

lsof -i tcp:5432    

This will return any existing processes running on that port and return their PID. Copy the PID and run the following to kill the process.

sudo kill PID
  • Replace PID with your process's PID.

Upvotes: 0

Lafifi Hamza
Lafifi Hamza

Reputation: 1

I am faced like this problem, when i ran CMD as administrator, the command worked

Upvotes: 0

ZediousZ
ZediousZ

Reputation: 23

In windows, look for postgres processes running in background.

To kill with command line, taskkill /f /IM postgres*

Upvotes: 2

Related Questions