English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
先说基本用法:
先按11G之前进行
conn / as sysdba;
create user test identified by test;
ORA-65096: 公用用户名或角色名无效.
查官方文档得知“试图创建一个通用用户,必需要用C##或者c##开头”,这时候心里会有疑问,什么是common user?不管先建成功了再说
create C##user test identified by test;
创建成功
SQL> show con_name;
CON_NAME
------------------------------
CDB$ROOT
select con_id, dbid, NAME, OPEN_MODE from v$pdbs;
CON_ID DBID NAME OPEN_MODE
---------- ---------- ------------------------------ ----------
2 4066409480 PDB$SEED READ ONLY
3 2270995695 PDBORCL MOUNTED
SQL> alter session set container=PDBORCL;
In questo momento, è sufficiente creare un utente utilizzando la seguente istruzione: create user test identified by test;
CDB e PDB sono una delle nuove caratteristiche più brillanti di ORACLE 12C, e la loro introduzione ha portato a molte modifiche alle idee tradizionali di gestione del database ORACLE. Ecco alcune delle modalità di gestione di base di CDB e PDB.
cdb和pdb关系图
ORACLE 12C版本
SQL> select * from v$version; BANNER CON_ID -------------------------------------------------------------------------------- ---------- Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0 PL/SQL Release 12.1.0.1.0 - Production 0 CORE 12.1.0.1.0 Production 0 TNS for Linux: Version 12.1.0.1.0 - Production 0 NLSRTL Version 12.1.0.1.0 - Production 0
启动关闭pdb
SQL> startup ORACLE instance started. Total System Global Area 597098496 bytes Fixed Size 2291072 bytes Variable Size 272632448 bytes Database Buffers 314572800 bytes Redo Buffers 7602176 bytes Database mounted. Database aperto. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE ---------- ---------- ------------------------------ ---------- 2 4048821679 PDB$SEED READ ONLY 3 3313918585 PDB1 MOUNTED 4 3872456618 PDB2 MOUNTED SQL> alter PLUGGABLE database pdb1 open; Database pluggabile alterato. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE ---------- ---------- ------------------------------ ---------- 2 4048821679 PDB$SEED READ ONLY 3 3313918585 PDB1 READ WRITE 4 3872456618 PDB2 MOUNTED SQL> alter PLUGGABLE database pdb1 close; Database pluggabile alterato. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE ---------- ---------- ------------------------------ ---------- 2 4048821679 PDB$SEED READ ONLY 3 3313918585 PDB1 MOUNTED 4 3872456618 PDB2 MOUNTED SQL> alter PLUGGABLE database all open; Database pluggabile alterato. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE ---------- ---------- ------------------------------ ---------- 2 4048821679 PDB$SEED READ ONLY 3 3313918585 PDB1 READ WRITE 4 3872456618 PDB2 READ WRITE SQL> alter PLUGGABLE database all close; Database pluggabile alterato. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE ---------- ---------- ------------------------------ ---------- 2 4048821679 PDB$SEED READ ONLY 3 3313918585 PDB1 MOUNTED 4 3872456618 PDB2 MOUNTED SQL> alter session set container=pdb1; Sessione alterata. SQL> startup Database pluggabile aperto. SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE ---------- ---------- ------------------------------ ---------- 3 3313918585 PDB1 READ WRITE
La gestione del pdb può essere eseguita sia nel cdb che nel pdb. Se viene eseguita nel cdb, è necessario il termine PLUGGABLE, se viene eseguita nel pdb è come con un database normale
Login pdb
[oracle@xifenfei ~]$ lsnrctl status LSNRCTL per Linux: Versione 12.1.0.1.0 - Produzione il 12-MAY-2013 08:07:02 Copyright (c) 1991, 2013, Oracle. Tutti i diritti riservati. Connettendo a (DESCRIZIONE=(INDIRIZZO=(PROTOCOLLO=TCP)(HOST=xifenfei)(PORTA=1521))) STATO del LISTENER ------------------------ Alias LISTENER Version TNSLSNR per Linux: Versione 12.1.0.1.0 - Produzione Start Date 11-MAY-2013 18:30:54 Uptime 0 giorni 13 ore 36 minuti 8 secondi Trace Level off Security ON: Local OS Authentication SNMP OFF File di parametri del listener /u01/app/grid/product/12.1/network/admin/listener.ora File di registro del listener /u01/app/grid/diag/tnslsnr/xifenfei/listener/alert/log.xml Riepilogo dei punti di ascolto... (DESCRIZIONE=(INDIRIZZO=(PROTOCOLLO=ipc)(CHIAVE=EXTPROC1521))) (DESCRIZIONE=(INDIRIZZO=(PROTOCOLLO=tcp)(HOST=xifenfei)(PORTO=1521))) (DESCRIZIONE=(INDIRIZZO=(PROTOCOLLO=tcps)(HOST=xifenfei)(PORTO=5500))) (Sicurezza=(my_wallet_directory=/u01/oracle/12.1/db_1/admin/cdb/xdb_wallet))(Presentazione=HTTP)(Sessione=RAW)) Riepilogo dei servizi... Il servizio "+ASM" ha 1 istanza(s). L'istanza "+ASM", stato PRONTO, ha 1 gestore(s) per questo servizio... Il servizio "cdb" ha 1 istanza(s). L'istanza "cdb", stato PRONTO, ha 1 gestore(s) per questo servizio... Il servizio "cdbXDB" ha 1 istanza(s). L'istanza "cdb", stato PRONTO, ha 1 gestore(s) per questo servizio... Il servizio "pdb1" ha 1 istanza(s). L'istanza "cdb", stato PRONTO, ha 1 gestore(s) per questo servizio... Il servizio "pdb2" ha 1 istanza(s). L'istanza "cdb", stato PRONTO, ha 1 gestore(s) per questo servizio... Il comando è stato completato con successo [oracle@xifenfei ~]$ tnsping pdb1 TNS Ping Utility per Linux: Versione 12.1.0.1.0 - Produzione il 12-MAGGIO-2013 08:07:09 Copyright (c) 1997, 2013, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = xifenfei) (PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdb1))) OK (20 msec) [oracle@xifenfei ~]$ sqlplus sys/xifenfei@pdb1 as sysdba SQL*Plus: Release 12.1.0.1.0 Production on Sun May 12 08:08:02 2013 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options SQL> show con_name; CON_NAME ------------------------------ PDB1 [oracle@xifenfei ~]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.1.0 Production on Sun May 12 08:09:14 2013 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options SQL> alter session set container=pdb1; Sessione alterata. SQL> show con_name; CON_NAME ------------------------------ PDB1
pdb可以通过alter session container进入也可以直接通过tns方式登录
创建用户
SQL> show con_name; CON_NAME ------------------------------ CDB$ROOT SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs; CON_ID DBID NAME OPEN_MODE ---------- ---------- ------------------------------ ---------- 2 4048821679 PDB$SEED READ ONLY 3 3313918585 PDB1 READ WRITE 4 3872456618 PDB2 MOUNTED SQL> create user xff identified by xifenfei; create user xff identified by xifenfei * ERROR at line 1: ORA-65096: nome di utente o ruolo comune non valido SQL> !oerr ora 65096 65096, 00000, "nome di utente o ruolo comune non valido" // *Cause: È stato tentato di creare un utente comune o un ruolo con un nome // che non erano validi per gli utenti comuni o i ruoli. In aggiunta a // le regole usuali per i nomi degli utenti e dei ruoli, degli utenti comuni e dei ruoli // i nomi devono iniziare con C## o c## e consistere solo di ASCII // caratteri. // *Azione: Specificare un nome di utente o ruolo comune valido. // SQL> create user c##xff identified by xifenfei; Utente creato. SQL> SELECT USERNAME, CON_ID, USER_ID FROM CDB_USERS WHERE USERNAME='C##XFF'; USERNAME CON_ID USER_ID ---------- ---------- ---------- C##XFF 1 103 C##XFF 3 104 SQL> alter session set container=pdb1; Sessione alterata. SQL> show con_name CON_NAME ------------------------------ PDB1 SQL> create user xff identified by xifenfei; Utente creato. SQL> create user c##abc identified by xifenfei; create user c##abc identified by xifenfei * ERROR at line 1: ORA-65094: nome utente locale o ruolo non valido
La creazione dell'utente di default è container=all, nel cdb è possibile creare solo utenti globali (iniziati con c##), verrà creato l'utente nel cdb e in tutti i pdb (ma l'utente globale nel pdb necessita di un'autorizzazione aggiuntiva per accedere al pdb). Gli utenti che possono essere creati nel pdb sono utenti locali
Autorizzazione dell'utente
SQL> grant connect to c##xff; Concessione riuscita. SQL> select GRANTEE,con_id from cdb_ROLE_PRIVS where GRANTED_ROLE='CONNECT' AND GRANTEE='C##XFF'; GRANTEE CON_ID ------------------------------ ---------- C##XFF 1 SQL> grant resource to c##xff container=all; Concessione riuscita. SQL> select GRANTEE,con_id from cdb_ROLE_PRIVS where GRANTED_ROLE='RESOURCE' AND GRANTEE='C##XFF'; GRANTEE CON_ID ------------------------------ ---------- C##XFF 1 C##XFF 3
L'autorizzazione dell'utente di default è solo per il container corrente, nel cdb è anche possibile specificare container=all, per autorizzare tutti i pdb aperti e per l'utente esistente
Modifica del parametro
SQL> alter system set open_cursors=500 container=all; System altered. SQL> conn sys/xifenfei@pdb1 as sysdba Connected. SQL> show parameter open_cursors; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ open_cursors intero 500 SQL> alter system set open_cursors=100; alter system set open_cursors=100 * ERROR at line 1: ORA-01219: database or pluggable database not open: queries allowed on fixed tables or views only SQL> alter database open; Database altered. SQL> alter system set open_cursors=100; System altered. SQL> show parameter open_cursors; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ open_cursors intero 100 SQL> conn / as sysdba Connected. SQL> show parameter open_cursors; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ open_cursors intero 500
Ecco come vedere le modifiche apportate in cdb, pdb le eredita; se vengono apportate modifiche in pdb, copreranno il significato dei parametri ereditati da cdb
Dichiarazione: il contenuto di questo articolo è stato tratto da Internet, il diritto d'autore è dell'autore originale, il contenuto è stato contribuito spontaneamente dagli utenti di Internet e caricato autonomamente, il sito web non detiene i diritti di proprietà, non è stato elaborato manualmente e non assume responsabilità legali correlate. Se trovi contenuti sospetti di violazione del copyright, ti preghiamo di inviare una e-mail a: notice#oldtoolbag.com (al momento dell'invio dell'e-mail, sostituisci # con @) per segnalare, fornendo prove pertinenti. Una volta verificata, il sito web rimuoverà immediatamente il contenuto sospetto di violazione del copyright.