w3resource

How to Change a PostgreSQL User’s Password?


Change a User’s Password

Write a PostgreSQL query to update the password for the user app_user to a new value.

Solution:

-- Change the user's password
ALTER USER app_user WITH PASSWORD 'NewSecurePass456';

Explanation:

  • Purpose of the Query:
    • Changes the password of an existing user.
  • Key Components:
    • ALTER USER app_user: Targets the specific user.
    • WITH PASSWORD 'NewSecurePass456': Assigns a new password.
  • Real-World Application:
    • Password rotation is an essential security practice.

Notes:

  • Password changes should be enforced periodically for security.

For more Practice: Solve these Related Problems:

  • Write a PostgreSQL query to update the password for the user marketing_lead and force a password history check.
  • Write a PostgreSQL query to change the password for the user finance_manager ensuring it includes at least one numeric character.
  • Write a PostgreSQL query to modify the password for the user support_agent and log the change timestamp in a separate audit table.
  • Write a PostgreSQL query to update the password for the user ceo_account and notify a security trigger upon change.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous PostgreSQL Exercise: Revoke a User’s Privileges.

Next PostgreSQL Exercise: Assign a User to a Role.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.