ORA-65096: invalid common user or role name - oracle

Hi I've tried to create a new user in Oracle 18c XE, but I get
ORA-65096: invalid common user or role name error when writing
create user student identified by "student";
I've tried to change the container to PDB by
SQL> alter session set container =PDB;
as I've understood that you should set that when trying to create a local user but I get the following error:
ORA-65011: Pluggable database PDB does not exist.
Do you have any idea how could I create a new user with all privileges from the command prompt?

A user cannot be created on a container for a DB with vers. 12c+.
So, need to alter as you did, but should display which pluggable databases are available :
SQL> select name, pdb from v$services order by pdb, name;
NAME PDB
----------------------------------------------- ----------
SYS$BACKGROUND CDB$ROOT
SYS$USERS CDB$ROOT
pdb1 PDB1
pdb2 PDB2
and check out the container by
SQL>show con_name
CON_NAME
——————————
CDB$ROOT
and check for the pluggable databases
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------- ----------
PDB$SEED READ ONLY
PDB1 MOUNTED
PDB2 MOUNTED
change container to a pluggable database
SQL> alter session set container=pdb1;
Session altered.
and open it
SQL> alter pluggable database pdb1 open;
Now, you can apply
SQL> create user student identified by student;
as an example.

First run the following command:
SQL> alter session set "_ORACLE_SCRIPT"=true;
After that, create the user:
SQL> create user student identified by student;

Related

What Roles or Privileges are needed for ALTER DATABASE ADD SUPPLEMENTAL LOG DATA?

I'm attempting to run the following command as I am trying to get logminer to log my database. When I run the following command, I get a response of Insufficient Privileges
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
I have to run it as a specific user, so I need to know what Granted Roles and/or System Privileges are required to run this statement.
I'm not a DBA (and stuff like that are supposed to be run by DBA), but: privileged user should grant you (as you said that you'll be running it yourself) the ALTER DATABASE privilege:
scott is just a poor user:
SQL> show user
USER is "SCOTT"
SQL>
SQL> alter database add supplemental log data;
alter database add supplemental log data
*
ERROR at line 1:
ORA-01031: insufficient privileges
A privileged user is SYS (if you don't have any other):
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> grant alter database to scott;
Grant succeeded.
Back to scott, re-run the statement:
SQL> connect scott/tiger
Connected.
SQL> alter database add supplemental log data;
Database altered.
SQL>
That's the minimum. You could have also granted the DBA role to scott, with the same effect (regarding this very statement, but - DBA is much more powerful):
To illustrate it, revoke the privilege first:
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> revoke alter database from scott;
Revoke succeeded.
Does it still work? Of course not:
SQL> connect scott/tiger
Connected.
SQL> alter database add supplemental log data;
alter database add supplemental log data
*
ERROR at line 1:
ORA-01031: insufficient privileges
Grant DBA role:
SQL> connect sys as sysdba
Enter password:
Connected.
SQL> grant dba to scott;
Grant succeeded.
Does it work now? Yes, it does:
SQL> connect scott/tiger
Connected.
SQL> alter database add supplemental log data;
Database altered.
SQL>

How to clone a pluggable database in Oracle

I'm new to Oracle's pluggable databases (we still use Oracle 11.2 at work). For a test of partitions and subpartitions, I'll need to create a couple of dozen tablespaces. I thought, I'd quickly clone my current database, do the tests, and drop the database afterwards.
I was able to clone the database:
CREATE PLUGGABLE DATABASE ora193p2 FROM ora193p1
FILE_NAME_CONVERT = (
'/opt/oracle/oradata/ORA193C/ORA193P1/',
'/opt/oracle/oradata/ORA193C/ORA193P2/');
Pluggable database ORA193P2 created.
but got an error ORA-01109: database not open when trying to connect to it.
I've tried to open it, but get an error message, too (ora193c is the name of the cdb):
ALTER DATABASE ora193p2 OPEN;
ORA-01509: specified name 'ORA193P2' does not match actual 'ORA193C'
I used the database from vagrant-boxes.
For pluggable databases you need to add key word pluggable database followed by pdb name
SQL> create pluggable database pdbclone from orclpdb;
Pluggable database created.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE MOUNTED
SQL> alter pluggable database pdbclone open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
4 PDBCLONE READ WRITE NO
SQL> alter pluggable database pdbclone save state;
Pluggable database altered.
From 12.1.0.2 onward, you can preserve the PDB startup state through CDB restart. The 12.1.0.2 patchset introduced SAVE STATE and DISCARD STATE options:
ALTER PLUGGABLE DATABASE pdb_name OPEN;
ALTER PLUGGABLE DATABASE pdb_name SAVE STATE;
To discard the saved state:
ALTER PLUGGABLE DATABASE pdb_name DISCARD STATE;
For 12.1.0.1 and before, you could create an after startup trigger:
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.
See Oracle 12c Post Installation Mandatory Steps

connecting to pluggable database using administrator user

I have a question about connecting to pluggable database using a user(scott/tiger).Lets say,I am connected as
sqlplus / as sysdba
Then I want to open my pluggable database:
alter pluggable database ORC open;
And then,I want to connect as user scott to my pluggable db (ORC) using this:
connect scott/tiger#ORC;
However,I got this error:
ORA-01031(INSUFFICIENT PRIVILEGES).
My question is should I have made scott as my administrator user while creating this pluggable db in order for scott to connect to this pdb?
Some help is appreciated.
Most probably user scott does not have CONNECT or CREATE SESSION privileges.
Regardless, you can effectively connect to a PDB from sqlplus by issuing
alter session set container = PDB_NAME;
Example:
$ sqlplus / as sysdba
SQL> select name, open_mode from v$containers;
NAME OPEN_MODE
------------------------------ ----------
CDB$ROOT READ WRITE
PDB$SEED READ ONLY
...........
TEST12C MOUNTED
TESTCAT READ WRITE
7 rows selected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> alter session set container = TESTCAT;
Session altered.
SQL> show con_name
CON_NAME
------------------------------
TESTCAT
Also check the official documentation:
Administering a CDB with SQL*Plus
Viewing Information About CDBs and PDBs with SQL*Plus

Oracle can only login as sysdba / can't login with configured user?

So I created the user w3038519 in the Oracle database configuration as I was installing Oracle yet it does not let me login with it.
C:\Users\Chris>sqlplus w13038519/mypass
SQL*Plus: Release 12.1.0.1.0 Production on Fri Aug 14 00:26:16 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
Could the account be locked somehow? Is there any way I can unlock it or create another user? The following doesn't work
sqlplus w13038519/mypass as sysdba
sqlplus osauthentication/anyuserpass as sysdba
SQL> create user chris
2 identified by chrispass
3 ;
create user chris
*
ERROR at line 1:
ORA-65096: invalid common user or role name
SQL> create user C##chris
2 identified by chrispass
3 ;
create user C##chris
*
ERROR at line 1:
ORA-65048: error encountered when processing the current DDL statement in
pluggable database PDBORCL
ORA-01031: insufficient privileges
I can't do anything I need to with sysdba because you can't create triggers logged in sysdba
I watched some tutorial and the person just setup sysdba as I have done and now can't use triggers.
I hate oracle so much. It's so retarded to use the most unideal platform there is
You have created a container database instead of a traditional one. In this case, When you use / as sysdba, you connect to the root container, where you can not create reguler users, only common users (starting with c##), so your user w13038519 can not exist in the root container. Run the below query:
select con_id from cdb_users where username = 'W13038519';
CON_ID
----------
3
This should return the container database where your user was created. If you get no result, your user does not exist. To find the name of the container:
SQL> select name from v$pdbs where con_id = 3;
NAME
------------------------------
PDB1
If you have a TNS entry pointing to that container database, you can connect as:
sqlplus w13038519/september23#PDB1
If you do not need the Multitenant Architechture specifically, you will save yourself a lot of trouble by creating a traditional database.
create user C##TESTDB identified by TESTDB container = all;
ORA-65048: error encountered when processing the current DDL statement in
pluggable database PDBORCL
ORA-01031: insufficient privileges
in my case this worked
alter session set "_oracle_script"=true;
create user C##TESTDB identified by TESTDB;
user created;

Why do I need a common account in Oracle?

Why do I need a common account in Oracle 12c? A common means a CDB account. When I create an account using enterprise manager express it's creating only common accounts. Could I create a non-common account there? A common user also appears in every container I ever switch/connect to. What's the purpose of this common account to access all those pluggable databases?
Why do I need a common account in Oracle 12c?
What's the purpose of this common account to access all those pluggable databases?
You need a common account(common user) to perform administrative operations on CDB(container database) such as changing the state of a pluggable database, plugging and unplugging pluggable databases (PDBs) and so forth, which local user cannot do. Well, in fact, a local user can change state of pluggable database as well, but only PDB it connected to as sysdba or sysoper.
Could I create a non-common account there(in CDB)?
No, non-common account(Local user) cannot be created in the root - can only be created and operate within a pluggable database(PDB) and wont have access(you cannot use it to log in to) CDB or other PDBs.
Find out more
about commonality and common and local users.
Edit
CDB$ROOT is root container. PDB$SEED is just a template needed to create a pluggable databases. You cannot create or modify objects in it. PDBORCL is a pluggable database, which you should use for your development.
Oracle will throw the ORA-01033 error if you are trying to connect to a closed PDB as non sysdba user. Usually, PDBs database are not open by default, just mounted (unless your have automated that process by creating a trigger, for example, that will do it for you upon starting up CDB) and you need to explicitly open it while connecting as a common user (SYS or other common user that has the privilege to startup/alter pluggable database) and issue:
SQL> alter pluggable database <<name_of_PDB>> open;
or
SQL> startup pluggable database <<name_of_PDB>>
After that you should be able to connect to your PDB as common or local user. Of course they have to have appropriate privileges(create session) to be able to do so.
Edit #2 Automating starting up of pluggable database(s) on startup of CDB using system event(after startup on database) trigger. Unfortunately there is no native way to startup PDs automatically.
SQL> conn / as sysdba
Connected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 NKRASNOV READ WRITE NO
This specific trigger opens one pluggable database. If you have more than one PDs and want to open them all, the alter statement can be modified as follows ALTER PLUGGABLE DATABASE ALL OPEN;
SQL> create or replace trigger open_pdb
2 after startup on database
3 begin
4 execute immediate 'alter pluggable database nkrasnov open';
5 end;
6 /
Trigger created.
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Database mounted.
Database opened.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 NKRASNOV READ WRITE NO
SQL> conn hr/hr#nkrasnov_pdb
Connected.
SQL> spool off;

Resources