doc-exports/docs/dws/dev/dws_04_0213.html
Lu, Huayi a24ca60074 DWS DEVELOPER 811 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>
2023-01-19 13:37:49 +00:00

120 lines
36 KiB
HTML

<a name="EN-US_TOPIC_0000001099441086"></a><a name="EN-US_TOPIC_0000001099441086"></a>
<h1 class="topictitle1">Manually Creating a Foreign Server</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p143401232191816">In the syntax <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b142231738194616">CREATE FOREIGN TABLE (SQL on Hadoop or OBS)</strong> for creating a foreign table, you need to specify a foreign server associated with the MRS data source connection.</p>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p22484229371">When you create an MRS data source connection on the <span id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_ph1692512422530">GaussDB(DWS)</span> management console, the database administrator <strong id="EN-US_TOPIC_0000001099441086__b41421941124514">dbadmin</strong> automatically creates a foreign server in the default database <strong id="EN-US_TOPIC_0000001099441086__b131437414457">postgres</strong>. If you want to create a foreign table in the default database <strong id="EN-US_TOPIC_0000001099441086__b11134130114617">postgres</strong> to read MRS data, skip this section.</p>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p129865112523">To allow a common user to create a foreign table in a user-defined database to read MRS data, you must manually create a foreign server in the user-defined database. This section describes how does a common user create a foreign server in a user-defined database. The procedure is as follows:</p>
<ol id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ol1368815211919"><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li186881231920">Ensure that an MRS data source connection has been created for the <span id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_ph417419975517">GaussDB(DWS)</span> cluster.<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_p114121921104019"><span id="EN-US_TOPIC_0000001099441086__ph49612052517">For details, see "Managing MRS Data Sources &gt; Creating an MRS Data Source Connection" in the <em id="EN-US_TOPIC_0000001099441086__i39591352313">Data Warehouse Service User Guide</em>.</span></p>
</li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li268817251913"><a href="#EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section765119474519">Creating a User and a Database and Granting the User Foreign Table Permissions</a></li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li36884218197"><a href="#EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section070174417129">Manually Creating a Foreign Server</a></li></ol>
<div class="note" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_note1596044164318"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p10960174134318">If you no longer need to read data from the MRS data source and have deleted the MRS data source on the <span id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_ph1933119180555">GaussDB(DWS)</span> management console, only the foreign server automatically created in the default database <strong id="EN-US_TOPIC_0000001099441086__b1982711581364">gaussdb</strong> will be deleted, and the manually created foreign server needs to be deleted manually. For details about the deletion, see <a href="dws_04_0216.html#EN-US_TOPIC_0000001099281248__en-us_topic_0000001082926731_en-us_topic_0109259519_en-us_topic_0102427953_section79551640133718">Deleting the Manually Created Foreign Server</a>.</p>
</div></div>
<div class="section" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section765119474519"><a name="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section765119474519"></a><a name="en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section765119474519"></a><h4 class="sectiontitle">Creating a User and a Database and Granting the User Foreign Table Permissions</h4><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p12921550135117">In the following example, a common user <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b8449128193415">dbuser</strong> and a database <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b17449122810344">mydatabase</strong> are created. Then, an administrator is used to grant foreign table permissions to user <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b13449828133415">dbuser</strong>.</p>
<ol id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ol829775011517"><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_li142731428201114"><span>Connect to the default database <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b825619498913">gaussdb</strong> as a database administrator through the database client tool provided by <span id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_ph6572122717556">GaussDB(DWS)</span>.</span><p><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_a6cd9e107bfd243c8b4dd75dc2755fc2d">For example, use the <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b41104516920">gsql</strong> client to connect to the database by running the following command:</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen8320450165111">gsql -d postgres -h <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i1733610509515">192.168.2.30</em> -U dbadmin -p 8000 -W <em id="EN-US_TOPIC_0000001099441086__i1932438565">password </em>-r</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p203461450165111">Enter your password as prompted.</p>
</p></li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li1754135025112"><span>Create a common user and use it to create a database.</span><p><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p85530506517">Create a user named <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b12668144373620">dbuser</strong> that has the permission to create databases.</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen145571950115118"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b256917503513">CREATE USER</strong> <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i185721650175111">dbuser </em><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b257685045116">WITH </strong><em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i10580155015119">CREATEDB </em><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b1158565016518">PASSWORD </strong>'<em id="EN-US_TOPIC_0000001099441086__i4525323115518">password</em>';</pre>
<div class="p" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p1059605020512">Switch to the created user.<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen760095055111"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b124141954596">SET ROLE</strong> <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i1641418555918">dbuser</em> <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b104148517595">PASSWORD </strong>'<em id="EN-US_TOPIC_0000001099441086__i1427371145715">password</em>';</pre>
</div>
<div class="p" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p1963475020515">Run the following command to create a database:<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen4638450115118"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b841911517592">CREATE</strong><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b9419259592"> DATABASE </strong><em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i141919585919">mydatabase</em>;</pre>
</div>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p3658185085119">Query the database.</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_s7b213b09aec54d51a415f31de9f34c2a"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_a53d58016c06340d796e2871fc3406916">SELECT * FROM pg_database;</strong></pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p106747500513">The database is successfully created if the returned result contains information about <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b3108143115442">mydatabase</strong>.</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen968475085113">datname | datdba | encoding | datcollate | datctype | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace | datcompatibility | datacl
------------+--------+----------+------------+----------+---------------+--------------+--------------+---------------+--------------+---------------+------------------+--------------------------------------
--------------
template1 | 10 | 0 | C | C | t | t | -1 | 14146 | 1351 | 1663 | ORA | {=c/<span id="EN-US_TOPIC_0000001099441086__ph158086103163">Ruby</span>,omm=CTc/<span id="EN-US_TOPIC_0000001099441086__ph61771016131617">Ruby</span>}
template0 | 10 | 0 | C | C | t | f | -1 | 14146 | 1350 | 1663 | ORA | {=c/<span id="EN-US_TOPIC_0000001099441086__ph5222212164">Ruby</span>,<span id="EN-US_TOPIC_0000001099441086__ph738892510162">Ruby</span>=CTc/<span id="EN-US_TOPIC_0000001099441086__ph388143018166">Ruby</span>}
postgres | 10 | 0 | C | C | f | t | -1 | 14146 | 1352 | 1663 | ORA | {=Tc/<span id="EN-US_TOPIC_0000001099441086__ph1031013358169">Ruby</span>,<span id="EN-US_TOPIC_0000001099441086__ph984433991618">Ruby</span>=CTc/<span id="EN-US_TOPIC_0000001099441086__ph3670164411161">Ruby</span>,chaojun=C/<span id="EN-US_TOPIC_0000001099441086__ph79200507167">Ruby</span>,hu
obinru=C/<span id="EN-US_TOPIC_0000001099441086__ph1070454345611">Ruby</span>}
<strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b15393123121311">mydatabase</strong> | 17000 | 0 | C | C | f | t | -1 | 14146 | 1351 | 1663 | ORA |
(4 rows)</pre>
</p></li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_lbb4792f399454947b6f66f19fbda4546"><span>Grant the permissions for creating foreign servers and using foreign tables to a common user as the administrator.</span><p><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_p20362151612179">Use the connection to create a database as a database administrator.</p>
<div class="p" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_a4bfb3f8aae0a416980e919e61dc06aac">You can use the <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b08648541099">gsql</strong> client to run the following command, switching to an administrator user, and connect to the new database:<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen17601950165117"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b1577055085115">\c</strong><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b277375016517"> </strong><em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i477685017518">mydatabase dbadmin</em>;</pre>
</div>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p147831050185118">Enter the password as prompted.</p>
<div class="note" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_note17786550145118"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p1879955025116">Note that you must use the administrator account to connect to the database where a foreign server is to be created and foreign tables are used; and then grant permissions to the common user.</p>
</div></div>
<div class="p" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p879945010516">By default, only system administrators can create foreign servers. Common users can create foreign servers only after being authorized. Run the following command to grant the permission:<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen7802125013517"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b84448514591">GRANT ALL ON</strong> FOREIGN DATA WRAPPER hdfs_fdw <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b164447585914">TO</strong> <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i114442519593">dbuser</em>;</pre>
</div>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p2082119504512">The name of <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b97502397413">FOREIGN DATA WRAPPER</strong> must be <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b157501539114116">hdfs_fdw</strong>. <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b1075013904112">dbuser</strong> is the username for creating <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b13750133916419">SERVER</strong>.</p>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p1382575017513">Run the following command to grant the user the permission to use foreign tables:</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen282835065114"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b148381150145119">ALTER USER</strong> <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i1841950195113">dbuser</em> <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b1684412504514">USEFT</strong>;</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p17847195011516">Query for the user.</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen1585195065113">SELECT r.rolname, r.rolsuper, r.rolinherit,
r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,
r.rolconnlimit, r.rolvalidbegin, r.rolvaliduntil,
ARRAY(SELECT b.rolname
FROM pg_catalog.pg_auth_members m
JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)
WHERE m.member = r.oid) as memberof
, r.rolreplication
, r.rolauditadmin
, r.rolsystemadmin
, r.roluseft
FROM pg_catalog.pg_roles r
ORDER BY 1;</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p38611150155111">The authorization is successful if the <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706113153">dbuser</strong> information in the returned result contains the <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b133971541171319">UseFT</strong> permission.</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen1486415504517"> rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolconnlimit | rolvalidbegin | rolvaliduntil | memberof | rolreplication | rolauditadmin | rolsystemadmin | <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b0101144815363">roluseft</strong>
-----------+----------+------------+---------------+-------------+-------------+--------------+---------------+---------------+----------+----------------+---------------+----------------+----------
dbuser | f | t | f | t | t | -1 | | | {} | f | f | f | t
lily | f | t | f | f | t | -1 | | | {} | f | f | f | f
<span id="EN-US_TOPIC_0000001099441086__ph103182351719">Ruby</span> | t | t | t | t | t | -1 | | | {} | t | t | t |<strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b17952185323619"> t</strong></pre>
</p></li></ol>
</div>
<div class="section" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section070174417129"><a name="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section070174417129"></a><a name="en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section070174417129"></a><h4 class="sectiontitle">Manually Creating a Foreign Server</h4><ol id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ol62901748313"><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li192864493116"><span>Connect to the default database <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b1943648151915">gaussdb</strong> as a database administrator through the database client tool provided by <span id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_ph25485443528">GaussDB(DWS)</span>.</span><p><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_a5fc88bf06fb14b88a4d77cd3859351da">You can use the <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b1687418231013">gsql</strong> client to log in to the database in either of the following ways:</p>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p10529175864113">You can use either of the following methods to create the connection:</p>
<ul id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ul1987102122918"><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li286821192916">If you have logged in to the gsql client, run the following command to switch the database and user:<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen78672118298"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b88615211297">\c</strong><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b2755124135614"> </strong>postgres dbadmin;</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p393324232911">Enter the password as prompted.</p>
</li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li28642119290">If you have not logged in to the gsql client or have exited the gsql client by running the <b><span class="cmdname" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_cmdname20356639125315">\q</span></b> command, run the following command to reconnect to it:<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen398519063110">gsql -d postgres -h <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i799010163118">192.168.2.30</em> -U dbadmin -p 8000 -W <em id="EN-US_TOPIC_0000001099441086__i753691795710">password</em> -r</pre>
</li></ul>
</p></li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li142862473118"><a name="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li142862473118"></a><a name="en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li142862473118"></a><span>Run the following command to query the information about the foreign server that is automatically created:</span><p><pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen3286541318">SELECT * FROM pg_foreign_server;</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p32869417313">The returned result is as follows:</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen162869416315"> srvname | srvowner | srvfdw | srvtype | srvversion | srvacl | srvoptions
--------------------------------------------------+----------+--------+---------+------------+--------+---------------------------------------------------------------------------------------------------------------------
gsmpp_server | 10 | 13673 | | | |
gsmpp_errorinfo_server | 10 | 13678 | | | |
<strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b2891145517415">hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca</strong> | 16476 | 13685 | | | | {<strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b181851322750">"address=192.168.1.245:25000,192.168.1.218:25000",hdfscfgpath=/MRS/8f79ada0-d998-4026-9020-80d6de2692ca</strong>,type=hdfs}
(3 rows)</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p125530415398">In the query result, each row contains the information about a foreign server. The foreign server associated with the MRS data source connection contains the following information:</p>
<ul id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ul35541483911"><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li1255512414397">The value of <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706114911">srvname</strong> contains <span class="parmvalue" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_parmvalue440033319114926"><b>hdfs_server</b></span> and the ID of the MRS cluster, which is the same as the MRS ID in the cluster list on the MRS management console.</li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li19558134113914">The <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b84235270611527">address</strong> parameter in the <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706115211">srvoptions</strong> field contains the IP addresses and ports of the active and standby nodes in the MRS cluster.</li></ul>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p165618463911">You can find the foreign server you want based on the above information and record the values of its <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706115338">srvname</strong> and <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706115342">srvoptions</strong>.</p>
</p></li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li16757220114119"><span>Switch to the user who is about to create a foreign server to connect to the corresponding database.</span><p><div class="p" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p17718143239">In this example, run the following command to use common user <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706115548">dbuser</strong> created in <a href="#EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_section765119474519">Creating a User and a Database and Granting the User Foreign Table Permissions</a> to connect to <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706115637">mydatabase</strong> created by the user:<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen1163511110314"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b2049445195914">\c</strong><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b34949575913"> </strong><em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i1649425205920">mydatabase dbuser</em>;</pre>
</div>
</p></li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li5290144113112"><span>Create a foreign server.</span><p><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p8991101111566">For details about the syntax for creating foreign servers, see CREATE SERVER. For example:</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen11290114183116"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b172204444358">CREATE SERVER</strong> <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i14681516142">hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca </em><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b1982813411406">FOREIGN DATA WRAPPER </strong>HDFS_FDW
<strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_b17838165617358">OPTIONS </strong>
(
address <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i1971186164617">'192.168.1.245:25000,192.168.1.218:25000'</em>,
hdfscfgpath <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i9934511124615">'/MRS/8f79ada0-d998-4026-9020-80d6de2692ca',</em>
type 'hdfs'
);</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p529094113116">Mandatory parameters are described as follows:</p>
<ul id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ul72904473112"><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li20112247502"><em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_i842352697115845">Name of the foreign server</em><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p597517818226">You can customize a name.</p>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p14825494018">In this example, specify the name to the value of the <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b84235270614142">srvname</strong> field recorded in <a href="#EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li142862473118">2</a>, such as <em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_i425787841419">hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca</em>.</p>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p172607412714">Resources in different databases are isolated. Therefore, the names of foreign servers in different databases can be the same.</p>
</li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li19490175515519"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b28224115532">FOREIGN DATA WRAPPER</strong><p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p183267571517">This parameter can only be set to <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b84235270614299">HDFS_FDW</strong>, which already exists in the database.</p>
</li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li18678132185718"><strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b0652215175318">OPTIONS</strong> parameters<div class="p" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p4600144865711">Set the following parameters to the values under <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706143059">srvoptions</strong> recorded in <a href="#EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li142862473118">2</a>.<ul id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ul18824445155713"><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li14824174512577">address<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p882410453571"><a name="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li14824174512577"></a><a name="en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li14824174512577"></a>Specifies the IP address and port number of the primary and standby nodes of the HDFS cluster.</p>
</li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li108241245175711">hdfscfgpath<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p18824134515575"><a name="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li108241245175711"></a><a name="en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li108241245175711"></a>Specifies the configuration file path of the HDFS cluster. This parameter is available only when <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b84235270610957">type</strong> is <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b84235270610100">HDFS</strong>. You can set only one path.</p>
</li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li164581429113218">type<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p34741157387"><a name="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li164581429113218"></a><a name="en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li164581429113218"></a>Its value is <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706143610">hdfs</strong>, which indicates that <strong id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_b842352706143623">HDFS_FDW</strong> connects to HDFS.</p>
</li></ul>
</div>
</li></ul>
</p></li><li id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_li1532292418484"><span>View the foreign server.</span><p><pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen1329004143114">SELECT * FROM pg_foreign_server WHERE srvname='<span id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_ph133139431845"><em id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_i131317435412">hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca</em></span>';</pre>
<p id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_p182901244318">The server is successfully created if the returned result is as follows:</p>
<pre class="screen" id="EN-US_TOPIC_0000001099441086__en-us_topic_0000001082926737_en-us_topic_0109259516_en-us_topic_0101997156_screen1290843319"> srvname | srvowner | srvfdw | srvtype | srvversion | srvacl | srvoptions
--------------------------------------------------+----------+--------+---------+------------+--------+---------------------------------------------------------------------------------------------------------------------
hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca | 16476 | 13685 | | | | {"address=192.168.1.245:25000,192.168.1.218:25000",hdfscfgpath=/MRS/8f79ada0-d998-4026-9020-80d6de2692ca,type=hdfs}
(1 row)</pre>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0210.html">Importing Data from MRS to a Cluster</a></div>
</div>
</div>