Databases

Unlock Locked Oracle DB Account

In this post, we will learn how to use the Oracle ALTER USER ACCOUNT UNLOCK statement.
Captain Salem 1 min read
Unlock Locked Oracle DB Account

As a database administrator, you often encounter instances where you need to unlock a locked database account.

A locked account refers to an account that has been disabled either by the database administrator or in cases of excessive failed authentication requests. There are other reasons an account can be locked, but we will not discuss that in this tutorial.

Once an account has been locked or disabled, the said account cannot log in unless the database administrator unlocks that account.

This is what we are going to discuss in this tutorial.

Oracle Create Test User

To best illustrate how we can unlock a user in Oracle, let us start by creating a test user for demonstration purposes.

Login into the database administrator:

$ sqlplus sys as sysdba;
Enter password:

Once logged in, alter the session to enable Oracle scripting mode. Scripting mode allows us to execute multiple SQL statements without executing sequentially. It may also prevent various errors when creating a User:

ALTER SESSIO SET "_ORACLE_SCRIPT"=true;

Next, create a user:

CREATE USER test_user IDENTIFIED BY password;

Once the user is created, let us manually lock the account to simulate an Oracle account.

We can do this by using the ALTER USER command as shown:

SQL> ALTER USER test_user ACCOUNT LOCK;
User altered.

Once the account is locked, we can unlock it by replacing the LOCK keyword in the command above to UNLOCK.

ALTER USER test_user ACCOUNT UNLOCK;

NOTE: If the account has failed due to incorrect password attempts or password expiration, it is recommended to reset the password; otherwise, it will remain expired.

You can do this by adding the IDENTIFIED BY clause followed by the new password. Example:

ALTER USER test_user IDENTIFIED BY new_password ACCOUNT UNLOCK;

This will reset the password and allow the user to set a new password.

Summary

In this post, you encountered the Oracle ALTER USER ACCOUNT UNLOCK clause that allows you to unlock a locked database account. Locking a database user is an incredible security feature when used correctly. However, it can lead to the locking of legitimate accounts when misused.

Share
Comments
More from Cloudenv
SQL XOR Operator
Databases

SQL XOR Operator

Let us explore what the XOR operator in SQL does and how we can use it. For demonstration purposes, we will use MySQL as the base database system.
Captain Salem 2 min read

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.