Home / Databases / Oracle

DatabasesTroubleshootingAdvanced

Oracle ORA-01017 invalid username/password: find the real cause when the password is right

ORA-01017 when the password is correct usually means a wrong container or database, old password verifiers, a stale password file or OS authentication. Find which one and fix it.

Deepak Bhardwaj7 min read

Applies toOracle Database 19c, 21c, 23ai (single instance, RAC, Data Guard), Oracle Base Database Service, Amazon RDS for Oracle

Symptom

A user, application or job fails to log in:

ORA-01017: invalid username/password; logon denied

On 23ai the text reads ORA-01017: invalid credential or not authorized; logon denied. The error number is the same. Oracle deliberately returns one error for "no such user", "wrong password" and several configuration problems, so the message alone does not tell you which one you have.

If the password really is wrong, reset it and you are done. This runbook is for the case where everyone insists the password is right.

Quick map

Clue Likely cause Go to
Works in one PDB, fails in another, or fails via the CDB service User is local to a different container Wrong container
Works from SQL*Plus on the server, fails from the app server App connects to a different database, or a wallet holds an old password Wrong target
Account created on 11g or earlier and never reset Only a 10G password verifier exists Password verifiers
/ as sysdba fails OS user not in the OSDBA group OS authentication
sys@service as sysdba fails remotely, works locally Password file missing or out of date Password file
Fails only on the standby after a switchover Standby password file differs Password file

Step 1: confirm what the server saw

Unified auditing records failed logons through the default ORA_LOGON_FAILURES policy in current releases. Check that it is enabled, then look at the failures:

SELECT policy_name, enabled_option, success, failure
FROM   audit_unified_enabled_policies
WHERE  policy_name = 'ORA_LOGON_FAILURES';

SELECT event_timestamp, dbusername, os_username, userhost,
       client_program_name, authentication_type, return_code
FROM   unified_audit_trail
WHERE  action_name = 'LOGON'
AND    return_code = 1017
AND    event_timestamp > SYSTIMESTAMP - INTERVAL '1' HOUR
ORDER  BY event_timestamp DESC;

What to read:

  • No rows at all while the client keeps failing: the client is not reaching this database. Go to Step 2.
  • dbusername in an unexpected case such as app instead of APP: the user was created with a quoted name, or the client quotes it.
  • userhost and client_program_name tell you which server and program are failing. Often it is one forgotten job, not the whole application.

In a CDB, run the query in the PDB the user connects to. Each container keeps its own audit records.

Step 2: wrong target or wrong container

Confirm where the connect string actually lands. Connect with the same alias or EZConnect string the application uses, as a user that works, and run:

SELECT sys_context('USERENV','DB_NAME')      AS db,
       sys_context('USERENV','CON_NAME')     AS container,
       sys_context('USERENV','SERVICE_NAME') AS service,
       sys_context('USERENV','SERVER_HOST')  AS host
FROM dual;

Then check where the failing user exists:

-- From CDB$ROOT
SELECT con_id, username, common, account_status, password_versions
FROM   cdb_users
WHERE  username = 'APP_USER';

A local user exists only in its PDB. Connecting through the CDB's default service, or through a service that belongs to another PDB, returns ORA-01017. Fix the connect string to use the PDB's service:

lsnrctl services | grep -i "service"
sqlplus app_user@//dbhost:1521/orders_pdb.example.com

Tip

Test with sqlplus user@alias and type the password at the prompt. Passwords containing @, / or " break when passed on the command line, and the shell may also mangle $ and !. If the prompt works and the scripted login fails, the script's quoting is the problem.

Secure external password store (wallets)

Jobs that log in with sqlplus /@alias read the password from a wallet. After a password change, the wallet still holds the old one:

mkstore -wrl /u01/app/oracle/wallet -listCredential
mkstore -wrl /u01/app/oracle/wallet -modifyCredential orders_batch batch_user

mkstore prompts for the new password and the wallet password. Check that sqlnet.ora on that client points WALLET_LOCATION at this wallet and that the alias matches tnsnames.ora.

Step 3: old password verifiers

Since 12.2, the default SQLNET.ALLOWED_LOGON_VERSION_SERVER in the server's sqlnet.ora is 12, which does not accept the old 10G verifier. An account whose password was last set on 11g or earlier and carried forward through upgrades may have only that verifier.

SELECT username, password_versions, account_status
FROM   dba_users
WHERE  password_versions NOT LIKE '%11G%'
AND    password_versions NOT LIKE '%12C%'
AND    authentication_type = 'PASSWORD';

Accounts listed with only 10G cannot log in. The fix is to set the password again, which creates current verifiers:

ALTER USER legacy_app IDENTIFIED BY "New-Strong-Password-1";

If you must keep the existing password, an approved short-term workaround is to set SQLNET.ALLOWED_LOGON_VERSION_SERVER=11 on the server, have the user log in and change the password, then return the setting to 12. Do not leave it lowered.

A different error, ORA-28040: No matching authentication protocol, means the client driver is too old for the server's setting. Upgrade the driver rather than lowering the server.

Step 4: OS authentication fails for / as sysdba

Local / as sysdba uses OS group membership, not a password. ORA-01017 here means the OS user is not in the OSDBA group the Oracle home was linked with.

id                                   # groups of the current OS user
grep -E "SS_DBA_GRP|SS_OPER_GRP" $ORACLE_HOME/rdbms/lib/config.c
echo $ORACLE_HOME $ORACLE_SID        # wrong home or SID gives the same error

Add the user to the right group (usermod -aG dba oracle, then log in again), or fix ORACLE_HOME and ORACLE_SID. On Windows, check that sqlnet.ora has SQLNET.AUTHENTICATION_SERVICES = (NTS) and the user is in ORA_DBA or the home-specific group.

Step 5: password file for remote SYSDBA

Remote logins as SYS, or as users with SYSDBA, SYSBACKUP or SYSDG, are checked against the password file, not the data dictionary.

SHOW PARAMETER remote_login_passwordfile    -- expect EXCLUSIVE
SELECT username, sysdba, sysoper, sysbackup, sysdg, account_status
FROM   v$pwfile_users;

If v$pwfile_users is empty or missing the user, the file is missing, unreadable or the wrong one. Find it:

ls -l $ORACLE_HOME/dbs/orapw$ORACLE_SID                 # single instance, Linux default
srvctl config database -db ORCL | grep -i "password file" # RAC or Oracle Restart

With remote_login_passwordfile=EXCLUSIVE, ALTER USER sys IDENTIFIED BY ... updates the file. If the file is missing, recreate it; orapwd prompts for the password when you leave it off the command line:

orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID format=12.2

On RAC with the file in ASM, use orapwd file='+DATA/ORCL/PASSWORD/pwdorcl' dbuniquename=ORCL format=12.2, or asmcmd pwcopy to copy an existing one. Then re-grant administrative privileges that were lost, for example GRANT SYSBACKUP TO rman_user;.

Warning

Recreating the password file with force=y overwrites the existing one and drops every SYSBACKUP, SYSDG and SYSKM grant stored in it. Back up the old file first and list v$pwfile_users before you replace it.

Data Guard

Redo transport uses the password file to authenticate between primary and standby. A mismatch shows up as ORA-01017 or ORA-16191 in the alert log and transport stops. From 12.2, password changes on the primary reach physical standbys through redo apply in most configurations, but a standby that was not applying redo at the time, a far sync instance, or a file replaced by hand will be out of step. Copy the primary's file to each standby with the standby's file name, then check transport:

SELECT dest_id, status, error FROM v$archive_dest_status WHERE status <> 'INACTIVE';

Prevent it next time

  • Keep failed-logon auditing on and alert when one dbusername and userhost pair fails more than a few times in five minutes. That catches a stale wallet before FAILED_LOGIN_ATTEMPTS locks the account (see the ORA-28000 post).
  • Before an upgrade, list accounts whose password_versions contain only 10G and reset them.
  • After changing SYS or any administrative password, check v$pwfile_users on every RAC node and Data Guard member.
  • Keep each application's connect string pointing at its PDB service, never the CDB service.
  • Rotate passwords through one documented process that updates the database, the wallets and the secret store together.