code: def stop(self, mode='fast', block_callbacks=False, checkpoint=None, on_safepoint=None):
          
          if checkpoint is None:
              checkpoint = False if mode == 'immediate' else True
  
          success, pg_signaled = self._do_stop(mode, block_callbacks, checkpoint, on_safepoint)
          if success:
              # block_callbacks is used during restart to avoid
              # running start/stop callbacks in addition to restart ones
              if not block_callbacks:
                  self.set_state('stopped')
                  if pg_signaled:
                      self.call_nowait(ACTION_ON_STOP)
          else:
              logger.warning('pg_ctl stop failed')
              self.set_state('stop failed')
          return success
docs: Stop PostgreSQL
  
          Supports a callback when a safepoint is reached. A safepoint is when no user backend can return a successful
          commit to users. Currently this means we wait for user backends to close. But in the future alternate mechanisms
          could be added.
  
          :param on_safepoint: This callback is called when no user backends are running.