title: postgresql pg_ctl start timed out
body: <p>My system is running on CentOS 7.4 and we used systemd service to start the postgresql 9.2.21 server. postgresql is started by the following commands:</p>
  
  <pre><code>ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA}
  ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 -l /tmp/log
  </code></pre>
  
  <p>pg_ctl returned start timed out intermittently. It failed with "postgresql.service start operation timed out." error.  Running <strong>systemctl status postgresql</strong> showed the following:</p>
  
  <pre><code>â postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
     Active: failed (Result: timeout) since Thu 2020-02-13 15:57:02 PST; 52s ago
    Process: 1098 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 -l /tmp/log (code=killed, signal=TERM)
    Process: 1021 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
  
  Feb 13 23:52:02 server systemd[1]: Starting PostgreSQL database server...
  Feb 13 23:52:03 server pg_ctl[1098]: pg_ctl: another server might be running; trying to start server anyway
  Feb 13 15:57:02 server systemd[1]: postgresql.service start operation timed out. Terminating.
  Feb 13 15:57:02 server systemd[1]: Failed to start PostgreSQL database server.
  Feb 13 15:57:02 server systemd[1]: Unit postgresql.service entered failed state.
  Feb 13 15:57:02 server systemd[1]: postgresql.service failed.
  </code></pre>
  
  <p>The output logs of the pg_ctl:</p>
  
  <pre><code>2020-02-13 23:52:05 UTC LOG:  database system was interrupted; last known up at 2020-02-13 23:49:55 UTC
  2020-02-13 23:52:21 UTC LOG:  database system was not properly shut down; automatic recovery in progress
  2020-02-13 23:52:21 UTC LOG:  record with zero length at 0/1CEDFD8
  2020-02-13 23:52:21 UTC LOG:  redo is not required
  2020-02-13 23:52:21 UTC LOG:  database system is ready to accept connections
  2020-02-13 23:52:21 UTC LOG:  autovacuum launcher started
  2020-02-13 23:57:02 UTC LOG:  received smart shutdown request
  2020-02-13 23:57:02 UTC LOG:  autovacuum launcher shutting down
  2020-02-13 23:57:02 UTC LOG:  shutting down
  2020-02-13 23:57:03 UTC LOG:  database system is shut down
  </code></pre>
  
  <p>The above log showed the database was started up successfully and I actually could sql to the database until the database was shutdown by pg_ctl.  According to the pg_ctl manpage, it will repeatedly attempts to connect to the server. I wonder why pg_ctl cannot connect to the server and exit but I can manually do that during the startup.</p>
  
  <p>Thanks
  Patrick</p>