dblink简单使用

1.配置tns

[oracle@pg1 admin]$ cat tnsnames.ora 
19c = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521))
    )
    (CONNECT_DATA = 
      (SERVICE_NAME = orcl)
    )
  )

11g = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521))
    )
    (CONNECT_DATA = 
      (SERVICE_NAME = prod)
    )
  )

ps:确定tns链接正常,好使

2.创建dblink

2.1模拟环境-1

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
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
相关推荐
Mephisto.java8 分钟前
【大数据学习 | kafka高级部分】kafka的kraft集群
大数据·sql·oracle·kafka·json·hbase
Mephisto.java10 分钟前
【大数据学习 | kafka高级部分】kafka的文件存储原理
大数据·sql·oracle·kafka·json
毕业设计制作和分享9 小时前
ssm《数据库系统原理》课程平台的设计与实现+vue
前端·数据库·vue.js·oracle·mybatis
Dingww101113 小时前
梧桐数据库中的网络地址类型使用介绍分享
数据库·oracle·php
2401_8570262315 小时前
Spring Boot框架下的知识管理与多维分类
spring boot·后端·oracle
刘艳兵的学习博客1 天前
刘艳兵-DBA027-在Oracle数据库,通常可以使用如下方法来得到目标SQL的执行计划,那么通过下列哪些方法得到的执行计划有可能是不准确的?
数据库·oracle·面试·database·刘艳兵
秋意钟1 天前
MySql事务
数据库·mysql·oracle
Mephisto.java1 天前
【大数据学习 | HBASE】hbase的整体架构
大数据·sql·oracle·json·hbase·database
蚊子不吸吸1 天前
DevOps开发运维简述
linux·运维·ci/cd·oracle·kubernetes·gitlab·devops
Ayka1 天前
Linux Qt 6安装Oracle QOCI SQL Driver插件(适用WSL)
linux·sql·qt·oracle·oci