当前位置:网站首页>Basic operations of openGauss database (super detailed)
Basic operations of openGauss database (super detailed)
2022-08-02 12:34:00 【m0_67394006】
openGauss数据库常用操作命令(超详细)
1. 以操作系统用户omm登录数据库主节点
su - omm
1.1 启动服务
分布式openGauss:
gs_om -t start 启动服务
gs_om -t restart 重启服务
集中式openGauss:
gs_om -t stop 关闭服务
gs_om -t start 启动服务
1.2 使用“gs_om -t status –detail”命令查询openGaussStatus of each instance.
gs_om -t status --detail
Centralized is deployed as followsopenGauss集群,The server for the database master node instanceIP地址为172.20.73.178
数据库主节点数据路径为/opt/gaussdb/master1/
centralized noCN,通过主DN访问
[[email protected] ~]$ gs_om -t status --detail
[ CMServer State ]node node_ip instance state
2 openGauss02 172.20.73.179 1 /opt/gaussdb/cmserver/cm_server Standby
3 openGauss03 172.20.74.210 2 /opt/gaussdb/cmserver/cm_server Primary[ ETCD State ]
node node_ip instance state
1 openGauss01 172.20.73.178 7001 /opt/huawei/xuanyuan/etcd StateFollower
2 openGauss02 172.20.73.179 7002 /opt/huawei/xuanyuan/etcd StateLeader
3 openGauss03 172.20.74.210 7003 /opt/huawei/xuanyuan/etcd StateFollower[ Cluster State ]
cluster_state : Normal
redistributing : No
balanced : Yes
current_az : AZ_ALL[ Datanode State ]
node node_ip instance state | node node_ip instance state | node node_ip instance state
1 openGauss01 172.20.73.178 6001 /opt/gaussdb/master1 P Primary Normal | 2 openGauss02 172.20.73.179 6002 /opt/gaussdb/slave1_1 S Standby Normal | 3 openGauss03 172.20.74.210 6003 /opt/gaussdb/slave1_2 S Standby Normal
[[email protected] ~]$
1.3 检查数据库性能
gs_checkperf
1. Displays performance statistics on the screen in a brief format.
gs_checkperf -i pmk -U omm
2. Displays performance statistics on the screen in a detailed format.
gs_checkperf -i pmk -U omm --detai
1.4 确认数据库主节点的端口号
在1.2查到的数据库主节点数据路径下的postgresql.conf文件中查看端口号信息.示例如下:
cat /opt/gaussdb/master1/postgresql.conf |grep port
[[email protected] ~]$ cat /opt/gaussdb/master1/postgresql.conf |grep port
port = '36000' # (change requires restart)
#ssl_renegotiation_limit = 0 # amount of data between renegotiations, no longer supported
# supported by the operating system:
- 36000为数据库主节点的端口号
- Port number when installing the database,会在xml文件中配置,Check when installingxmlConfiguration files can also find ports.
1.5列出所有可用的数据库
gsql -d postgres -p 36000 -l
[[email protected] ~]$ gsql -d postgres -p 36000 -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+-----------+---------+-------+-------------------
db1 | song | SQL_ASCII | C | C |
db2 | song | SQL_ASCII | C | C |
kwdb | kw | SQL_ASCII | C | C |
mydb | song | GBK | C | C |
postgres | omm | SQL_ASCII | C | C |
song_suse | song | SQL_ASCII | C | C |
template0 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
(8 rows)
其中,postgres为openGauss安装完成后默认生成的数据库.初始可以连接到此数据库进行新数据库的创建.
2. 查看数据库对象
1. Log in to the default databasepostgres:
gsql -d postgres -p 36000
[[email protected] ~]$ gsql -d postgres -p 36000
gsql ((GaussDB Kernel V500R002C00 build fab4f5ea) compiled at 2021-10-24 11:58:09 commit 3086 last mr 6592 release)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
openGauss=#
2. Log in to the self-built databasesong_suse:
gsql -d 数据库名 -p 36000 -U 用户名 -W 密码 -r
[[email protected] ~]$ gsql -d song_suse -p 36000 -U song -W Info1234 -r
gsql ((GaussDB Kernel V500R002C00 build fab4f5ea) compiled at 2021-10-24 11:58:09 commit 3086 last mr 6592 release)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
song_suse=>
1)查看帮助信息:
postgres=# ?
2)切换数据库:
postgres=# c dbname
3)列举数据库:
使用l元命令查看数据库系统的数据库列表.
postgres=# l
使用如下命令通过系统表pg_database查询数据库列表.
postgres=# select dataname from pg_database;
4)列举表:
postgres=# dt
postgres=# d
5)列举所有表、视图和索引:
postgres=# d+
6)使用gsql的d+命令查询表的属性:
postgres=# d+ tablename
7)查看表结构:
postgres=# d tablename
8)列举schema:
postgres=# dn
9)查看索引:
postgres=# di
10)查询表空间:
使用gsql程序的元命令查询表空间.postgres=# db
检查pg_tablespace系统表.如下命令可查到系统和用户定义的全部表空间.
postgres=# select spcname from pg_tablespace;
11)查看数据库用户列表:
postgres=# select * from pg_user;
12)要查看用户属性:
postgres=# select * from pg_authid;
13)查看所有角色:
postgres=# select * from PG_ROLES;
14)切换用户:
postgres=# c – username
15)退出数据库:
postgres=# q
3. 常用SQL语言:
1)创建数据库用户
create user 用户名 with password "密码";
create user jack password "Info1234";
every time a new user is created,The system creates a new user with the same name in the currently logged in databaseSchema.对于其他数据库,Same name if requiredSchema,It needs to be created manually by the user.
openGauss=# create user jack password "Info1234";
CREATE ROLE
openGauss=# du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------------------------------------------------------------+-----------
jack | | {}
kw | | {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}
song | Create role, Sysadmin | {}
2)删除数据库用户
drop user 用户名 cascade;
drop user jack cascade;
3)创建数据库,and specify the ownerowner
create database 数据库名 owner 用户名;
create database jack_test owner jack;
4)为用户授权
Grants a user all permissions on a database
grant all privileges on database jack_test to jack;
Add a role to the userCREATEROLE权限
alter user jack createrole;
将sysadmin权限授权给用户joe
grant all privileges to jack;
openGauss=# create database jack_test owner jack;
CREATE DATABASE
openGauss=# l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+-----------+---------+-------+-------------------
db1 | song | SQL_ASCII | C | C |
db2 | song | SQL_ASCII | C | C |
jack_test | jack | SQL_ASCII | C | C |
kwdb | kw | SQL_ASCII | C | C |
mydb | song | GBK | C | C |
postgres | omm | SQL_ASCII | C | C |
song_suse | song | SQL_ASCII | C | C | =Tc/song +
| | | | | song=CTc/song +
| | | | | song=APm/song
template0 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
template1 | omm | SQL_ASCII | C | C | =c/omm +
| | | | | omm=CTc/omm
(9 rows)
openGauss=# grant all privileges on database jack_test to jack;
GRANT
openGauss=# alter user jack createrole;
ALTER ROLE
openGauss=# grant all privileges to jack;
ALTER ROLE
openGauss=# du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------------------------------------------------------------+-----------
jack | Create role, Sysadmin | {}
kw | | {}
omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}
song | Create role, Sysadmin | {}
openGauss=#
5)删除数据库
drop database 数据库名;
drop database jack_test;
6)创建schema(模式,默认为public)
1. 切换到jack_test数据库:
openGauss=# c jack_test
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "jack_test" as user "omm".
2. 切换到jack用户
jack_test=# c - jack
Password for user jack:
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "jack_test" as user "jack".
3. 查看schema
jack_test=> dn
List of schemas
Name | Owner
----------------------+-------
blockchain | omm
cstore | omm
db4ai | omm
dbe_application_info | omm
dbe_file | omm
dbe_lob | omm
dbe_match | omm
dbe_output | omm
dbe_perf | omm
dbe_pldebugger | omm
dbe_pldeveloper | omm
dbe_random | omm
dbe_raw | omm
dbe_scheduler | omm
dbe_session | omm
dbe_sql | omm
dbe_task | omm
dbe_utility | omm
pkg_service | omm
pkg_util | omm
public | omm
snapshot | omm
sqladvisor | omm
sys | omm
(24 rows)
jack_test=>
4. 查看当前用户:
select * from current_user;
select user;
jack_test=> select * from current_user;
current_user
--------------
jack
(1 row)
jack_test=> select user;
current_user
--------------
jack
(1 row)
jack_test=>
5. 为用户jack创建一个模式jack1
create schema 模式名 authorization 用户名;
create schema jack1 authorization jack;
jack_test=> create schema jack1 authorization jack;
CREATE SCHEMA
jack_test=> dn
List of schemas
Name | Owner
----------------------+-------
blockchain | omm
cstore | omm
db4ai | omm
dbe_application_info | omm
dbe_file | omm
dbe_lob | omm
dbe_match | omm
dbe_output | omm
dbe_perf | omm
dbe_pldebugger | omm
dbe_pldeveloper | omm
dbe_random | omm
dbe_raw | omm
dbe_scheduler | omm
dbe_session | omm
dbe_sql | omm
dbe_task | omm
dbe_utility | omm
jack1 | jack
pkg_service | omm
pkg_util | omm
public | omm
snapshot | omm
sqladvisor | omm
sys | omm
(25 rows)
jack_test=>
6. 修改schema名称
alter schema jack1 rename to jack2;
7. To change the default for the current sessionSchema,请使用SET命令.
Execute the following command to set the search path to myschema、public,首先搜索myschema.
set search_path to jack2;
查看当前schema
show search_path;
jack_test=> set search_path to jack2;
SET
jack_test=> show search_path;
search_path
-------------
jack2
(1 row)
jack_test=>
7)授权
grant usage on schema jack2 to jack;
回收(revoke)
将Schema中的表或者视图对象授权给其他用户或角色时,需要将表或视图所属Schema的USAGE权限同时授予该用户或角色.Otherwise the user or role will only see the names of these objects,并不能实际进行对象访问.
8)Database renamed
alter database jack_test rename to jack_db;
9)command to view the current database storage encoding
show server_encoding;
10)Query table distribution columns(分布式openGauss才有,centralized no):
select getdistributekey ('schemaName.tableName');
select getdistributekey ('tableName');
11)修改omm管理员密码
openGaussDatabase login if promptedomm密码过期,需要修改omm管理员密码,例如:
alter role omm identified by '新密码' replace '旧密码';
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在.深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小.自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前.因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担.添加下方名片,即可获取全套学习资料哦
边栏推荐
猜你喜欢
随机推荐
How to set up wireless PPI communication between Weiluntong touch screen and S7-200smart?
自己如何做小程序呢?
如何更好评估信用贷风险?看这场评分卡模型直播就可以了
PHP伪协议详解
SQL Server 数据库之生成与执行 SQL 脚本
新特性解读 | MySQL 8.0 GIPK 不可见主键
Process finished with exit code 1
After Effects 教程,如何在 After Effects 中对蒙版进行动画绘制?
Taurus.MVC V3.0.3 Microservice Open Source Framework Released: Make the evolution of .NET architecture easier in large concurrency.
kvm部署
redis cluster cluster, the ultimate solution?
To eliminate air bubbles to save the mushroom h5 small game source code
Likou 977-Squaring of ordered arrays - brute force method & double pointer method
分布式限流利器,手撕&redisson实现
如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?
Thymeleaf
PHP+MYSQL【学生信息管理系统】(极简版)
NVIDIA NeMo Metrics 轻量性能采集系统
According to the field classification Golang map array
FreeRTOS实验--一个函数创建多个任务








