暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第6天 | 学习心得体会

220

概述

本文档记录openGauss 3.0.0数据库每日一练第6天课程作业,学习openGauss体系结构,通过实验,了解用户一次只能连接到一个数据库,没法访问其他数据库的对象。

课程练习

创建用户user6,分别在数据库musicdb6、数据库musicdb7创建表t11,t21

[omm@ogauss1 ~]$ gsql -d postgres -p 15400 -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm@local:/opt/huawei/tmp [postgres]=#create user user6 with sysadmin identified by 'zs@123456'; CREATE ROLE omm@local:/opt/huawei/tmp [postgres]=#create database musicdb6; CREATE DATABASE omm@local:/opt/huawei/tmp [postgres]=#create database musicdb7; CREATE DATABASE omm@local:/opt/huawei/tmp [postgres]=#\c musicdb6 Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb6" as user "omm". omm@local:/opt/huawei/tmp [musicdb6]=#create table day6_db6(id int,name char(10)); CREATE TABLE omm@local:/opt/huawei/tmp [musicdb6]=#insert into day6_db6 values(1,'musicdb6'); INSERT 0 1 omm@local:/opt/huawei/tmp [musicdb6]=#\c musicdb7 Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb7" as user "omm". omm@local:/opt/huawei/tmp [musicdb7]=#create table day6_db7(id int,name char(10)); CREATE TABLE omm@local:/opt/huawei/tmp [musicdb7]=#insert into day6_db7 values(1,'musicdb7'); INSERT 0 1

user6用户连接到数据库musicdb6,并访问数据库musicdb6下的表day6_db6

[omm@ogauss1 ~]$ gsql -d postgres -p 15400 -r gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm@local:/opt/huawei/tmp [postgres]=#\c musicdb6 user6 Password for user user6: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb6" as user "user6". user6@local:/opt/huawei/tmp [musicdb6]=>\d List of relations Schema | Name | Type | Owner | Storage --------+----------+-------+-------+---------------------------------- public | day6_db6 | table | omm | {orientation=row,compression=no} (1 row) user6@local:/opt/huawei/tmp [musicdb6]=>select * from musicdb6.public.day6_db6; id | name ----+------------ 1 | musicdb6 (1 row)

访问成功。

在这个连接中(使用数据库用户user6连接到数据库musicdb6)访问数据库musicdb7下的day6_db7表(会报错)

user6@local:/opt/huawei/tmp [musicdb6]=>select * from musicdb7.public.day6_db7; ERROR: cross-database references are not implemented: "musicdb7.public.day6_db7" LINE 1: select * from musicdb7.public.day6_db7; ^ user6@local:/opt/huawei/tmp [musicdb6]=>

访问失败

使用数据库用户user6连接到数据库musicdb7,访问数据库musicdb7下的day6_db7表

user6@local:/opt/huawei/tmp [musicdb6]=>\c musicdb7 Password for user user6: Non-SSL connection (SSL connection is recommended when requiring high-security) You are now connected to database "musicdb7" as user "user6". user6@local:/opt/huawei/tmp [musicdb7]=>select * from musicdb7.public.day6_db7; id | name ----+------------ 1 | musicdb7 (1 row)

访问成功。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论