Why do I need a common account in Oracle? - 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;

Related

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

ORA-65096: invalid common user or role name

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;

How do I connect to the default Oracle10g instance on my PC?

I have a strong SQL Server background but fairly new to Oracle. I have a Windows 10 Home Edition. I installed Oracle 10g along with Oracle SQL Developer. What credentials/settings do I need to do to specify in SQL Developer to connect to the default Oracle database (if one exists)?
Well, that depends on what exactly you installed. Which Oracle 10g version? XE? Standard? Enterprise? As far as I can tell, Oracle was never certified on any Windows Home edition. It's not that it won't work at all, it just depends.
By the way, why 10g? It is outdated; the most recent version is 18c (available for download on Oracle Technology Network, https://www.oracle.com/downloads/).
As you are new to Oracle, I'd suggest you to use XE (Express Edition). Even 10g would do, I presume (if that's what you installed). For amusement, I have 11gXE on my Windows 7, works well. Why? Because it is a small footprint database, fully functional, free to use. It has its restrictions (such as 1 CPU, 1 GB RAM, 8 GB of user data) (those restrictions depend on XE version), but it is OK for most purposes.
Moreover, it automatically installs the database you can start using. During the installation process, you're asked for password for SYS (and SYSTEM) users (they "own" the database). Once you know these, you're the boss.
In XE, you have pre-installed schemas (i.e. users with their objects: tables, views, ...) which are named Scott, HR (Human Resources). By default, they are locked so you'd have to connect to the database as SYS and unlock them.
As you already have SQL Developer, you'd create a connection:
username = SYS
password = you know it
connection type = Basic
role = default
hostname = localhost
port = 1521 (it is the default; if you use some other port, you'll know it)
SID = xe (by default)
Once you're connected, check which users you have
select username, account_status from dba_users;
As I've said, Scott and/or HR might be interesting for you as they already have some objects. See their status; if they are locked, you'd unlock them and set new passwords as
alter user scott account unlock;
alter user scott identified by tiger;
Now you can create a new connection to Scott, following the same instructions as above.
If you want to create your own user, no problem. Still connected as SYS, check available tablespaces (this is SQL*Plus output, command-line tool; in SQL Developer, you won't have the "SQL>" prompt):
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
SQL> create user sam identified by nasr
2 default tablespace users
3 temporary tablespace temp
4 quota unlimited on users;
User created.
Once the user is created, it can't do anything - you have to grant it certain privileges, such as :
SQL> grant create session, create table, create view to sam;
Grant succeeded.
Create session allows it to establish connection; another two will let you create tables and views. If you - as the time goes by - need yet another privilege, connect as SYS and grant it the same way.
Now you can connect to it (that would be yet another connection in SQL Developer) and ... do something:
SQL> connect sam/nasr
Connected.
SQL> create table test (id number);
Table created.
SQL> insert into test (id) values (100);
1 row created.
SQL>
So: if you have anything but XE, I'd suggest you to uninstall it. Use Universal Installer to do that. Then download and install XE. In my opinion, as Oracle beginner, that should make your life easier.
On the other hand, if you want to practice to be a DBA, then XE probably isn't the right choice as there can be only one - preinstalled - database.

How to create a database user for oracle 11g on windows 8?

I am new to oracle database and therefore is trying to follow the office guide. (link to the guide) However, it seems that the guide is for Windows 7, so in step 2 - creating database user, it says:
Display the SQL command prompt window. For example, on Windows, click Start, then Programs (or All Programs), then Oracle Database 11g
Express Edition, and then Run SQL Command Line.
And in windows 8, there is not start button. I try to search the menu using keyword oracle but nothing with similar name is found. I tried to go to the Program Files directly but also no similar file found. So, how should I create a database user on Windows 8?
I don't use Windows 8, but I guess that it must have some kind of a "command prompt" (you know, a program that lets you perform text-based (command-line) functions; its window is black with white letters. Once opened, the cursor blinks at the prompt, waiting for your commands). Try to find it, run it.
Then you'll be able to connect to your database (you do have it installed, right?) as
C:\> sqlplus sys/your_sys_password#database as sysdba
You'll be connected as SYS (be careful! It is a powerful user and its misuse might break your database! I'd suggest you to create another user, for example "mydba", grant it DBA role and let it perform DBA actions).
If you're unsure of what your tablespaces are, run
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USER_DATA
APEX
APEX_9695076087226093
7 rows selected.
SQL>
as you'll need at least two of them. Now create your new user:
SQL> create user mike identified by lion
2 default tablespace user_data
3 temporary tablespace temp
4 profile default
5 quota unlimited on user_data;
User created.
SQL> grant create session to mike;
Grant succeeded.
SQL>
Granting create session, it'll be able to connect to the database, but won't be able to do anything else, so you'd have to grant it some more privileges (such as create table, create view, create procedure etc.).
SQL> connect mike/lion#orcl
Connected.
SQL> create table test (id number);
create table test (id number)
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL>

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

Resources