当前位置:网站首页>MogDB study notes - starting from 0
MogDB study notes - starting from 0
2022-08-08 18:45:00 【Ink Sky Wheel】
MogDB学习笔记-从0开始
写在前面
MogDB是基于OpenGauss开发的、OpenGauss又是基于PostgreSql开发的,My cognitive opportunities for these three database systems are:0,So refer to it when you studyOpenGauss和PostgreSql的官方文档.
Learning environment is set up based on the previous noteMogDB主从环境,接下来从0开始学习PGfaction database.
Manually deploy the address of the master-slave note:https://www.modb.pro/db/453770
基本概念
through the basic think about itMysqlActually quite similar,只是mysqlThere is no concept of schema.
数据库(database)
数据库用于管理各类数据对象,与其他数据库隔离.创建数据对象时可以指定对应的表空间,如果不指定相应的表空间,相关的对象会默认保存在PG_DEFAULT空间中.数据库管理的对象可分布在多个表空间上.
表空间(tablespace)
在openGauss中,表空间是一个目录,可以存在多个,里面存储的是它所包含的数据库的各种物理文件.由于表空间是一个目录,仅是起到了物理隔离的作用,其管理功能依赖于文件系统.
模式(schema)
openGauss的模式是对数据库做一个逻辑分割.所有的数据库对象都建立在模式下面.openGauss的模式和用户是弱绑定的,所谓的弱绑定是指虽然创建用户的同时会自动创建一个同名模式,但用户也可以单独创建模式,并且为用户指定其他的模式.
用户和角色(user role)
openGauss使用用户和角色来控制对数据库的访问.根据角色自身的设置不同,一个角色可以看做是一个数据库用户,或者一组数据库用户.在openGauss中角色和用户之间的区别只在于角色默认是没有LOGIN权限的.在openGauss中一个用户唯一对应一个角色,不过可以使用角色叠加来更灵活地进行管理.
数据文件(Datafile Segment)
Each table usually only corresponds to a data file.If a particular data is greater than the table1GB,will be divided into multiple data file storage
数据库(block)
The basic unit of the database management,默认是8k
学习环境
NODE1(主库) | NODE2(从库) | |
Hostname | mogdb1 | mogdb2 |
IP | 10.80.9.249 | 10.80.9.250 |
磁盘 | 20G | 20G |
内存 | 2G | 2G |
MogDB初窥
1、登录主库
[[email protected] ~]$ gsql -d postgres -p 26000 |
2、创建用户
create user zkh with password "Zkh12345678"; |
3、Empower new usersdba
grant all privileges to zkh; |
4、创建数据库,并指定所有者
create database db_mogdb owner zkh; |
5、Verify that the slave library is successfully synchronized
主库
gsql -d postgres -p 26000 -l |

从库

It can be seen that the operation on the master library is also successfully synchronized from the slave library
6、Using the new user to connect the new library
gsql -d db_mogdb -p 26000 -U zkh -W Zkh12345678 |
7、创建表
CREATE TABLE mytable (firstcol int); |
Check the table information just created
select * from pg_tables where tablename='mytable'; |

By querying, you can see that this table belongs topublic模式下.这一点区别于Oracle或者DB2,Because the above two databases will be created to the current by default when the table is createduser的schema下面
8、创建模式
CREATE SCHEMA zkh AUTHORIZATION zkh; |
再次创建表
CREATE TABLE mytable1(firstcol int); |
查询表的信息
select * from pg_tables where tablename in('mytable','mytable1'); |

new table can be seenmytable1已经创建在zkh的模式下了.
9,Verify that the table is in sync from the library
登录从库
gsql -d db_mogdb -p 26000 -U zkh -W Zkh12345678 |
Whether the query table is synchronized
select * from pg_tables where tablename in('mytable','mytable1'); |

The data has been synchronized to the slave library
10、Query the physical location of data files
首先查询data目录的位置,You can use several methods such as viewingconfig文件等等,这里使用sql查询
show data_directory; |

The table data will be stored in the data directorybase目录.Each database has a correspondingid,先看一下base目录的目录结构

查询数据库对应的id
select datname,oid from pg_database; |

数据文件存放在base/16388目录下
Further query tableoid是什么
select oid,relname,relnamespace from PG_CLASS where relname like 'mytable%'; |


The two files in the picture are the tables I just created
最后
Note this timeMogDBThe first use also verified whether the built master-slave environment can be synchronized normally,continue from0开始学习MogDB,Take this opportunity to learnPG派系.
边栏推荐
猜你喜欢
随机推荐
Shell脚本三剑客(grep、sed、awk)
串行通信:常见的串行通信接口协议UART、SPI、I2C简介
codeforces 231A.Team
面试突击:输入URL之后会执行什么流程?
Laravel 5.8 Notes
APICloud AVM 封装日期和时间选择组件
Flush can buy stock?Is it safe to buy stocks?
智文最终版本
水印图像读取与制作,三通道图转为4通道,制作透明图
flask基础知识:
请问shake数据库中mongoshake同步过程中,src_mongo挂了,同步服务不会退出吗?
第4讲:SQL语句之DDL类型的数据库定义语言
TensorFlow学习记录(七):生成对抗网络
内核实战教程第1期|数据库系统概述,带你走近 OceanBase 研发环境!
mv-lcd初始化
HCIP第十三天作业——综合实验
CF633C(trie树dfs / 字符串hash + 线性dp)
feign的性能优化、Feign的使用-最佳优化两种方案
Nioke 2022 Summer Multi-School 6 B Eezie and Pie (Difference on the tree + multiplication to find the kth ancestor board)
A Preliminary Study on Pannellum, a Lightweight Panorama Viewer









