forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Wang , Deng Ke <wangdengke2@huawei.com> Co-committed-by: Wang , Deng Ke <wangdengke2@huawei.com>
88 lines
18 KiB
HTML
88 lines
18 KiB
HTML
<a name="opengauss_01_0030"></a><a name="opengauss_01_0030"></a>
|
|
|
|
<h1 class="topictitle1">Step 4: Connect to a DB Instance Through gsql</h1>
|
|
<div id="body8662426"><p id="opengauss_01_0030__a88aae95ae57b4e3dbf758728642a5683">gsql is a database command-line connection tool provided by <span id="opengauss_01_0030__t6ee16d77b2f245a190a5b47527d873fd">GaussDB(openGauss)</span>.</p>
|
|
<div class="notice" id="opengauss_01_0030__n5e62652398fa49448284a3c26f6df6ba"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="opengauss_01_0030__en-us_topic_0241495508_p18938595234">Currently, the gsql tool supports only the Euler OS.</p>
|
|
</div></div>
|
|
<div class="section" id="opengauss_01_0030__s578d3fd66b9a4d8f8efbb6fe5b638f28"><h4 class="sectiontitle">Preparations</h4><p id="opengauss_01_0030__a191c757a8fd54381ba97ff0cb28e3508">To connect to a <span id="opengauss_01_0030__tfd3a45420d3c4ee785530bf021f248bb">GaussDB(openGauss)</span> DB instance through an ECS, you must first create an ECS running Euler OS. For details, see the <em id="opengauss_01_0030__i1494412238241">Elastic Cloud Server User Guide</em>.</p>
|
|
</div>
|
|
<div class="section" id="opengauss_01_0030__sf044c91aa505487ab55a4adedec3c11e"><h4 class="sectiontitle">Remotely Connecting to the Database</h4><ol id="opengauss_01_0030__o504e2397ac4043c28d0c04cf1eb07040"><li id="opengauss_01_0030__lf889978fe706429a963e4e7f936519df"><span>Log in to the ECS.</span></li><li id="opengauss_01_0030__l53c7d80cd85840eda3a18a7f57dd1563"><span>Upload the client tool package and configure gsql environment variables.</span><p><ol type="a" id="opengauss_01_0030__o662296a2ae584636905cf0f8350f17e4"><li id="opengauss_01_0030__l69b4079aca714d1d842a6cb722fb2461">Log in to the client as user <strong id="opengauss_01_0030__a98726f41a3dd4df595fd2aabe0906216">root</strong>.</li><li id="opengauss_01_0030__l73b4daa998e5414dbfcee1a34c6a7d81">Create the <strong id="opengauss_01_0030__acf27c11ab0c24a108700c30f7999f0a2">/tmp/tools</strong> directory.<pre class="screen" id="opengauss_01_0030__s9c2cb0dd01be4fcdab25ebff73a63b90"><strong id="opengauss_01_0030__ab1e59d50ed264d4d82a9c4a0a1a0f39a">mkdir </strong><em id="opengauss_01_0030__en-us_topic_0241495508_i162441922161">/tmp/tools</em></pre>
|
|
</li><li id="opengauss_01_0030__l6df5b7a0611645e5932e537a81baf421">Click <a href="https://dbs-download.obs.otc.t-systems.com/rds/GaussDB_opengauss_client_tools.zip" target="_blank" rel="noopener noreferrer">here</a> to obtain the <span id="opengauss_01_0030__tf9e0a3b763b242a4a3f3fc8e8c4c09b0">GaussDB(openGauss)</span> software package. Go to the corresponding directory based on the ECS OS architecture, obtain <strong id="opengauss_01_0030__a3ff697e983ec42a5ad1e999fa16c9597">GaussDB-Kernel</strong>-<em id="opengauss_01_0030__a3de74bb31ad94bb4bb2a4d54f027b412">xxx</em><strong id="opengauss_01_0030__a01643c89099541ecaccdd25acf4bf48b">-EULER-64bit-gsql.tar.gz</strong>, and upload it to the <strong id="opengauss_01_0030__en-us_topic_0241495508_b281514417365">/tmp/tools</strong> directory.<div class="note" id="opengauss_01_0030__nb266296237ff479b910c4c3997d4d58f"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="opengauss_01_0030__aa819a1e354b54681b748bbc15e140468">The software package is located where you put it before installation.</p>
|
|
</div></div>
|
|
</li><li id="opengauss_01_0030__l1033b6ed1dde48cc9630c0e4571e6269">Decompress the package.<pre class="screen" id="opengauss_01_0030__sc679cea4fd4b48aa96f83cd870a74cde"><strong id="opengauss_01_0030__aeebbeb8269324c19a8a22ba0d4b7dc01">cd </strong><em id="opengauss_01_0030__a2a70ea1feec54ea1a52032222c81bca3">/tmp/tools</em>
|
|
<strong id="opengauss_01_0030__a0e2924a274a445ba889c45ef1a20dda4">tar -zxvf </strong>GaussDB-Kernel-V500R001C00-EULER-64bit-gsql.tar.gz</pre>
|
|
</li><li id="opengauss_01_0030__l5d510a9ea6754c85b66e65f4c87c431a">Set environment variables.<p id="opengauss_01_0030__aac5ce025c699457ab48f77def316d6df"><a name="opengauss_01_0030__l5d510a9ea6754c85b66e65f4c87c431a"></a><a name="l5d510a9ea6754c85b66e65f4c87c431a"></a>Open the <strong id="opengauss_01_0030__af3c36e03512149a2a4e7549669fd913e">~/.bashrc</strong> file.</p>
|
|
<pre class="screen" id="opengauss_01_0030__s041aab31f5524d65899f4b137ae45ec7"><strong id="opengauss_01_0030__a7dc0a02c374c433bb0f7d16499a9c969">vi ~/.bashrc</strong></pre>
|
|
<p id="opengauss_01_0030__adc14d61d9b644aac92000acc8c56d340">Enter the following content and run the <strong id="opengauss_01_0030__a91ddc5959d594e1691f639bc936d15f3">:wq!</strong> command to save and then exit.</p>
|
|
<pre class="screen" id="opengauss_01_0030__s7fd3f8969c6743c4a64ad710cdc0d1d0"><strong id="opengauss_01_0030__a1486ba6735f4473d845383087b49dae8">export PATH=</strong><em id="opengauss_01_0030__a738fbee852b9455daf218f5a555ff310">/tmp/tools</em>/<strong id="opengauss_01_0030__a63b4bef069b2493d89dfcb24a9f00075">bin:$PATH</strong></pre>
|
|
<pre class="screen" id="opengauss_01_0030__s5ed0dbe4130948d788b18d29a7a4b7f0"><strong id="opengauss_01_0030__a63fc8f92fb794ee580c7b37d700a69b6">export LD_LIBRARY_PATH=</strong><em id="opengauss_01_0030__ad835eee4852c46d7bafc594600d18855">/tmp/tools/</em><strong id="opengauss_01_0030__en-us_topic_0241495508_b74026217167">lib:$LD_LIBRARY_PATH</strong></pre>
|
|
<div class="p" id="opengauss_01_0030__a96f91f1683ab4e78a390a3f2f3cc9119">Make the environment variables take effect.<pre class="screen" id="opengauss_01_0030__sa41bfd0a68164231a81d3a930207aa48"><strong id="opengauss_01_0030__en-us_topic_0241495508_b241727161614">source ~/.bashrc</strong></pre>
|
|
</div>
|
|
</li></ol>
|
|
</p></li><li id="opengauss_01_0030__lf29fb77e9c294e9c93d8735eac199153"><span>Run the following command and enter the password as prompted to connect to the database.</span><p><p id="opengauss_01_0030__aa6a69c17deed4487acf5208629e88df0">After the database is installed, a database named <strong id="opengauss_01_0030__a1dca51a218da4b3a98f160dc6386981b">postgres</strong> is generated by default.</p>
|
|
<pre class="screen" id="opengauss_01_0030__s1e2f814d1be541d69ec7fef6920a7c7c"><strong id="opengauss_01_0030__b1645341773510">gsql</strong> <strong id="opengauss_01_0030__b1939342013355">-d</strong> <em id="opengauss_01_0030__i1452119237358">postgres</em> <strong id="opengauss_01_0030__b197142718351">-h</strong> <em id="opengauss_01_0030__i761053016355">10.0.0.0</em> <strong id="opengauss_01_0030__b385311353517">-U</strong><em id="opengauss_01_0030__i08531913113516"> jack</em> <strong id="opengauss_01_0030__b1185318136353">-p</strong> <em id="opengauss_01_0030__i5853161393515">8000</em>
|
|
Password for user jack:</pre>
|
|
<p id="opengauss_01_0030__aa06aa6c633bc4e1ca5bd1aa48ed3617b"><strong id="opengauss_01_0030__a84610a4683e24432a9fb4ee1eda242ff">postgres</strong> is the name of the database to be connected; <strong id="opengauss_01_0030__en-us_topic_0241495508_b665112585317">10.0.0.0</strong> is the EIP bound to the DB instance; <strong id="opengauss_01_0030__a08a53b9dfaa34cdb8c2a622bf9402df5">jack</strong> is the username for logging in to the database; <strong id="opengauss_01_0030__a70e0e19f5c5a4363919a8224f91c867e">8000</strong> is the port number of the DB instance.</p>
|
|
<div class="note" id="opengauss_01_0030__ndecc34f047b84e6cace194d81ed15284"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="opengauss_01_0030__ue3215069e9824969b78a3f25b5cf3a58"><li id="opengauss_01_0030__l80212b94d2b447759e21bd5696a643a7">In the preceding example, user <strong id="opengauss_01_0030__ab531711383c8495aa6b8c0638c29b151">jack</strong> is a common user created for database initialization.</li><li id="opengauss_01_0030__laeb8a9c2653d4c06aabba9d53207175c">The initialized user cannot be used for remote connection.</li></ul>
|
|
</div></div>
|
|
</p></li></ol>
|
|
</div>
|
|
<div class="section" id="opengauss_01_0030__s5fc4b0c34a0c4a80b8a7a0ef90bbd10d"><h4 class="sectiontitle"><strong id="opengauss_01_0030__a1eda7c169a7b4ffda032577d7a554cd7"><span class="keyword" id="opengauss_01_0030__keyword182851565306">SSL Connection</span></strong></h4><ol id="opengauss_01_0030__o9c4f8b82b96e439ea56ccb3808195e61"><li id="opengauss_01_0030__l65e57bf5cf2347a8bcdbf91584e31bfb"><span>Log in to the management console.</span></li><li id="opengauss_01_0030__en-us_topic_0241495508_li42514315519"><span>Click <span><img id="opengauss_01_0030__id354dc78dd024ceba50e54b18087b222" src="en-us_image_0000001072358973.png"></span> in the upper left corner and select a region and a project.</span></li><li id="opengauss_01_0030__li8993164052218"><span>Click <strong id="opengauss_01_0030__afab9a51872a0475eac5831778f04beda">Service List</strong>. Under <strong id="opengauss_01_0030__en-us_topic_0241495502_b155592161758">Database</strong>, click <strong id="opengauss_01_0030__en-us_topic_0241495502_b056012161059">GaussDB</strong>.</span></li><li id="opengauss_01_0030__lb7a94adb746945549de0480d03e6919d"><span>In the navigation pane on the left, choose <strong id="opengauss_01_0030__aac73ac6a5277470ca896f424ceddcc09">GaussDB(openGauss)</strong> > <strong id="opengauss_01_0030__a8989b0cbeb2940689376ccc2b84bc056">Instance Management</strong>.</span></li><li id="opengauss_01_0030__l0b5c844cc50f4e78abc74087e933c5e2"><span>In the <span class="uicontrol" id="opengauss_01_0030__u1fab4a9e484f4559949b59c81b65569f"><b>DB Information</b></span> area on the <strong id="opengauss_01_0030__a4709d08fea774885920ece16584ac66d">Basic Information</strong> page, click <span><img id="opengauss_01_0030__i4be8a55f1cd14b61bfec6fd032ae225d" src="en-us_image_0000001072790870.png"></span> in the <strong id="opengauss_01_0030__a9721ae3cdb5b4a0ea2cef55d836c285a">SSL</strong> field to download the root certificate or certificate bundle.</span></li><li id="opengauss_01_0030__lbc31529e315149a689a178515eafaf4f"><span>Upload the root certificate to the ECS or save it to the device to be connected to the <span id="opengauss_01_0030__t4fc39f1a0d81411ba351549e7d3b7b7f">GaussDB(openGauss)</span> DB instance.</span><p><p id="opengauss_01_0030__p123399553444">Import the root certificate to the Linux OS on the ECS. </p>
|
|
</p></li><li id="opengauss_01_0030__l7ae5bd142d5a4229a00d377374ded4d1"><span>Connect to a DB instance. The Linux OS is used as an example.</span><p><pre class="screen" id="opengauss_01_0030__se3f86874b2bc497599b47eb923712697">export PGSSLMODE=<sslmode>
|
|
export PGSSLROOTCERT=<em id="opengauss_01_0030__a383730a2fb5342388964fd4a5e845044"><ca-file-directory></em></pre>
|
|
<p id="opengauss_01_0030__en-us_topic_0241495508_p955522714389"><strong id="opengauss_01_0030__a77b62936cb5040e58533b825d93a5264">gsql -h </strong><em id="opengauss_01_0030__ac543290d187542da91ceab1fa3258bb7"><host></em> <strong id="opengauss_01_0030__a27dc4bd2e48e410a99d3c90117b6cbe7">-p</strong> <em id="opengauss_01_0030__en-us_topic_0241495508_i295722394011"><port></em> <strong id="opengauss_01_0030__a63857ab9dd304aa6918a6c69be040d6d">-d</strong><em id="opengauss_01_0030__a0aa1a0e6a94141f789f2bbc7319d2e69"> <database></em> <em id="opengauss_01_0030__a9f496dba309c4bc0adb9f010fca96f31"><strong id="opengauss_01_0030__a4842469aaedf4ae4aa7e4aa26ad17786">-U</strong> <strong id="opengauss_01_0030__a67f950fbf6424dbbb0a73c9753d3fcb1"><user> -W</strong> <password></em></p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="opengauss_01_0030__tc40ca1cff0e64e21a27259e1a02c76ea" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="opengauss_01_0030__rdc8baa2ea95f476d99652cf342b539ea"><th align="left" class="cellrowborder" valign="top" width="20.44%" id="mcps1.3.5.2.7.2.3.2.3.1.1"><p id="opengauss_01_0030__ad864aea46b4e4f38b3131913e41d52b4"><strong id="opengauss_01_0030__en-us_topic_0241495508_b331744819578">Parameter</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="79.56%" id="mcps1.3.5.2.7.2.3.2.3.1.2"><p id="opengauss_01_0030__a0107bc1aa31746beb53734548cb339ed"><strong id="opengauss_01_0030__en-us_topic_0241495508_b28859484577">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="opengauss_01_0030__r2ebad2d92d8849cfab85b7edebcd1d40"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0030__aedd83b9409f04c8780281ccf17047e8f"><em id="opengauss_01_0030__aa20a9b2b2c7f441da08d0884b3206849"><host></em></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.56%" headers="mcps1.3.5.2.7.2.3.2.3.1.2 "><p id="opengauss_01_0030__a12e3c80c80054b9dafa5ea998f6115db">IP address of the DB instance. To obtain this parameter, go to the <span class="uicontrol" id="opengauss_01_0030__u7cd5b45260674d24b35c1ea3a964ac4f"><b>Basic Information</b></span> page of the DB instance. If the DB instance is accessed through the ECS, the IP address can be found in the <span class="uicontrol" id="opengauss_01_0030__ucd2f40cb151442219a9191f4b7e44ef3"><b>Floating IP Address</b></span> field in the <strong id="opengauss_01_0030__a9f4929a05950432cbdcf15eed6c07d73">Connection Information</strong> area.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0030__r393c3517e6854838806ae023cf2213e8"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0030__a77fc48733d444e19831cc9a83f87ecd7"><em id="opengauss_01_0030__en-us_topic_0241495508_i149573233405"><port></em></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.56%" headers="mcps1.3.5.2.7.2.3.2.3.1.2 "><p id="opengauss_01_0030__acfd08a43d791422d9f93461571aef21f">Database port in use. The default value is <strong id="opengauss_01_0030__en-us_topic_0241495508_b265814824516">8000</strong>. To obtain this parameter, go to the <span class="uicontrol" id="opengauss_01_0030__u3081b75f502a4fcb8945f4137eb20082"><b>Basic Information</b></span> page of the DB instance. The port number can be found in the <span class="uicontrol" id="opengauss_01_0030__ua766ee276483444890ba1a18a9692921"><b>Database Port</b></span> field in the <span class="uicontrol" id="opengauss_01_0030__u58ed42c8cb5a493b9fd82a8458293b01"><b>Connection Information</b></span> area.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0030__rf3721c06f748437090050e48905fdfba"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0030__en-us_topic_0241495508_p169572236402"><em id="opengauss_01_0030__en-us_topic_0241495508_i295782334015"><database></em></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.56%" headers="mcps1.3.5.2.7.2.3.2.3.1.2 "><p id="opengauss_01_0030__a84fba19adfe1435c827e858deec30ad6">Name of the database (<strong id="opengauss_01_0030__ab4e4987c81714a7a8c83013a057f0940">postgres</strong> by default).</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0030__r386fad53d5c34217bbf0a4772ddc4828"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0030__en-us_topic_0241495508_p695832315402"><em id="opengauss_01_0030__a0f30412dc385471d921197ae833f25e6"><user></em></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.56%" headers="mcps1.3.5.2.7.2.3.2.3.1.2 "><p id="opengauss_01_0030__en-us_topic_0241495508_p195862311406">Username of the database account. The default administrator is <strong id="opengauss_01_0030__a26b1d926c7254b839832aee61729caf2">root</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0030__r07866275eb354c17ac93f8406076e74e"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0030__addd5e90a59494a8998fee9fe599c687d"><em id="opengauss_01_0030__aed5c840bbd0d4a7480354265af0e1315"><ca-file-directory></em></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.56%" headers="mcps1.3.5.2.7.2.3.2.3.1.2 "><p id="opengauss_01_0030__a06a88d3ddf704721ac4a6657c9926480">Directory of the CA certificate for the SSL connection. The certificate should be stored in the directory where the command is executed.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0030__r27994ef10b5e480b99fa6e13db025341"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0030__en-us_topic_0241495508_p159589230402"><sslmode></p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.56%" headers="mcps1.3.5.2.7.2.3.2.3.1.2 "><p id="opengauss_01_0030__en-us_topic_0241495508_p119583234400">SSL connection mode. Set it to <strong id="opengauss_01_0030__a18e0472d311b4d7d8aff0f9141378a94">verify-ca</strong> to use a CA to check whether the service is trusted.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="opengauss_01_0030__acf8c4094b38a4bdeaacdb99c5075aad0">For example, to connect to a DB instance through an SSL connection as user <strong id="opengauss_01_0030__ae2f84f3b106a4b189f24196223068fee">root</strong>, run the following command:</p>
|
|
<pre class="screen" id="opengauss_01_0030__s9ec4f40611474e4891a829615e47100d">export PGSSLMODE="verify-ca"
|
|
export PGSSLROOTCERT="/home/Ruby/ca.pem"</pre>
|
|
<p id="opengauss_01_0030__a0189ca21442243a9b4cd32e1f649a40b"><strong id="opengauss_01_0030__a96ca8abfa02e4d0c85d2854c97e09232">gsql -d postgres -h 10.10.0.11 <em id="opengauss_01_0030__a4f0e5cdafc774e09bee2025f1965c4d5"> -U jack</em> -p <em id="opengauss_01_0030__a78c5c6b9e7e846b1987200e6f0968490">8000</em> <em id="opengauss_01_0030__en-us_topic_0241495508_i199581237403">-W Test@123</em></strong></p>
|
|
</p></li><li id="opengauss_01_0030__ld86f03c22c1348049b609762d6f382f6"><span>The SSL connection is established if information similar to the following is displayed after you log in to the database:</span><p><pre class="screen" id="opengauss_01_0030__sd59e08ed237842898d2490967c0f2219">SSL connection (cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256)</pre>
|
|
</p></li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="opengauss_01_0025.html">Connecting to a DB Instance Over a Public Network</a></div>
|
|
</div>
|
|
</div>
|
|
|