PostgreSQL – Drop User

To delete or drop a user from PostgreSQL, run DROP USER command. The syntax is as shown below.

DROP USER [ IF EXISTS ] username [, ...]

where username is the name of the user you would like to drop from PostgreSQL.

IF EXISTS which is optional checks if the user is available and then proceeds with the action.

You can drop more than one user at a time, by provided the user names separated by comma.

Example 1 – Delete a User

Consider a PostgreSQL where there are two users as shown in the following.

ADVERTISEMENT
PostgreSQL - List Users

In this example, we are going to drop user lini. To delete the user, we run the following command.

DROP USER IF EXISTS lini;
PostgreSQL DROP USER

The user is successfully deleted from PostgreSQL database.

Example 2 – Delete multiple Users

Consider a PostgreSQL where there are four users as shown in the following.

In this example, we are going to drop users lini, kiku and jobin. To delete these multiple users, we run the following command.

DROP USER IF EXISTS lini, kiku, jobin;
PostgreSQL - Drop multiple users

The user is successfully deleted from PostgreSQL database.

Conclusion

In this PostgreSQL Tutorial, we deleted single or multiple users in PostgreSQL using DROP USER query.