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

openGauss每日一练第2天-gsql使用Part3

原创 libai21 2022-11-25
769

4.使用两种方法,连到postgres数据库中

方法1:

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=# \c postgres
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database “postgres” as user “omm”.
openGauss=#

方法2:

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=#

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

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

openGauss=# create table customer_new as select * from customer_t;
INSERT 0 0
openGauss=# \q
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}
public | t1 | table | omm | {orientation=row,compression=no}
(3 rows)

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

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

openGauss=# select * from customer_t;
c_customer_sk | c_customer_id | c_first_name | c_last_name
---------------±--------------±-------------±------------
3769 | 5 | Grace | White
(1 row)

openGauss=# delete from customer_t;
DELETE 1
openGauss=# select * from customer_t;

openGauss=# c_customer_sk | c_customer_id | c_first_name | c_last_name
---------------±--------------±-------------±------------
(0 rows)

openGauss=# rollback;
ROLLBACK
openGauss=# select * from customer_t;
(1 row)

openGauss=# c_customer_sk | c_customer_id | c_first_name | c_last_name
---------------±--------------±-------------±------------
3769 | 5 | Grace | White

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
-d, --dbname=DBNAME database name to connect to (default: “omm”)

openGauss=# \h
Available help:
ABORT CREATE DATA SOURCE DROP NODE GROUP
ALTER APP WORKLOAD GROUP CREATE DATABASE DROP OPERATOR
ALTER APP WORKLOAD GROUP MAPPING CREATE DIRECTORY DROP OWNED
ALTER AUDIT POLICY CREATE EXTENSION DROP PACKAGE
ALTER DATA SOURCE CREATE FOREIGN TABLE DROP PACKAGE BODY
ALTER DATABASE CREATE FUNCTION DROP PROCEDURE

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

评论