openGauss每日一练第6天
一次连接只能同时访问一个数据库
实验一个用户只能连接到一个数据库,不能访问其他数据库里的对象并完成课后作业
创建用户user1并授予权限
omm=# create user user1 identified by 'Test@123'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# alter user user1 sysadmin; omm=# ALTER ROLE
创建数据库db1和db2
omm=# create database db1; CREATE DATABASE omm=# create database db2; CREATE DATABASE
分别在两个数据库中创建t1和t2表
omm=# \c db1 user1 Password for user user1: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "db1" as user "user1". db1=> create table t1(name char(10)); CREATE TABLE db1=> \c db2 user1 Password for user user1: db2=> Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "db2" as user "user1". create table t2(name char(10)); CREATE TABLE
从db2中访问t1和t2表
db2=> select * from db1.public.t1; db2=> ERROR: cross-database references are not implemented: "db1.public.t1" LINE 1: select * from db1.public.t1; db2=> select * from db2.public.t2; name ------ (0 rows)
可以发现访问t1表的时候报错了,而t2表在db2数据库可以正常访问。
总结
在用户连接数据库后的连接中无法访问其他数据库内的对象,只能访问当前连接的数据库对象,这时起到了对数据库内数据的隔离保护作用,让多数据库实例内的数据更安全。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




