Oracle dba_users: List All User Account Information
Oracle dba_users: List All User Account Information
Purpose
DBA_USERS is the data dictionary view that describes all users of the database. Each row is one account. The row shows the account status, the creation date, the default tablespace and the temporary tablespace. Other columns show the profile, the password expiry date and, in newer releases, the last login time.
The query below reads that view and prints one line per account, sorted by name. A DBA runs it to see who has an account, which accounts are locked or expired, and where each account stores its data. It is a good first query on a database you do not know yet.
The view lists accounts, not connections. It tells you that an account exists and what state it is in. It does not tell you who is logged in at this moment. Use the session views for that question.
Code
1set pages 999 lines 100
2col username format a20
3col status format a8
4col tablespace format a20
5col temp_ts format a20
6select username
7, account_status status
8, created
9, default_tablespace tablespace
10, temporary_tablespace temp_ts
11from dba_users
12order by username
13/
A second query narrows the list to accounts that people created. It hides the accounts that Oracle-supplied scripts created, and it adds the profile and the password expiry date.
1set pages 999 lines 120
2col username format a25
3col account_status format a20
4col profile format a20
5select username
6, account_status
7, profile
8, expiry_date
9, lock_date
10from dba_users
11where oracle_maintained = 'N'
12order by username
13/
A third query uses ALL_USERS. This view is the one a user without access to DBA_USERS can read. It shows fewer columns.
1select username
2, user_id
3, created
4, common
5from all_users
6order by username
7/
Code Breakdown
SQL*Plus formatting lines
set pages 999 lines 100sets two things.pagesis the page size: the number of lines on each page of output.linesis the line size: the total number of characters SQL*Plus shows on one line before it starts a new line. A page size of 999 means the column headings repeat less often.col username format a20sets the display width of theusernamecolumn to 20 characters. Theastands for alphabetic. The same pattern sets the width ofstatus,tablespaceandtemp_ts.- If a width is shorter than the column heading, SQL*Plus cuts the heading. The first query uses a narrow width of 8 for
status. Longer values such asEXPIRED & LOCKEDneed more room, so the second query uses a wider column.
The select list of the first query
usernameis the name of the user.account_status statusreturns the account status and gives the column the short aliasstatus.createdis the date the user was created.default_tablespace tablespaceis the default tablespace for the data of this user.temporary_tablespace temp_tsis the name of the default tablespace for temporary tables. It can also be the name of a tablespace group.order by usernamesorts the result by name so you can find an account fast.
The second query
where oracle_maintained = 'N'keeps only the users that Oracle-supplied scripts did not create. The column isYfor a user that Oracle scripts created and maintain.profileshows the resource profile of the user. The profile holds the password rules, so it explains why an account locks or expires.expiry_dateis the date the account expires.lock_dateis the date the account was locked, if the status wasLOCKED.
The third query
all_userslists all users of the database that are visible to the current user. Compare this withdba_users, which describes all users.commonshowsYESfor a common user andNOfor a local user. This matters in a multitenant database.
Key Points
DBA_USERShas more columns than the first query shows. Useful ones areUSER_ID,PROFILE,EXPIRY_DATE,LOCK_DATE,AUTHENTICATION_TYPE,COMMON,ORACLE_MAINTAINEDandLAST_LOGIN.ACCOUNT_STATUSholds more than three values. The simple ones areOPEN,EXPIRED,EXPIRED(GRACE),LOCKEDandLOCKED(TIMED). Combined values also exist, such asEXPIRED & LOCKED.LAST_LOGINis not filled when a user connects with an administrative privilege such asSYSDBA,SYSOPERorSYSBACKUP. A blank value does not prove that the account was never used.ORACLE_MAINTAINEDmarks accounts that Oracle-supplied scripts created. The documentation says such a user must not be changed in any way except by running an Oracle-supplied script.- In a multitenant database, a common user should connect to the CDB root when it queries
DBA_USERS. This makes sure the result is complete. - The
PASSWORDcolumn is deprecated. UseAUTHENTICATION_TYPEto see how an account logs in.
Insights and Best Practices
Read the account status correctly
The status tells you why a user cannot log in. Use this table when you read the output.
OPENmeans the account is open.EXPIREDmeans the password is expired. Either thePASSWORD_LIFE_TIMElimit was reached, or someone ranALTER USER ... PASSWORD EXPIRE.EXPIRED(GRACE)means thePASSWORD_LIFE_TIMElimit was reached, but thePASSWORD_GRACE_TIMEperiod has not ended yet.LOCKEDmeans the account is locked. Either someone ranALTER USER ... ACCOUNT LOCK, or failed logins went overFAILED_LOGIN_ATTEMPTSwhilePASSWORD_LOCK_TIMEisUNLIMITED.LOCKED(TIMED)means the account is locked because of failed logins, and thePASSWORD_LOCK_TIMEperiod has not ended yet.OPEN & IN ROLLOVERmeans the account is in the password rollover period. The user can log in with the earlier password or the new password.
Do not treat all of these the same way. LOCKED(TIMED) is tied to the PASSWORD_LOCK_TIME period. LOCKED has no lock period that runs out: either a DBA locked the account, or PASSWORD_LOCK_TIME is UNLIMITED.
Separate your accounts from Oracle accounts
Oracle-supplied scripts create some accounts for you. Filter with oracle_maintained = 'N' when you review accounts for an audit. Use oracle_maintained = 'Y' when you want to confirm that Oracle accounts stay locked and unchanged. Do not alter these accounts by hand.
Check how each account authenticates
The AUTHENTICATION_TYPE column shows the method. PASSWORD means the user was created with IDENTIFIED BY. EXTERNAL means IDENTIFIED EXTERNALLY. GLOBAL means IDENTIFIED GLOBALLY. NONE means no method is set for the user. Add this column when you want to find accounts that use a password and accounts that do not.
Also look at PASSWORD_VERSIONS. It lists the password hash versions stored for the account, such as 10G, 11G and 12C. An account that keeps only an old verifier may need a password change.
Use the multitenant columns
In a multitenant database, COMMON tells you if a user is common or local. INHERITED tells you if the user definition came from another container. When you work in a pluggable database, check which container your session is in before you trust the result. A common user should query from the CDB root to get complete information.
Keep the report simple
Spool the result to a file with a date in the name and keep it. Two reports from different weeks show you new accounts, removed accounts and status changes. A simple text comparison is enough.
When to Use This Check
- At the start of work on a database that is new to you
- Before an audit, to list every account and its profile
- When a user reports that a login fails, to see if the account is locked or expired
- Before you drop a tablespace, to find the users that name it as default or temporary
- After an application release, to find new accounts
- When you plan a password policy change and need the list of profiles in use
Troubleshooting Common Issues
If the query returns an error that the table or view does not exist, your account cannot read DBA_USERS. Run the third query against ALL_USERS instead. It lists the users that are visible to you. You can also ask the DBA team for access.
If the output looks cut or wrapped, change the lines value or the col ... format widths. A status such as EXPIRED(GRACE) & LOCKED is longer than eight characters, so the first query hides part of it. Use a wider column when you need the full value.
If LAST_LOGIN is empty for an account you know is used, check how the user connects. The column is not filled for logins with an administrative privilege. If you see fewer users than you expect in a multitenant database, check the container you are connected to. Connect to the CDB root as a common user for the complete list.
If a user is locked and you want to open it, the status tells you the cause. A user locked after failed logins needs the cause fixed first. Check the profile limits FAILED_LOGIN_ATTEMPTS and PASSWORD_LOCK_TIME before you unlock.
References
- DBA_USERS (Oracle Database 19c Reference) - Column list, the full set of
ACCOUNT_STATUSvalues,ORACLE_MAINTAINED,LAST_LOGINand the CDB root note. - ALL_USERS (Oracle Database 19c Reference) - The view of users that are visible to the current user, with the
COMMONandORACLE_MAINTAINEDcolumns. - ALTER USER (Oracle Database 19c SQL Language Reference) - Syntax and behavior of
PASSWORD EXPIREand other user changes. - SET system variable summary (SQL*Plus 19c User's Guide) - Definitions of
PAGESIZEandLINESIZE. - COLUMN (SQL*Plus 19c User's Guide) - The
FORMAToption and character column widths such asA20. - Change Your Own Password in an Oracle Database (ORACLE-BASE) - Community walkthrough of
ALTER USERfor password changes and the privileges needed.