openGauss下的操作指令【华为根技术】

举报
tea_year 发表于 2025/04/29 15:05:49 2025/04/29
【摘要】 高斯数据库的启动/停止/重启指令:gs_ctl start -D /home/gauss/openGauss/data/gs_ctl stop-D /home/gauss/openGauss/data/gs_ctl restart -D /home/gauss/openGauss/data/#查看进程ps ux |grep gauss#查看端口号netstat -lntup|grep gau...

openGauss 是一款全面友好开放,携手伙伴共同打造的企业级开源关系型数据库。openGauss采用木兰宽松许可证v2发行,提供面向多核架构的极致性能、全链路的业务、数据安全、基于AI的调优和高效运维的能力。openGauss深度融合华为在数据库领域多年的研发经验,结合企业级场景需求,持续构建竞争力特性。同时,openGauss也是一个开源、免费的数据库平台,鼓励社区贡献、合作。

数据库作为信息系统基础底座软件,在大数据背景下,数据库的数据量和节点规模日益增长,数据库使用方越来越看重系统运行是否稳定、安全和高效,这也使数据库自身的运行与维护的要求也随之增高。是否拥有成熟健全的运行维护体系,支撑团队的数据库运维管理能力是否足够专业化和标准化,这都将影响和制约着整个企业信息化发展的步伐。

数据库运维一般会涉及到数据存储方案设计、数据库表设计、索引设计和SQL优化等,另外还包括对数据库进行变更、监控、备份、高可用设计等工作。

本文将从数据库运维的角度简单介绍一下openGauss在日常运维工作中常用的操作命令,以便能够帮助大家轻松使用openGauss数据库。

常用运维相关命令


第一组:openGauss启停

高斯数据库的启动/停止/重启指令:

gs_ctl start -D /home/gauss/openGauss/data/

gs_ctl stop-D /home/gauss/openGauss/data/

gs_ctl restart -D /home/gauss/openGauss/data/

#查看进程

ps ux |grep gauss

#查看端口号

netstat -lntup|grep gauss

ss -lntup|grep gauss


第二组:openGauss库表指令

#进入到高斯数据库

使用jack用户连接到远程主机postgres数据库的15400端口。复杂格式

gsql -h 10.180.123.163 -d postgres -U jack -p 15400

[gauss@server1 ~]$ gsql -d postgres -p 5432

gsql ((openGauss-lite 6.0.1 build 84c20a90) compiled at 2025-01-17 17:49:04 commit 0 last mr release)

Non-SSL connection (SSL connection is recommended when requiring high-security)

Type "help" for help.

openGauss=#

#查看相应的数据库

openGauss=# \l

List of databases

Name | Owner | Encoding | Collate | Ctype | Access privileges

-------------+-------+----------+-------------+-------------+-------------------

human_staff | gauss | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |

postgres | gauss | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |

template0 | gauss | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/gauss +

| | | | | gauss=CTc/gauss

template1 | gauss | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/gauss +

| | | | | gauss=CTc/gauss

(4 rows)

#库的删除

drop database human_staff;

DROP DATABASE

#创建数据库

openGauss=# create database human_staff;

CREATE DATABASE

#和\l 类似 查看库指令

openGauss=# SELECT datname FROM pg_database;

datname
-------------
template1

human_staff

template0

postgres

(4 rows)

#进入到human_staff

openGauss=# \c human_staff

Non-SSL connection (SSL connection is recommended when requiring high-security)

You are now connected to database "human_staff" as user "gauss".

#下面的指令不会成功,不是mysql的指令。
human_staff=# select * from tables;

第三#查看表信息

#human_staff=# \dt

No relations found.


human_staff=# create table users(id int,uname varchar(50));

CREATE TABLE

human_staff=# \dt

List of relations

Schema | Name | Type | Owner | Storage

--------+-------+-------+-------+----------------------------------

public | users | table | gauss | {orientation=row,compression=no}

(1 row)
human_staff=# insert into users values(1,'tom');

INSERT 0 1

human_staff=# select * from users;

id | uname

----+-------

1 | tom

(1 row)


#变量的设置

#设置变量
openGauss=# \set dbname2 shopdb
#显示变量
openGauss=# \echo :dbname2
shopdb

#删除变量
openGauss=# \unset dbname2


#解决:^A H问题;

bash

# 在root用户下,安装rlwrap

sudo yum install rlwrap

# 使用rlwrap运行gsql

rlwrap gsql -d postgres -p 5432


第三组:openGauss表数据管理

需要提前创建库omm

1、创建一张表 products

字段名 数据类型 含义
product_id integer 产品编号
product_name char(30) 产品名
category char(20) 种类

----建表语句

create table products
( product_id integer,
product_name char(30),
category char(20)
) ;

----查看表的结构
omm=# \d products

2、向表中插入数据,分别采用一次插入一条和一次插入多条记录的方式

insert into products(product_id,product_name,category) values (1502, ‘olympus camera’, ‘electrncs’);

insert into products(product_id,product_name,category) values

(1601,‘lamaze’,‘toys’),
(1700,‘wait interface’,‘Books’),
(1666,‘harry potter’,‘toys’);



3、查询表中所有记录及记录数

select count(*) from products;

select * from products;

4、查询表中所有category记录,并将查询结果按升序排序

select category from products order by category asc;

5、查询表中category为toys的记录

select * from products where category = ‘toys’;

6、更改表中某个字段的值

update products set product_name=‘camera’ where product_id=1502;
select * from products;

6、删除表products

drop table products;

select * from products;

总结

openGauss数据库作为一款基于SQL标准的关系型数据库管理系统,支持广泛的SQL指令进行数据操作、查询、管理以及权限控制。OpenGauss提供面向多核的极致性能、全链路的业务和数据安全、基于AI的调优和高效运维的能力让我受益匪浅。尤其是OpenGauss在AI自治方面的能力真是令人惊喜。自调优、自诊断自愈、自组装这三大自治简直是所有dba的福音。

 
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。