How to Lock a PostgreSQL User Account?
Lock a User Account
Write a PostgreSQL query to disable the login capability for inactive_user.
Solution:
-- Lock a user account
ALTER ROLE inactive_user NOLOGIN;
Explanation:
- Purpose of the Query:
- Prevents inactive_user from logging in.
- Key Components:
- ALTER ROLE inactive_user NOLOGIN: Disables authentication.
- Real-World Application:
- Useful for suspending inactive users.
For more Practice: Solve these Related Problems:
- Write a PostgreSQL query to lock a user account and set an expiration date for the lockout period.
- Write a PostgreSQL query to disable a user's login and immediately send a notification to the system administrator.
- Write a PostgreSQL query to lock multiple user accounts that have not been active for a specified time period.
- Write a PostgreSQL query to disable login for a user and check if the account is already locked before applying the change.
Go to:
PREV : Remove a User.
NEXT : Create a Role with Limited Connection Attempts.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
