1.在19c,pdb中创建用户
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ WRITE NO
SQL> alter session set container=pdb;
SQL> create user pdb_19c identified by oracle default tablespace users;
SQL> grant resource,connect to pdb_19c;
3.11g中创建19cpdb,pdb_19c用户的link-link_pdb
SQL> create database link link_pdb connect to pdb_19c identified by oracle using '19c';
4.在19c---pdb_19c用户中创建表
[oracle@pg1 admin]$ sqlplus pdb_19c/oracle@192.168.56.100:1521/pdb
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> create table a (id int);
SQL> insert into a (id) values (3);
insert into a (id) values (3)
*
ERROR at line 1:
ORA-01950: no privileges on tablespace 'USERS'
解决:
oracle@pg1 admin]$ sqlplus sys/oracle@192.168.56.100:1521/pdb as sysdba
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
3 PDB READ WRITE NO
SQL> alter user pdb_19c quota unlimited on users;
[oracle@pg1 admin]$ sqlppdb_19c/oracle@192.168.56.100:1521/pdb
SQL> insert into a (id) values (3);
SQL> commit;
Commit complete.
2.2 模拟环境-2
1. 11g中创建用户
SQL> grant connect,resource to test identified by oracle;
2.创建pdb相应的tns
pdb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = pdb)
)
)
2. 赋予test用户创建dblink的权限
SQL> grant create public database link to test;
4. 11g中链接test用户,并创建dblink---link_pdb
[oracle@pg1 admin]$ sqlplus test/oracle@11g
SQL> create public database link link_pdb connect to pdb_19c identified by oracle using 'pdb';
5.验证dblink是否创建成功
SQL> select * from a@link_pdb;
ID
----------
3
3. dblink查看
--以下操作都在sys用户中进行
---查看全部用户
SELECT OWNER,OBJECT_NAME FROM DBA_OBJECTS WHERE OBJECT_TYPE= 'DATABASE LINK' ;
---查看全部用户
19c:
SQL> col owner for a20
SQL> col db_link for a20
SQL> col username for a10
SQL> col host for a15
SQL> set linesize 400
SQL> select * from dba_db_links;
OWNER DB_LINK USERNAME HOST CREATED HID SHA VAL INT
-------------------- -------------------- ---------- --------------- --------- --- --- --- ---
SYS SYS_HUB SEEDDATA 17-APR-19 NO NO YES NO
11g:哪个用户创建的dblink哪个用户登录,sys登录可查看全部的dblink
SQL> col owner for a20
col db_link for a20
col username for a10
col host for a15
set linesize 400
select * from dba_db_links;
OWNER DB_LINK USERNAME HOST CREATED
-------------------- -------------------- ---------- --------------- ---------
SYS LINK_PDB PDB_19C 19c 04-AUG-23
PUBLIC LINK_PDB PDB_19C pdb 04-AUG-23
4.删除dblink
11g:
SQL> drop database link LINK_PDB;
SQL> col owner for a20
col db_link for a20
col username for a10
col host for a15
set linesize 400
select * from USER_DB_LINKS;
no rows selected