user8063779
user8063779

Reputation:

How to remove a postgresql user

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.

Upvotes: 4

Views: 14399

Answers (3)

Ravi
Ravi

Reputation: 1

First run the command

sudo su

Enter the user password for root access.

Then run the below command

su - postgres -c "dropuser www-dtata"

No password will be prompted

Upvotes: -1

Vasyl Moskalov
Vasyl Moskalov

Reputation: 4650

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

Upvotes: 6

Nick
Nick

Reputation: 2513

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.

Upvotes: 2

Related Questions