当前位置:网站首页>Opengauss database development and debugging tool guide
Opengauss database development and debugging tool guide
2022-07-03 02:52:00 【Gauss squirrel Club】
The main content is to use gsql Database development debugging tool connection openGauss database .
gsql Client tools
gsql yes openGauss Provide database connection tools running under the command line , You can connect to the server through this tool and operate and maintain it , In addition to the basic functions of operating the database ,gsql Several advanced features are also available , User friendly .
gsql Connect to database
gsql yes openGauss Native Client Tools . Use gsql Connect to database , You can interactively input 、 edit 、 perform SQL sentence .
Confirm connection information
The client tool connects to the database through the database master node . So before connecting , You need to get the server where the database master node is located IP Address and port number information of the database master node .
step 1 Switch to omm user , Operating system users omm Log in to the database master node .
[[email protected] script]# su - omm
step 2 Use “gs_om -t status --detail” Command query openGauss Each instance .
[[email protected] ~]$ gs_om -t status --detail
The situation is shown below :
[ DBnode State ] node node_ip instance state ------------------------------------------------------------------------------------- 1 db1 192.168.0.58 6001 /gaussdb/data/db1 P Primary Normal
The server with the database master node instance deployed as above IP The address is 192.168.0.58. The data path of the database master node is “/gaussdb/data/db1”.
step 3 Confirm the port number of the database master node .
Steps in 2 Under the data path of the database master node postgresql.conf Check the port number information in the file . Examples are as follows :
port = 26000 # (change requires restart)#ssl_renegotiation_limit = 0 # amount of data between renegotiations, no longer supported#tcp_recv_timeout = 0 # SO_RCVTIMEO, specify the receiving timeouts until reporting an error(change requires restart)#comm_sctp_port = 1024 # Assigned by installation (change requires restart)#comm_control_port = 10001 # Assigned by installation (change requires restart) # supported by the operating system: # The heartbeat thread will not start if not set localheartbeatport and remoteheartbeatport. # e.g. 'localhost=xx.xx.xxx.2 localport=12211 localheartbeatport=12214 remotehost=xx.xx.xxx.3 remoteport=12212 remoteheartbeatport=12215, localhost=xx.xx.xxx.2 localport=12213 remotehost=xx.xx.xxx.3 remoteport=12214' # %r = remote host and portalarm_report_interval = 10
26000 Is the port number of the database master node .
Please record the server of the database master node instance in actual operation IP Address , Data path and port number , And replace it according to the actual situation in the subsequent operation .
Local connection database
step 1 Switch to omm user , Operating system users omm Log in to the database master node .
[[email protected] script]# su - omm
step 2 Start database service
[[email protected] script]# gs_om -t start
It is shown as follows , Successful launch .
Starting cluster.==================================================================================Successfully started.
step 3 Connect to database .
Execute the following command to connect to the database .
[[email protected] ~]$ gsql -d postgres -p 26000 -r
among postgres The name of the database to be connected ,26000 Is the port number of the database master node . Please replace according to the actual situation .
After successful connection , The system displays information similar to :
gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
omm The user is an administrator user , Therefore, the system displays “DBNAME=#”. If you log in and connect to the database as an ordinary user , systems display “DBNAME=>”.
“Non-SSL connection” Indicates not used SSL How to connect to the database . If high security is required , Please use SSL Make it safe TCP/IP Connect .
step 4 Exit database .
postgres=# \q
gsql get help
Prerequisite
The following operations are openGauss Execute on the host where the database master node of ( Local connection database ), Switch to omm user .
su - omm
When connecting to the database , You can use the following command to get help information
gsql --help
The following help information is displayed :
...... 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: "postgres") -f, --file=FILENAME execute commands from file, then exit ......
After connecting to the database , You can use the following command to get help information
step 1 Use the following command to connect to the database .
gsql -d postgres -p 26000 -r
step 2 Input help Instructions .
postgres=#help
The following help information is displayed :
You are using gsql, the command-line interface to gaussdb. Type: \copyright for distribution terms \h for help with SQL commands \? for help with gsql commands \g or terminate with semicolon to execute query \q to quit
step 3 View copyright information .
postgres=#\copyright
The following copyright information is displayed :
openGauss Database Management SystemCopyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
step 4 see openGauss All supported SQL sentence .
postgres=#\h
Display the following information :
Available help: ABORT ALTER AGGREGATE ALTER APP WORKLOAD GROUP ... ...
step 5 see CREATE DATABASE The parameters of the command can use the following command .
postgres=#\help CREATE DATABASE
The following help information is displayed :
Command: CREATE DATABASE Description: create a new database Syntax: CREATE DATABASE database_name [ [ WITH ] {[ OWNER [=] user_name ]| [ TEMPLATE [=] template ]| [ ENCODING [=] encoding ]| [ LC_COLLATE [=] lc_collate ]| [ LC_CTYPE [=] lc_ctype ]| [ DBCOMPATIBILITY [=] compatibility_type ]| [ TABLESPACE [=] tablespace_name ]| [ CONNECTION LIMIT [=] connlimit ]}[...] ];
step 6 see gsql Supported commands .
postgres=# \?
Display the following information :
General \copyright show PostgreSQL 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 \q quit gsql ... ...
step 7 Exit database
postgres=# \q
gsql Command to use
Prerequisite
The following operations are openGauss Execute on the host where the database master node of ( Local connection database ), Switch to omm user .
su - omm
Execute a string command
gsql Command directly executes a string command that displays copyright information
gsql -d postgres -p 26000 -c "\copyright"
It is shown as follows , Exit after display gsql Environmental Science :
openGauss Database Management SystemCopyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved$
Use file as command source instead of interactive input
step 1 Create a folder to store relevant documents .
mkdir /home/omm/openGauss
step 2 create a file , For example, the file name is “mysql.sql”, And write executable sql sentence “select * from pg_user;”.
vi /home/omm/openGauss/mysql.sql
File open input i, Get into INSERT Pattern , Input ” select * from pg_user;”.
select * from pg_user;
And then click Esc, Input “:wq” Save the document and exit .
step 3 Execute the following command and use the file as the command source .
gsql -d postgres -p 26000 -f /home/omm/openGauss/mysql.sql
give the result as follows , also gsql Will end after processing the file :
usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valbegin | valuntil | respool | parent | spacelimit | useconfig | nodegroup | tempspacelimit | spillspacelimit ---------+----------+-------------+----------+-----------+---------+----------+----------+----------+--------------+--------+------------+-----------+-----------+----------------+----------------- omm | 10 | t | t | t | t | ******** | | | default_pool | 0 | | | | | jack | 16385 | f | f | f | f | ******** | | | default_pool | 0 | | | | | (2 rows)total time: 3 ms
step 4 If FILENAME yes -( A hyphen ), Read from standard input .
gsql -d postgres -p 26000 -f -postgres=# select * from pg_user;usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valbegin | valuntil | respool | parent | spacelimit | useconfig | nodegroup | tempspacelimit | spillspacelimit ---------+----------+-------------+----------+-----------+---------+----------+----------+----------+--------------+--------+------------+-----------+-----------+----------------+----------------- omm | 10 | t | t | t | t | ******** | | | default_pool | 0 | | | | | joe | 16385 | f | f | f | f | ******** | | | default_pool | 0 | | | | | (2 rows)
step 5 Exit database connection .
postgres=# \q total time: 174163 ms
List all available databases (\l Of l Express list)
gsql -d postgres -p 26000 -l
give the result as follows , also gsql Will end after the display :
List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+-----------+---------+-------+------------------- db_tpcc | joe | SQL_ASCII | C | C | postgres | omm | 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(4 rows)$
Set up gsql Variable NAME by VALUE
step 1 Set up foo The value of is bar.
gsql -d postgres -p 26000 -v foo=bar
step 2 The database can display foo Value .
postgres=# \echo :foobar
step 3 Exit database connection .
postgres=> \q
Print gsql Version information .
gsql -V
give the result as follows , also gsql Will end after the display :
gsql (openGauss 1.0.0 build 0bd0ce80) compiled at 2020-06-30 18:19:23 commit 0 last mr
Use file as output source .
step 1 create a file , For example, the file name is “output.txt”.
touch /home/omm/openGauss/output.txt
step 2 Execute the following command , In addition to the normal output source , Record all query output in a file .
gsql -d postgres -p 26000 -L /home/omm/openGauss/output.txt
Get into gsql Environmental Science , Enter the following statement :
postgres=# create table mytable (firstcol int);CREATE TABLEpostgres=# insert into mytable values(100);INSERT 0 1postgres=# select * from mytable ; firstcol ---------- 100(1 row)postgres=# \q
step 3 see “output.txt” The contents in the document are as follows :
cat /home/omm/openGauss/output.txt
It is shown as follows :
********* QUERY **********create table mytable (firstcol int);**************************CREATE TABLE********* QUERY **********insert into mytable values(100);**************************INSERT 0 1********* QUERY **********select * from mytable;************************** firstcol---------- 100(1 row)
Redirect all query output to a file FILENAME
step 1 create a file , For example, the file name is “outputOnly.txt”.
touch /home/omm/openGauss/outputOnly.txt
step 2 Execute the following command
gsql -d postgres -p 26000 -o /home/omm/openGauss/outputOnly.txt
step 3 Get into gsql Environmental Science , Enter the following statement :
postgres=# drop table mytable;postgres=# create table mytable (firstcol int);postgres=# insert into mytable values(100);postgres=# select * from mytable;postgres=# \q
All operations are not echoed .
step 4 see “outputOnly.txt” The contents in the document are as follows :
cat /home/omm/openGauss/outputOnly.txt
It is shown as follows :
DROP TABLECREATE TABLEINSERT 0 1 firstcol---------- 100(1 row)"/opt/software/openGauss/output.txt" 8L, 76C
Quiet mode
Quiet mode : No additional information will be printed during execution
gsql -d postgres -p 26000 -q
Get into gsql Environmental Science , Enter the following statement :
postgres=# create table t_test (firstcol int);postgres=# insert into t_test values(200);postgres=# select * from t_test; firstcol ---------- 200(1 row)postgres=# \q
Connect to the database , There is no echo information for creating database and inserting data .
Single line operation mode
Single line operation mode : At this time, each command will end with a newline character , Like a semicolon
gsql -d postgres -p 26000 -S
Get into gsql Environmental Science , Enter the following statement :
postgres^# select * from t_test; firstcol ---------- 200(1 row)postgres^# select * from t_test firstcol ---------- 200(1 row)postgres=# \q
There is ; No. and No ; Number , The effect is the same .
Edit mode
step 1 Connect to the database with the following command , Open the mode that can be edited in the client operation .
gsql -d postgres -p 26000 -r
step 2 Get into gsql Environmental Science , Enter the following statement :
step 3 Don't press enter after writing , The cursor flashes at the end .
step 4 Press “ towards the left ” Key to move the cursor to “*”, Change this symbol to “firstcol”.
Edit mode “ Up, down, left and right ”,“ Delete key ” and “ backspace ” You can use , And press “* Up ”、“ Down ” Key can switch the input command .
step 5 Exit database connection
postgres=# \q
Connect to the database remotely with user name and password
Remote use jack User connection ip The address is 192.168.0.58 The port number is 26000 The database of .
Log in to the client host (192.168.0.58), Use the following command to log in to the database remotely .
gsql -d postgres -h 192.168.0.58 -U jack -p 26000 -W [email protected];
-d Parameter specifies the target database name 、-U Parameter specifies the database user name 、-h Parameter specifies the hostname 、-p Parameter specifies port number information ,-W Parameter specifies the database user password .
Get into gsql Environmental Science , It is shown as follows :
gsql ((openGauss 1.0 build ec0e781b) compiled at 2020-04-27 17:25:57 commit 2144 last mr 131 )SSL connection (cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256)Type "help" for help.postgres=>
gsql Metacommand uses
Prerequisite
The following operations are openGauss Execute on the host where the database master node of ( Local connection database ), Use gsql Connect to openGauss database .
step 1 Switch to omm user , Operating system users omm Log in to the database master node .
su - omm
step 2gsql Connect to database .
gsql -d postgres -p 26000 -r
Print the current query buffer to standard output
step 1 establish “outputSQL.txt” file .
touch /home/omm/openGauss/outputSQL.txt
step 2 Connect to database .
gsql -d postgres -p 26000 -r
step 3 Enter the following statement .
postgres=# select * from pg_roles; rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcatupdate | rolcanlogin | rolreplication | rolauditadmin | rolsystemadmin | rolconnlimit | rolpassword | rolvalidbegin | rolvaliduntil | rolrespool | rolparentid | roltabspace | rolconfig | oid | roluseft | rolkind | nodegroup | roltempspace | rolspillspace ---------+----------+------------+---------------+-------------+--------------+-------------+----------------+---------------+----------------+--------------+-------------+---------------+---------------+--------------+-------------+-------------+-----------+-------+----------+---------+-----------+--------------+--------------- omm | t | t | t | t | t | t | t | t | t | -1 | ******** | | | default_pool | 0 | | | 10 | t | n | | | joe | f | t | f | f | f | t | f | f | f | -1 | ******** | | | default_pool | 0 | | | 17255 | f | n | | | (3 rows)postgres=# \w /home/omm/openGauss/outputSQL.txtpostgres=# \q
step 4 Open file “outputSQL.txt” file , See what's in it .
cat /home/omm/openGauss/outputSQL.txt
It is shown as follows :
select * from pg_roles;
Import data
step 1 Connect to database .
gsql -d postgres -p 26000 -r
step 2 Create the target table a.
postgres=# CREATE TABLE a(a int);
step 3 Import data , from stdin Copy data to the target table a.
postgres=# \copy a from stdin;
appear >> When the symbol prompts , input data , Input . End of time .
Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself. >> 1 >> 2 >> \.
step 4 Query the import target table a The data of .
postgres=# SELECT * FROM a; a --- 1 2
Exit database :
postgres=# \q
step 5 Copy data from local file to target table a, create a file /home/omm/openGauss/2.csv.
vi /home/omm/openGauss/2.csv
step 6 Input i, Switch to INSERT Pattern , Insert the data as follows :
345
- If there is more than one data , The separator is ‘,’.
- During the import process , If the data source file has more columns than the appearance definition , Ignore the extra columns at the end of the row
step 7 Press down Esc key , Input “:wq” Back carriage return , Save and exit .
step 8 Connect to database .
gsql -d postgres -p 26000 -r
step 9 The following command copies data to the target table .
postgres=# \copy a FROM '/home/omm//openGauss/2.csv' WITH (delimiter',',IGNORE_EXTRA_DATA 'on');
step 10 Query the import target table a The data of .
postgres=# SELECT * FROM a; a --- 1 2 345(5 rows)
Query tablespace
postgres=# \db
It is shown as follows :
postgres=> List of tablespaces Name | Owner | Location ------------+-------+---------- pg_default | omm | pg_global | omm | (2 rows)
Properties of query table .
step 1 Create table customer_t1.
postgres=# DROP TABLE IF EXISTS customer_t1;postgres=# CREATE TABLE customer_t1 ( c_customer_sk integer, c_customer_id char(5), c_first_name char(6), c_last_name char(8) );
step 2 Properties of query table .
postgres=# \d+;
It is shown as follows :
Schema | Name | Type | Owner | Size | Storage | Description --------+-------------+-------+-------+------------+----------------------------------+------------- public | customer_t1 | table | omm | 0 bytes | {orientation=row,compression=no} | public | mytable | table | omm | 8192 bytes | {orientation=row,compression=no} | public | t_test | table | omm | 8192 bytes | {orientation=row,compression=no} | public | ta | table | omm | 0 bytes | {orientation=row,compression=no} | (4 rows)
step 3 Query table customer_t1 Properties of .
postgres=# \d+ customer_t1;
It is shown as follows :
Table "public.customer_t1" Column | Type | Modifiers | Storage | Stats target | Description ---------------+--------------+-----------+----------+--------------+------------- c_customer_sk | integer | | plain | | c_customer_id | character(5) | | extended | | c_first_name | character(6) | | extended | | c_last_name | character(8) | | extended | | Has OIDs: noOptions: orientation=row, compression=no
Query index information
step 1 In the table customer_t1 Create index on .
create index customer_t1_index1 on customer_t1(c_customer_id);
step 2 Query index information .
postgres=# \di+;
postgres=# \di+;
It is shown as follows :
List of relations Schema | Name | Type | Owner | Table | Size | Storage | Description --------+--------------------+-------+-------+-------------+------------+---------+------------- public | customer_t1_index1 | index | omm | customer_t1 | 8192 bytes | |
step 3 Inquire about customer_t1_index1 Index information .
postgres=# \di+ customer_t1_index1
It is shown as follows :
List of relations Schema | Name | Type | Owner | Table | Size | Storage | Description --------+--------------------+-------+-------+-------------+------------+---------+------------- public | customer_t1_index1 | index | omm | customer_t1 | 8192 bytes | |
Switch database
step 1 Create database .
DROP DATABASE IF EXISTS db_tpcc02;CREATE DATABASE db_tpcc02;
step 2 Switch database .
postgres=# \c db_tpcc02;
It is shown as follows :
Non-SSL connection (SSL connection is recommended when requiring high-security)You are now connected to database "db_tpcc" as user "omm".db_tpcc=#
step 3 Exit database :
postgres=# \q
边栏推荐
- [principles of multithreading and high concurrency: 1_cpu multi-level cache model]
- What does "where 1=1" mean
- [leectode 2022.2.15] lucky numbers in the matrix
- Practice of traffic recording and playback in vivo
- Kubernetes family container housekeeper pod online Q & A?
- 内存泄漏工具VLD安装及使用
- [translation] flux is safe. Gain more confidence through fuzzy processing
- Installation and use of memory leak tool VLD
- 用docker 连接mysql的过程
- sql server 查询指定表的表结构
猜你喜欢
Linear rectification function relu and its variants in deep learning activation function
Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
SqlServer行转列PIVOT
Installation and use of memory leak tool VLD
Mathematical statistics -- Sampling and sampling distribution
random shuffle注意
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
Build a private cloud disk cloudrev
The process of connecting MySQL with docker
【Flutter】shared_ Preferences local storage (introduction | install the shared_preferences plug-in | use the shared_preferences process)
随机推荐
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Process the dataset and use labelencoder to convert all IDs to start from 0
左连接,内连接
二维格式数组格式索引下标连续问题导致 返回json 格式问题
Introduction to cron expression
Informatics Olympiad one general question bank 1006 a+b questions
Principle and application of database
疫情当头,作为Leader如何进行代码版本和需求开发管控?| 社区征文
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)
Your family must be very poor if you fight like this!
What is the way out for children from poor families?
你真的懂继电器吗?
Kubernetes cluster log and efk architecture log scheme
The left value and the right finger explain better
MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
random shuffle注意
[translation] flux is safe. Gain more confidence through fuzzy processing
Global and Chinese ammonium dimolybdate market in-depth analysis and prospect risk prediction report 2022 Edition
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]