doc-exports/docs/dws/umn/dws_01_0037.html
Lu, Huayi c5fcb46315 DWS UMN 801 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2022-12-13 12:47:57 +00:00

67 lines
16 KiB
HTML

<a name="EN-US_TOPIC_0000001180320141"></a><a name="EN-US_TOPIC_0000001180320141"></a>
<h1 class="topictitle1">Using the gsql Client to Connect to a Cluster</h1>
<div id="body1491553271744"><p id="EN-US_TOPIC_0000001180320141__p1699416016201">This section describes how to connect to a database through an SQL client after you create a data warehouse cluster and before you use the cluster's database. GaussDB(DWS) provides the gsql client that matches the cluster version for you to access the cluster using the cluster's public or private network address.</p>
<div class="section" id="EN-US_TOPIC_0000001180320141__section2664278815443"><h4 class="sectiontitle">Using the gsql CLI Client to Connect to a Cluster</h4><ol id="EN-US_TOPIC_0000001180320141__ol3845850015443"><li id="EN-US_TOPIC_0000001180320141__li147272252437"><span>Prepare a Linux ECS to install and run the gsql client.</span><p><p id="EN-US_TOPIC_0000001180320141__p103589108451">For details, see <a href="dws_01_0128.html">Preparing an ECS as the gsql Client Host</a>.</p>
</p></li><li id="EN-US_TOPIC_0000001180320141__li57820116171210"><span>Download the gsql client by referring to <a href="dws_01_0031.html">Downloading the Client</a>, and use an SSH file transfer tool (such as WinSCP) to upload the client to a target Linux host.</span><p><p id="EN-US_TOPIC_0000001180320141__adf760149a35140c48cf09071207cd279">The user who uploads the client must have the full control permission on the target directory on the host to which the client is uploaded.</p>
<p id="EN-US_TOPIC_0000001180320141__p2754133018133">Alternatively, you can remotely log in to the Linux host where the gsql is to be installed in SSH mode and run the following command in the Linux command window to download the gsql client:</p>
<pre class="screen" id="EN-US_TOPIC_0000001180320141__screen0169162716481">wget https://obs.otc.t-systems.com/dws/download/dws_client_redhat_x64.zip --no-check-certificate</pre>
</p></li><li id="EN-US_TOPIC_0000001180320141__li14921556171524"><span>Use the SSH tool to remotely log in to the host where the client is installed.</span><p><p id="EN-US_TOPIC_0000001180320141__en-us_topic_0106888034_p141041143523">For details about how to log in to an ECS, see "ECSs&gt; Logging In to a Linux ECS &gt; Login Using an SSH Password" in the <i><cite id="EN-US_TOPIC_0000001180320141__cd7370d9c4ec64f37aeceb04df55fd347">Elastic Cloud Server User Guide</cite></i>.</p>
</p></li><li id="EN-US_TOPIC_0000001180320141__li143598191920"><span>(Optional) <span id="EN-US_TOPIC_0000001180320141__text443615881913">To connect to the cluster in SSL mode</span>, configure SSL authentication parameters on the host where the client is installed. For details, see <a href="dws_01_0038.html">Establishing Secure TCP/IP Connections in SSL Mode</a>.</span><p><div class="note" id="EN-US_TOPIC_0000001180320141__note04362085193"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001180320141__p943638171915">The SSL connection mode is more secure than the non-SSL mode. You are advised to connect the client to the cluster in SSL mode.</p>
</div></div>
</p></li><li id="EN-US_TOPIC_0000001180320141__li28159407171547"><span>Run the following commands to decompress the client:</span><p><pre class="screen" id="EN-US_TOPIC_0000001180320141__screen173918175523">cd &lt;<em id="EN-US_TOPIC_0000001180320141__i3290164118364">Path for saving the client</em>&gt;
unzip <em id="EN-US_TOPIC_0000001180320141__i10517201512535">dws_client_8.1.x_redhat_x64.zip</em></pre>
<p id="EN-US_TOPIC_0000001180320141__p14308192714355">In the preceding commands:</p>
<ul id="EN-US_TOPIC_0000001180320141__ul18555114323517"><li id="EN-US_TOPIC_0000001180320141__li155410439357">&lt;<em id="EN-US_TOPIC_0000001180320141__i953114942312">Path_for_storing_the_client</em>&gt;: Replace it with the actual path.</li><li id="EN-US_TOPIC_0000001180320141__li9555114313356"><em id="EN-US_TOPIC_0000001180320141__i123762054104815">dws_client_8.1.x_redhat_x64.zip</em>: This is the client tool package name of <span class="parmvalue" id="EN-US_TOPIC_0000001180320141__parmvalue185611912154213"><b>RedHat x86</b></span>. Replace it with the actual name.</li></ul>
</p></li><li id="EN-US_TOPIC_0000001180320141__li15256751171613"><span>Run the following command to configure the GaussDB(DWS) client:</span><p><pre class="screen" id="EN-US_TOPIC_0000001180320141__screen39549318531">source gsql_env.sh</pre>
<p id="EN-US_TOPIC_0000001180320141__acba60d877148432faf5ecdf94dd7b73e">If the following information is displayed, the GaussDB(DWS) client is successfully configured:</p>
<pre class="screen" id="EN-US_TOPIC_0000001180320141__s8fd77cb5c040479baaab9ae3f2ea8fa5">All things done.</pre>
</p></li><li id="EN-US_TOPIC_0000001180320141__li41463031113158"><span>Connect to the database in the GaussDB(DWS) cluster using the gsql client. Replace the values of each parameter with actual values.</span><p><pre class="screen" id="EN-US_TOPIC_0000001180320141__screen14165156155416"><strong id="EN-US_TOPIC_0000001180320141__b1429125514332">gsql -d &lt;</strong><em id="EN-US_TOPIC_0000001180320141__i1643665510335">Database_name</em><strong id="EN-US_TOPIC_0000001180320141__b12436185533316">&gt; -h &lt;</strong><em id="EN-US_TOPIC_0000001180320141__i5437255163316">Cluster_address</em><strong id="EN-US_TOPIC_0000001180320141__b184371355133320">&gt; -U &lt;</strong><em id="EN-US_TOPIC_0000001180320141__i18438205533314">Database_user</em><strong id="EN-US_TOPIC_0000001180320141__b943825513311">&gt; -p &lt;</strong><em id="EN-US_TOPIC_0000001180320141__i243915503318">Database_port</em>&gt; <strong id="EN-US_TOPIC_0000001180320141__b1844112558334">-r</strong></pre>
<p id="EN-US_TOPIC_0000001180320141__p6670175610390">The parameters are described as follows:</p>
<ul id="EN-US_TOPIC_0000001180320141__ul6532192614405"><li id="EN-US_TOPIC_0000001180320141__li135361926194014"><em id="EN-US_TOPIC_0000001180320141__i43181148132517">Database_name</em>: Enter the name of the database to be connected. If you use the client to connect to the cluster for the first time, enter the default database <strong id="EN-US_TOPIC_0000001180320141__b13322154812111"><span id="EN-US_TOPIC_0000001180320141__text6850145215424">gaussdb</span></strong>.</li><li id="EN-US_TOPIC_0000001180320141__li112312661818"><em id="EN-US_TOPIC_0000001180320141__i094617612267">Cluster_address</em>: For details about how to obtain this address, see <a href="dws_01_0033.html">Obtaining the Cluster Connection Address</a>. If a public network address is used for connection, set this parameter to <span class="parmname" id="EN-US_TOPIC_0000001180320141__parmname21231326121819"><b>Public Network Address</b></span> or <span class="parmname" id="EN-US_TOPIC_0000001180320141__parmname587154113195"><b>Public Network Domain Name</b></span>. If a private network address is used for connection, set this parameter to <span class="parmname" id="EN-US_TOPIC_0000001180320141__parmname12124132611189"><b>Private Network Address</b></span> or <span class="parmname" id="EN-US_TOPIC_0000001180320141__parmname89791149141913"><b>Private Network Domain Name</b></span>. </li><li id="EN-US_TOPIC_0000001180320141__li16543122664016"><em id="EN-US_TOPIC_0000001180320141__i87951622192618">Database_user</em>: Enter the username of the cluster's database. If you use the client to connect to the cluster for the first time, set this parameter to the default database administrator configured during cluster creation, for example, <span class="parmvalue" id="EN-US_TOPIC_0000001180320141__parmvalue901316906152829"><b>dbadmin</b></span>.</li><li id="EN-US_TOPIC_0000001180320141__li10550102618400"><em id="EN-US_TOPIC_0000001180320141__i1975219309261">Database_port</em>: Enter the database port set during cluster creation.</li></ul>
<p id="EN-US_TOPIC_0000001180320141__p4649355413199">For example, run the following command to connect to the default database <strong id="EN-US_TOPIC_0000001180320141__b4518103716511"><span id="EN-US_TOPIC_0000001180320141__text16675135114313">gaussdb</span></strong> in the GaussDB(DWS) cluster:</p>
<pre class="screen" id="EN-US_TOPIC_0000001180320141__screen157451922201313">gsql -d <span id="EN-US_TOPIC_0000001180320141__text8980103144418">gaussdb</span> -h 10.168.0.74 -U dbadmin -p 8000 -W <em id="EN-US_TOPIC_0000001180320141__i1655214575539">password</em> -r</pre>
<p id="EN-US_TOPIC_0000001180320141__p14596465113158">If the following information is displayed, the connection succeeded:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001180320141__screen64259327113158"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">gaussdb</span><span class="o">=&gt;</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</p></li></ol>
</div>
<div class="section" id="EN-US_TOPIC_0000001180320141__section41003216539"><h4 class="sectiontitle">gsql Command Reference</h4><p id="EN-US_TOPIC_0000001180320141__p94866279131">For more information about the gsql commands, see the <em id="EN-US_TOPIC_0000001180320141__i1539711813349">Data Warehouse Service (DWS) Tool Guide</em>.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001180320141__section16360114045919"><h4 class="sectiontitle">(Optional) Importing TPC-DS Sample Data Using gsql</h4><p id="EN-US_TOPIC_0000001180320141__p19752111617011">GaussDB(DWS) users can import data from external sources to data warehouse clusters. This section describes how to import sample data from OBS to a data warehouse cluster and perform querying and analysis operations on the sample data. The sample data is generated based on the standard TPC-DS benchmark test.</p>
<p id="EN-US_TOPIC_0000001180320141__p7938170102720">TPC-DS is the benchmark for testing the performance of decision support. With TPC-DS test data and cases, you can simulate complex scenarios, such as big data set statistics, report generation, online query, and data mining, to better understand functions and performance of database applications.</p>
<ol id="EN-US_TOPIC_0000001180320141__ol157036501972"><li id="EN-US_TOPIC_0000001180320141__li6937618813"><span>Use the SSH remote connection tool to log in to the host where the gsql client is installed and go to the gsql directory. The <strong id="EN-US_TOPIC_0000001180320141__b137521936738">/opt</strong> directory is used as an example for storing the gsql client.</span><p><pre class="screen" id="EN-US_TOPIC_0000001180320141__screen12234194145713"><strong id="EN-US_TOPIC_0000001180320141__b82451541105710">cd /opt</strong></pre>
</p></li><li id="EN-US_TOPIC_0000001180320141__li2697125017711"><span>Switch to the specified directory and set the AK and SK for importing sample data and the OBS access address.</span><p><pre class="screen" id="EN-US_TOPIC_0000001180320141__screen9534125810547">cd sample
/bin/bash setup.sh -ak &lt;<em id="EN-US_TOPIC_0000001180320141__i2311247155617">Access_Key_Id&gt;</em> -sk &lt;<em id="EN-US_TOPIC_0000001180320141__i10311247135620">Secret_Access_Key&gt;</em> -obs_location obs.otc.t-systems.com</pre>
<p id="EN-US_TOPIC_0000001180320141__p66971501171">If the following information is displayed, the settings are successful:</p>
<pre class="screen" id="EN-US_TOPIC_0000001180320141__screen569735012718">setup successfully!</pre>
<div class="note" id="EN-US_TOPIC_0000001180320141__note1369735019715"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001180320141__p204716185300"><em id="EN-US_TOPIC_0000001180320141__i174184215373">&lt;Access_Key_Id&gt;</em> and <em id="EN-US_TOPIC_0000001180320141__i20802426373">&lt;Secret_Access_Key&gt;</em>: indicate the AK and SK, respectively. For details about how to obtain the AK and SK, see "Data Import &gt; Concurrently Importing Data from OBS &gt; Creating Access Keys (AK and SK)" in the <em id="EN-US_TOPIC_0000001180320141__i9466108124912">Data Warehouse Service (DWS) Developer Guide</em>. Then, replace the parameters in the statements with the obtained values.</p>
</div></div>
</p></li><li id="EN-US_TOPIC_0000001180320141__li144036111801"><span>Go back to previous directory and run the gsql environment variables.</span><p><pre class="screen" id="EN-US_TOPIC_0000001180320141__screen18599162743510">cd ..
source gsql_env.sh
cd bin</pre>
</p></li><li id="EN-US_TOPIC_0000001180320141__li07034507712"><span>Import the sample data to the data warehouse.</span><p><p id="EN-US_TOPIC_0000001180320141__p14375203571114">Command format:</p>
<pre class="screen" id="EN-US_TOPIC_0000001180320141__screen1354517342593">gsql -d &lt;<em id="EN-US_TOPIC_0000001180320141__i20811148143716">Database name</em>&gt; -h &lt;<em id="EN-US_TOPIC_0000001180320141__i1581694883714">Public network address of the cluster&gt;</em> -U &lt;<em id="EN-US_TOPIC_0000001180320141__i16817184812371">Administrator&gt;</em> -p &lt;<em id="EN-US_TOPIC_0000001180320141__i19817104843711">Data warehouse port number&gt;</em> -f &lt;<em id="EN-US_TOPIC_0000001180320141__i1781704811379">Path for storing the sample data script&gt; -r</em></pre>
<p id="EN-US_TOPIC_0000001180320141__p549564951117">Sample command:</p>
<pre class="screen" id="EN-US_TOPIC_0000001180320141__screen398214551593">gsql -d <span id="EN-US_TOPIC_0000001180320141__text254144216457">gaussdb</span> -h 10.168.0.74 -U dbadmin -p 8000 -f /opt/sample/tpcds_load_data_from_obs.sql -r</pre>
<div class="note" id="EN-US_TOPIC_0000001180320141__note1870365011711"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001180320141__p117032502710">In the preceding command, sample data script <span class="filepath" id="EN-US_TOPIC_0000001180320141__filepath17375399518"><b>tpcds_load_data_from_obs.sql</b></span> is stored in the sample directory (for example, <strong id="EN-US_TOPIC_0000001180320141__b3388191157">/opt/sample/</strong>) of the GaussDB(DWS) client.</p>
</div></div>
<p id="EN-US_TOPIC_0000001180320141__p207031150572">After you enter the database administrator password and successfully connect to the database in the cluster, the system will automatically create a foreign table to associate the sample data outside the cluster. Then, the system creates a target table for saving the sample data and imports the data to the target table using the foreign table.</p>
<p id="EN-US_TOPIC_0000001180320141__p1270312509710">The time required for importing a large dataset depends on the current GaussDB(DWS) cluster specifications. Generally, the import takes about 10 to 20 minutes. If information similar to the following is displayed, the import is successful.</p>
<pre class="screen" id="EN-US_TOPIC_0000001180320141__screen15703115012718">Time:1845600.524 ms</pre>
</p></li></ol><ol start="5" id="EN-US_TOPIC_0000001180320141__ol146958501712"><li id="EN-US_TOPIC_0000001180320141__li969412502719"><span>In the Linux command window, run the following commands to switch to a specific directory and query the sample data:</span><p><pre class="screen" id="EN-US_TOPIC_0000001180320141__screen7422039141412">cd /opt/sample/query_sql/
/bin/bash tpcds100x.sh</pre>
</p></li><li id="EN-US_TOPIC_0000001180320141__li116951502710"><span>Enter the cluster's public network IP address, access port, database name, user who accesses the database, and password of the user as prompted.</span><p><ul id="EN-US_TOPIC_0000001180320141__ul11694115016711"><li id="EN-US_TOPIC_0000001180320141__li269445010716">The default database name is <strong id="EN-US_TOPIC_0000001180320141__b378716551568"><span id="EN-US_TOPIC_0000001180320141__text149310555455">gaussdb</span></strong>.</li><li id="EN-US_TOPIC_0000001180320141__li26941502712">Use the database administrator username and password configured during cluster creation as the username and password for accessing the database.</li></ul>
<p id="EN-US_TOPIC_0000001180320141__p46944501878">After the query is complete, a directory for storing the query result, such as <strong id="EN-US_TOPIC_0000001180320141__b842352706184710">query_output_20170914_072341</strong>, will be generated in the current query directory, for example, <span class="filepath" id="EN-US_TOPIC_0000001180320141__filepath494650861184645"><b>sample/query_sql/</b></span>.</p>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_01_0093.html">Using the gsql CLI Client to Connect to a Cluster</a></div>
</div>
</div>