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
15 KiB
HTML
88 lines
15 KiB
HTML
<a name="opengauss_01_0024"></a><a name="opengauss_01_0024"></a>
|
|
|
|
<h1 class="topictitle1">Step 3: Connect to a DB Instance Through gsql</h1>
|
|
<div id="body8662426"><p id="opengauss_01_0024__p187381851121615">gsql is a database command-line connection tool provided by <span id="opengauss_01_0024__text974061111714">GaussDB(openGauss)</span>.</p>
|
|
<div class="notice" id="opengauss_01_0024__note138931859192312"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="opengauss_01_0024__p18938595234">Currently, the gsql tool supports only the Euler OS.</p>
|
|
</div></div>
|
|
<div class="section" id="opengauss_01_0024__s7b0af386b5d94405afa47f59b3af4266"><h4 class="sectiontitle">Preparations</h4><p id="opengauss_01_0024__p5306143618161">To connect to a <span id="opengauss_01_0024__text2099244864">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_0024__i1494412238241">Elastic Cloud Server User Guide</em>.</p>
|
|
</div>
|
|
<div class="section" id="opengauss_01_0024__section1427142520137"><h4 class="sectiontitle">Remotely Connecting to the Database</h4><ol id="opengauss_01_0024__ol1567322561314"><li id="opengauss_01_0024__li13204149191411"><span>Log in to the ECS.</span></li><li id="opengauss_01_0024__li1667313257133"><span>Upload the client tool package and configure gsql environment variables.</span><p><ol type="a" id="opengauss_01_0024__ol46731225131312"><li id="opengauss_01_0024__li1667342591320">Log in to the client as user <strong id="opengauss_01_0024__b1497216366494">root</strong>.</li><li id="opengauss_01_0024__li26731825171315">Create the <strong id="opengauss_01_0024__b97581346144915">/tmp/tools</strong> directory.<pre class="screen" id="opengauss_01_0024__screen6242132141615"><strong id="opengauss_01_0024__b1324420215164">mkdir </strong><em id="opengauss_01_0024__i162441922161">/tmp/tools</em></pre>
|
|
</li><li id="opengauss_01_0024__li280361019585">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_0024__text4803810105814">GaussDB(openGauss)</span> software package. Go to the corresponding directory based on the ECS OS architecture, obtain <strong id="opengauss_01_0024__b39021942143518">GaussDB-Kernel</strong>-<em id="opengauss_01_0024__i0794154783519">xxx</em><strong id="opengauss_01_0024__b14764115403510">-EULER-64bit-gsql.tar.gz</strong>, and upload it to the <strong id="opengauss_01_0024__b281514417365">/tmp/tools</strong> directory.<div class="note" id="opengauss_01_0024__note134333255136"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="opengauss_01_0024__p2385145418255">The software package is located where you put it before installation.</p>
|
|
</div></div>
|
|
</li><li id="opengauss_01_0024__li1567342551311">Decompress the package.<pre class="screen" id="opengauss_01_0024__screen6366899166"><strong id="opengauss_01_0024__b1537810911610">cd </strong><em id="opengauss_01_0024__i19378119141619">/tmp/tools</em>
|
|
<strong id="opengauss_01_0024__b16378119141615">tar -zxvf </strong>GaussDB-Kernel-V500R001C00-EULER-64bit-gsql.tar.gz</pre>
|
|
</li><li id="opengauss_01_0024__li16731825181311">Set environment variables.<p id="opengauss_01_0024__p66731125161315"><a name="opengauss_01_0024__li16731825181311"></a><a name="li16731825181311"></a>Open the <strong id="opengauss_01_0024__b12794183215119">~/.bashrc</strong> file.</p>
|
|
<pre class="screen" id="opengauss_01_0024__screen180311651613"><strong id="opengauss_01_0024__b5816141614164">vi ~/.bashrc</strong></pre>
|
|
<p id="opengauss_01_0024__p9673825181310">Enter the following content and run the <strong id="opengauss_01_0024__b3147445175114">:wq!</strong> command to save and then exit.</p>
|
|
<pre class="screen" id="opengauss_01_0024__screen64490126397"><strong id="opengauss_01_0024__b144021121201613">export PATH=</strong><em id="opengauss_01_0024__i7402112114162">/tmp/tools</em>/<strong id="opengauss_01_0024__b1440212216162">bin:$PATH</strong></pre>
|
|
<pre class="screen" id="opengauss_01_0024__screen039916210163"><strong id="opengauss_01_0024__b1040212215162">export LD_LIBRARY_PATH=</strong><em id="opengauss_01_0024__i04021621101616">/tmp/tools/</em><strong id="opengauss_01_0024__b74026217167">lib:$LD_LIBRARY_PATH</strong></pre>
|
|
<div class="p" id="opengauss_01_0024__p9348143613119">Make the environment variables take effect.<pre class="screen" id="opengauss_01_0024__screen104072717160"><strong id="opengauss_01_0024__b241727161614">source ~/.bashrc</strong></pre>
|
|
</div>
|
|
</li></ol>
|
|
</p></li><li id="opengauss_01_0024__li6673725101318"><span>Eenter the password as prompted to connect to the database.</span><p><p id="opengauss_01_0024__p11673172512138">After the database is installed, a database named <strong id="opengauss_01_0024__b9487126155212">postgres</strong> is generated by default.</p>
|
|
<pre class="screen" id="opengauss_01_0024__screen9673172541314"><strong id="opengauss_01_0024__b1645341773510">gsql</strong> <strong id="opengauss_01_0024__b1939342013355">-d</strong> <em id="opengauss_01_0024__i1452119237358">postgres</em> <strong id="opengauss_01_0024__b197142718351">-h</strong> <em id="opengauss_01_0024__i761053016355">10.0.0.0</em> <strong id="opengauss_01_0024__b385311353517">-U</strong><em id="opengauss_01_0024__i08531913113516"> jack</em> <strong id="opengauss_01_0024__b1185318136353">-p</strong> <em id="opengauss_01_0024__i5853161393515">8000</em>
|
|
Password for user jack:</pre>
|
|
<p id="opengauss_01_0024__p16673725161312"><strong id="opengauss_01_0024__b6173358135217">postgres</strong> is the name of the database to be connected; <strong id="opengauss_01_0024__b665112585317">10.0.0.0</strong> is the IP address of the server where the CN resides; <strong id="opengauss_01_0024__b1488717144530">jack</strong> is the username for logging in to the database; <strong id="opengauss_01_0024__b164321623135318">8000</strong> is the port number of the CN.</p>
|
|
<div class="note" id="opengauss_01_0024__note7434162581320"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="opengauss_01_0024__ul9673152512135"><li id="opengauss_01_0024__li96731725161320">In the preceding example, user <strong id="opengauss_01_0024__b1916124711363">jack</strong> is a common user created for database initialization.</li><li id="opengauss_01_0024__li467352511137">The initialized user cannot be used for remote connection.</li></ul>
|
|
</div></div>
|
|
</p></li></ol>
|
|
</div>
|
|
<div class="section" id="opengauss_01_0024__section251948884"><h4 class="sectiontitle"><strong id="opengauss_01_0024__a2e7dd90592a5461db0261be6c598b940"><span class="keyword" id="opengauss_01_0024__keyword182851565306">SSL Connection</span></strong></h4><ol id="opengauss_01_0024__oe949fbf25aff40c1ad987a049746f625"><li id="opengauss_01_0024__li17251143135117"><span>Log in to the management console.</span></li><li id="opengauss_01_0024__li42514315519"><span>Click <span><img id="opengauss_01_0024__i1c51f843842a4aee83d6b24bd3870a53" src="en-us_image_0000001072133021.png"></span> in the upper left corner and select a region and a project.</span></li><li id="opengauss_01_0024__li8993164052218"><span>Click <strong id="opengauss_01_0024__afab9a51872a0475eac5831778f04beda">Service List</strong>. Under <strong id="opengauss_01_0024__en-us_topic_0241495502_b155592161758">Database</strong>, click <strong id="opengauss_01_0024__en-us_topic_0241495502_b056012161059">GaussDB</strong>.</span></li><li id="opengauss_01_0024__lb7a94adb746945549de0480d03e6919d"><span>In the navigation pane on the left, choose <strong id="opengauss_01_0024__aac73ac6a5277470ca896f424ceddcc09">GaussDB(openGauss)</strong> > <strong id="opengauss_01_0024__a8989b0cbeb2940689376ccc2b84bc056">Instance Management</strong>.</span></li><li id="opengauss_01_0024__l322c3bcd0cc14ab28e1f842ca865d487"><span>In the <span class="uicontrol" id="opengauss_01_0024__uicontrol573017864212"><b>DB Information</b></span> area on the <strong id="opengauss_01_0024__b4731188154217">Basic Information</strong> page, click <span><img id="opengauss_01_0024__image197254186415" src="en-us_image_0000001072133027.png"></span> in the <strong id="opengauss_01_0024__b1473338154218">SSL</strong> field to download the root certificate or certificate bundle.</span></li><li id="opengauss_01_0024__lfea66b0cbae8423fb43ae6adfa8804dd"><span>Upload the root certificate to the ECS or save it to the device to be connected to the <span id="opengauss_01_0024__text10106357104218">GaussDB(openGauss)</span> DB instance.</span><p><p id="opengauss_01_0024__p123399553444">Import the root certificate to the Linux OS on the ECS. </p>
|
|
</p></li><li id="opengauss_01_0024__l9181e1cf94d242afa93a2f4eb25f9311"><span>Connect to a DB instance. The Linux OS is used as an example.</span><p><pre class="screen" id="opengauss_01_0024__screen1444092013425">export PGSSLMODE=<sslmode>
|
|
export PGSSLROOTCERT=<em id="opengauss_01_0024__i104452020104213"><ca-file-directory></em></pre>
|
|
<p id="opengauss_01_0024__p955522714389"><strong id="opengauss_01_0024__b29571223104015">gsql -h </strong><em id="opengauss_01_0024__i17957142344011"><host></em> <strong id="opengauss_01_0024__b16957182314019">-p</strong> <em id="opengauss_01_0024__i295722394011"><port></em> <strong id="opengauss_01_0024__b99571123124014">-d</strong><em id="opengauss_01_0024__i1595712317404"> <database></em> <em id="opengauss_01_0024__i1895732313406"><strong id="opengauss_01_0024__b59571123154016">-U</strong> <strong id="opengauss_01_0024__b4957423144016"><user> -W</strong> <password></em></p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="opengauss_01_0024__table12958112315409" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="opengauss_01_0024__row149573234405"><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_0024__p15957623194016"><strong id="opengauss_01_0024__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_0024__p189571623164011"><strong id="opengauss_01_0024__b28859484577">Description</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="opengauss_01_0024__row1195714233407"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0024__p179571723184015"><em id="opengauss_01_0024__i209571423174015"><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_0024__p7957132344011">IP address of the DB instance. To obtain this parameter, go to the <span class="uicontrol" id="opengauss_01_0024__uicontrol8655174815320"><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_0024__uicontrol836685711406"><b>Floating IP Address</b></span> field in the <strong id="opengauss_01_0024__b1036711571401">Connection Information</strong> area.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0024__row99572237409"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0024__p69571923144015"><em id="opengauss_01_0024__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_0024__p7957142314406">Database port in use. The default value is <strong id="opengauss_01_0024__b265814824516">8000</strong>. To obtain this parameter, go to the <span class="uicontrol" id="opengauss_01_0024__uicontrol8659548144517"><b>Basic Information</b></span> page of the DB instance. The port number can be found in the <span class="uicontrol" id="opengauss_01_0024__uicontrol36591848104517"><b>Database Port</b></span> field in the <span class="uicontrol" id="opengauss_01_0024__uicontrol14660174834513"><b>Connection Information</b></span> area.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0024__row189580230407"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0024__p169572236402"><em id="opengauss_01_0024__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_0024__p14958162344016">Name of the database (<strong id="opengauss_01_0024__b17860154145520">postgres</strong> by default).</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0024__row2958102319408"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0024__p695832315402"><em id="opengauss_01_0024__i49581623104015"><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_0024__p195862311406">Username of the database account. The default administrator is <strong id="opengauss_01_0024__b1816174416556">root</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="opengauss_01_0024__row89581923174019"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0024__p5958723124011"><em id="opengauss_01_0024__i12958423114010"><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_0024__p7958223134010">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_0024__row5958172320409"><td class="cellrowborder" valign="top" width="20.44%" headers="mcps1.3.5.2.7.2.3.2.3.1.1 "><p id="opengauss_01_0024__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_0024__p119583234400">SSL connection mode. Set it to <strong id="opengauss_01_0024__b18802144914552">verify-ca</strong> to use a CA to check whether the service is trusted.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="opengauss_01_0024__p1295814234402">For example, to connect to a DB instance through an SSL connection as user <strong id="opengauss_01_0024__a04865b35f681444aa5ebbbcaf26b4ea7">root</strong>, run the following command:</p>
|
|
<pre class="screen" id="opengauss_01_0024__screen7917526114219">export PGSSLMODE="verify-ca"
|
|
export PGSSLROOTCERT="/home/Ruby/ca.pem"</pre>
|
|
<p id="opengauss_01_0024__p13958102364013"><strong id="opengauss_01_0024__b5958192304014">gsql -d postgres -h 10.10.0.11 <em id="opengauss_01_0024__i1195892374012"> -U jack</em> -p <em id="opengauss_01_0024__i2958223134014">8000</em> <em id="opengauss_01_0024__i199581237403">-W Test@123</em></strong></p>
|
|
</p></li><li id="opengauss_01_0024__l8a49eb9117de47e2a5c00711a7369720"><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_0024__sc2c86d87346640af8c88520b4b2d8dba">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_0020.html">Connecting to a DB Instance Over a Private Network</a></div>
|
|
</div>
|
|
</div>
|
|
|