Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a postgresql user

Tags:

postgresql

I followed this tutorial and made a typo where I was supposed to create a user for my django apps to connect as;

I was supposed to run su - postgres -c "createuser www-data -P" but I ran su - postgres -c "createuser www-dtata -P".

I dont want to proceed until I remove that user, which I don't know the command for. I found and tried DROP USER after searching around, but the terminal returned -su: DROP: command not found.


2 Answers

Run sudo su - postgres -c "dropuser www-dtata"

like image 109
Vasyl Moskalov Avatar answered Oct 22 '25 01:10

Vasyl Moskalov


You can use dropuser console tool (see https://www.postgresql.org/docs/current/static/app-dropuser.html):

su - postgres -c "dropuser www-dtata"

Or use DROP USER SQL query (see https://www.postgresql.org/docs/current/static/sql-dropuser.html):

sudo -u postgres psql -c 'DROP USER "www-dtata";'

These 2 approaches do the same thing. In SQL version, you also need to use double quotes around DB user name, due to - in it.

like image 26
Nick Avatar answered Oct 22 '25 00:10

Nick