PostgreSQL – User Management

First login to PostGre
Run this command:

su - postgres


Now run:

createuser --role=postgres --superuser --createdb -P testik

Here all roles:
superuser, createrole, createdb, replication, bypassrls
You will  prompt to enter password to new role( user) enter your password twice

Now you will prompt to insert password of ‘postgres

Now open postgres shell with command from linux cli:

sudo -u postgres psql postgres

To check all existing users:

SELECT username FROM pg_user;

To check user roles

\du

To revoke all privileges

REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM Testik;
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM Testik;
REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM Testik;
REVOKE ALL PRIVILEGES ON DATABASE "postgres" FROM Testik;
DROP USER Testik;

Delete user

DROP USER Testik;