Oracle Database12c ORA 01918 and connection error

两盒软妹~` 提交于 2020-01-12 08:39:05

问题


I have installed the Oracle 12c and I have problems creating my first database and using it. I run SQL Developer and use "hr" user but it keeps telling me that the account is locked. I searched into stackoverflow answers and official doc and tried to unlock it with:

ALTER USER HR IDENTIFIED BY password ACCOUNT UNLOCK;

but with no success. I got error ORA01918, meaning that user does not exist.

I tried then to use the user created at the installation (SYS as SYSDBA)but then it says that the user/password is incorrect. I am pretty sure that I have installed Oracle 12c correctly on my system, which is Windows 8.1 x64.

What should I do? Please help me.

Other thing I do not understand is wether or not the term "database" is equivalent to MySQL's "Schema"? The "connection" is to connect to a specific database, yes? Thank you.


回答1:


How did you configure your database? Did you check the option for Pluggable database? If yes, please make sure you login to PDB and not CDB.

Please read Oracle 12c Post Installation Mandatory Steps.

By default, pre-installed users like SCOTT, HR etc. resides in container database and not in pluggable database.

tnsnames.ora

Edit your tnsnames.ora file to add the PDB details. For example,

PDBORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pdborcl)
    )
  )

Open all PDBs

To open all/specific PDBs immediately after logon, create a AFTER STARTUP system level trigger in CDB.

Since, the PDBs are not open through a CDB start. Let’s see :

SHUTDOWN IMMEDIATE;
STARTUP;

SQL> SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDB$SEED                       READ ONLY
PDBP6                          MOUNTED

So, in order to have all the PDBs automatically open, do this :

Do, “SQLPLUS / AS SYSDBA”, and then execute :

CREATE OR REPLACE TRIGGER open_pdbs 
  AFTER STARTUP ON DATABASE 
BEGIN 
   EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN'; 
END open_pdbs;
/

It creates a after startup system level trigger in CDB.

SQLPLUS / AS SYSDBA

The most common misunderstanding is about “SQLPLUS / AS SYSDBA” usage.

Since we have checked the option to create a single CDB, the “SQLPLUS / AS SYSDBA” command will always log into CDB. Usually developers used to unlock the “SCOTT” account directly after logging as SYSDBA. But here is the trick :

“SCOTT” and other sample schemas are in the PDB and not in the CDB. So, you need to login as sysdba into PDB.

sqlplus SYS/password@PDBORCL AS SYSDBA

SQL> ALTER USER scott ACCOUNT UNLOCK IDENTIFIED BY tiger;

sqlplus scott/tiger@pdborcl

SQL> show user;
USER is "SCOTT"


来源:https://stackoverflow.com/questions/26591467/oracle-database12c-ora-01918-and-connection-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!