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

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

原创 olabll1 2022-11-25
195

1.gsql命令连到数据库omm

–使用omm用户连接到本机omm数据库的5432端口,命令中的-r选项提供了对gsql命令的历史版本支持。

su - omm  
gsql -r  
或  
gsql -d omm -p 5432 -r

复制

2.查看数据库的版本、版权信息

select version();  
show server\_version;  
\copyright

复制

3.常见元命令使用

\pset border  里有好几种选择

\x 打开扩展表格式模式,再次执行\x 关闭扩展

4.使用两种方法,连到postgres数据库中,连上切库或者直接连

gsql -r  
\c postgres  
或  
gsql -d postgres -p 5432 -r

复制

5.测试gsql中的默认事务自动提交功能

openGauss=# --查看gsql中事务是否默认为自动提交

openGauss=# show AUTOCOMMIT;  
+------------+  
| autocommit |  
+------------+  
| on |  
+------------+  
(1 row)  

复制

openGauss=# --测试gsql中事务默认为自动提交功能

openGauss=# create table customer\_new as select \* from customer\_t;  
INSERT 0 1  
openGauss=# \q 

复制

omm@modb:~$ --重新登录后看到之前创建的表customer_new:

omm@modb:~$ gsql -d postgres -p 5432 -r  
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr )  
Non-SSL connection (SSL connection is recommended when requiring high-security)  
Type "help" for help.  
  
openGauss=# \dt  
List of relations  
Schema | Name | Type | Owner | Storage  
\--------+--------------+-------+-------+----------------------------------  
public | customer\_new | table | omm | {orientation=row,compression=no}  
public | customer\_t | table | omm | {orientation=row,compression=no}  
(2 rows)

复制

6.测试gsql中的事务手动提交功能

–测试gsql手动提交
#Opengauss默认执行完一条语句后,立即提交。可以关闭自动提交功能:
#注意:此处设置AUTOCOMMIT必须用大写!

show autocommit可以小写

omm=# \set autocommit off  
omm=# show AUTOCOMMIT;  
autocommit  
------------  
on  
(1 row)  
  
omm=# show autocommit;  
autocommit  
------------  
on  
(1 row)

复制

7.了解gsql相关帮助

omm@modb:~$ gsql --help  
gsql is the openGauss interactive terminal.  
  
Usage:  
gsql [OPTION\]... [DBNAME [USERNAME]]  
  
General options:  
-c, --command=COMMAND run only single command (SQL or internal) and exit

omm@modb:~$ gsql -r  
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr )  
Non-SSL connection (SSL connection is recommended when requiring high-security)  
Type "help" for help.  
  
omm=# \h  
Available help:  
ABORT CREATE DATA SOURCE DROP NODE GROUP

omm=# \?  
General  
\copyright show openGauss usage and distribution terms  
\g [FILE] or ; execute query (and send results to file or |pipe)  
h(help) [NAME] help on syntax of SQL commands, * for all commands

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

评论

墨天轮福利君
暂无图片
2年前
评论
暂无图片 0
作业审核合格,一起参与21天openGauss学习打卡活动! 活动详情:https://www.modb.pro/db/551619
2年前
暂无图片 点赞
评论