docs: def _run_initdb(name,
          auth='password',
          user=None,
          password=None,
          encoding='UTF8',
          locale=None,
          runas=None,
          waldir=None,
          checksums=False):
      '''
      Helper function to call initdb
      '''
      if runas is None:
          if 'FreeBSD' in __grains__['os_family']:
              runas = 'pgsql'
          elif 'OpenBSD' in __grains__['os_family']:
              runas = '_postgresql'
          else:
              runas = 'postgres'
  
      if user is None:
          user = runas
      _INITDB_BIN = _find_pg_binary('initdb')
      if not _INITDB_BIN:
          raise CommandExecutionError('initdb executable not found.')
      cmd = [
          _INITDB_BIN,
          '--pgdata={0}'.format(name),
          '--username={0}'.format(user),
          '--auth={0}'.format(auth),
          '--encoding={0}'.format(encoding),
          ]
  
      if locale is not None:
          cmd.append('--locale={0}'.format(locale))
  
      # intentionally use short option, as the long option name has been
      # renamed from "xlogdir" to "waldir" in PostgreSQL 10
      if waldir is not None:
          cmd.append('-X')
          cmd.append(waldir)
  
      if checksums:
          cmd.append('--data-checksums')
  
      if password is not None:
          pgpassfile = salt.utils.files.mkstemp(text=True)
          with salt.utils.files.fopen(pgpassfile, 'w') as fp_:
              fp_.write(salt.utils.stringutils.to_str('{0}'.format(password)))
              __salt__['file.chown'](pgpassfile, runas, '')
          cmd.extend([
              '--pwfile={0}'.format(pgpassfile),
          ])
  
      kwargs = dict(runas=runas, clean_env=True)
      cmdstr = ' '.join([pipes.quote(c) for c in cmd])
      ret = __salt__['cmd.run_all'](cmdstr, python_shell=False, **kwargs)
  
      if ret.get('retcode', 0) != 0:
          log.error('Error initilizing the postgres data directory')
  
      if password is not None and not __salt__['file.remove'](pgpassfile):
          log.warning('Removal of PGPASSFILE failed')
  
      return ret