code: def handle_starting_instance(self):
          
  
          # Check if we are in startup, when paused defer to main loop for manual failovers.
          if not self.state_handler.check_for_startup() or self.is_paused():
              self.set_start_timeout(None)
              if self.is_paused():
                  self.state_handler.set_state(self.state_handler.is_running() and 'running' or 'stopped')
              return None
  
          # state_handler.state == 'starting' here
          if self.has_lock():
              if not self.update_lock():
                  logger.info("Lost lock while starting up. Demoting self.")
                  self.demote('immediate-nolock')
                  return 'stopped PostgreSQL while starting up because leader key was lost'
  
              timeout = self._start_timeout or self.patroni.config['master_start_timeout']
              time_left = timeout - self.state_handler.time_in_state()
  
              if time_left <= 0:
                  if self.is_failover_possible(self.cluster.members):
                      logger.info("Demoting self because master startup is taking too long")
                      self.demote('immediate')
                      return 'stopped PostgreSQL because of startup timeout'
                  else:
                      return 'master start has timed out, but continuing to wait because failover is not possible'
              else:
                  msg = self.process_manual_failover_from_leader()
                  if msg is not None:
                      return msg
  
                  return 'PostgreSQL is still starting up, {0:.0f} seconds until timeout'.format(time_left)
          else:
              # Use normal processing for standbys
              logger.info("Still starting up as a standby.")
              return None
docs: Starting up PostgreSQL may take a long time. In case we are the leader we may want to
          fail over to.