Why PostgreSQL can't create user? Use this ansible playbook to install PostgreSQL and create a user:

---
- name: Download PostgreSQL 10
  get_url:
    url: https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    dest: /usr/local/src/pgdg-redhat-repo-latest.noarch.rpm

- name: Install PostgreSQL 10 rpm
  yum:
    name: /usr/local/src/pgdg-redhat-repo-latest.noarch.rpm
    state: present

- name: Install epel-release rpm
  yum:
    name: epel-release
    state: present

- name: Install PostgreSQL 10
  yum:
    name: ['postgresql10-server', 'postgresql10']
    state: present
    update_cache: yes

- name: Update .bash_profile
  copy:
    src: bash_profile
    dest: /var/lib/pgsql/.bash_profile
    owner: postgres

- name: Source bash_profile
  shell: source /var/lib/pgsql/.bash_profile
  become: true

- name: Initialize the Database
  command: /usr/pgsql-10/bin/postgresql-10-setup initdb
  become: true
  ignore_errors: yes

- name: Set postgresql.conf
  copy:
    src: postgresql.conf
    dest: /var/lib/pgsql/10/data/postgresql.conf
    owner: postgres

- name: Set pg_hba.conf
  copy:
    src: pg_hba.conf
    dest: /var/lib/pgsql/10/data/pg_hba.conf
    owner: postgres

- name: Install repmgr repository
  get_url:
    url: https://dl.2ndquadrant.com/default/release/get/10/rpm
    dest: /var/lib/pgsql/repmgr

- name: Install repmgr rpm
  shell: bash /var/lib/pgsql/repmgr

- name: Install repmgr
  yum:
    name: repmgr10
    state: present

- name: Enable and Start PostgreSQL
  systemd:
    name: postgresql-10
    state: started
    enabled: yes

- name: Create repmgr user
  command: createuser -s repmgr
  become: true
  become_user: postgres
  ignore_errors: yes


It pending for a longtime, no response. What's the reason?

Even I login with psql try to create user by:

CREATE USER testuser;


The same it got pending without any response.
There must be a lock on a system catalog preventing the update. This is a pretty unusual occurrence.


Check pg_stat_activity for long running transactions that are not in state idle. Cancel those.
Look for prepared transactions in pg_prepared_statements and roll them back.


If both don't help, have a look at pg_locks while your CREATE USER hangs. It will show you for which transaction the statement is waiting.