Updated on 2024-03-08 GMT+08:00

Deleting Resources

After completing operations in this tutorial, if you no longer need to use the resources created during the operations, you can delete them to avoid resource waste or quota occupation.

Deleting the Foreign Table and Target Table

  1. (Optional) If operations in Querying Data After Importing It have been performed, run the following command to delete the target table:

    1
    DROP TABLE product_info;
    

  2. Run the following command to delete the foreign table:

    1
    DROP FOREIGN TABLE foreign_product_info;
    

Deleting the Manually Created Foreign Server

If operations in Manually Creating a Foreign Server have been performed, perform the following steps to delete the foreign server, database, and user:

  1. Use the client provided by GaussDB(DWS) to connect to the database where the foreign server resides as the user who created the foreign server.

    You can use the gsql client to log in to the database in either of the following ways:

    • If you have logged in to the gsql client, run the following command to switch the database and user:
      1
      \c mydatabase dbuser;
      

      Enter the password as prompted.

    • If you have logged in to the gsql client, you can run the \q command to exit gsql, and run the following command to reconnect to it:
      1
      gsql -d mydatabase -h 192.168.2.30 -U dbuser -p 8000 -r
      

      Enter the password as prompted.

  2. Delete the manually created foreign server.

    Run the following command to delete the server. For details about the syntax, see DROP SERVER.

    1
    DROP SERVER hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca;
    

    The foreign server is deleted if the following information is displayed:

    1
    DROP SERVER
    

    View the foreign server.

    1
    SELECT * FROM pg_foreign_server WHERE srvname='hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca';
    

    The server is successfully deleted if the returned result is as follows:

    1
    2
    3
     srvname | srvowner | srvfdw | srvtype | srvversion | srvacl | srvoptions
    ---------+----------+--------+---------+------------+--------+------------
    (0 rows)
    

  3. Delete the customized database.

    Connect to the default database postgres through the database client tool provided by GaussDB(DWS).

    If you have logged in to the database using the gsql client, run the following command to switch the database and user:

    1
    \c postgres
    

    Enter your password as prompted.

    Run the following command to delete the customized database:

    1
    DROP DATABASE mydatabase;
    

    The database is deleted if the following information is displayed:

    1
    DROP DATABASE
    

  4. Delete the common user created in this example as the administrator.

    Connect to the database as a database administrator through the database client tool provided by GaussDB(DWS).

    If you have logged in to the database using the gsql client, run the following command to switch the database and user:

    1
    \c postgres dbadmin
    
    Run the following command to reclaim the permission for creating foreign servers:
    1
    REVOKE ALL ON FOREIGN DATA WRAPPER hdfs_fdw FROM dbuser;
    

    The name of FOREIGN DATA WRAPPER must be hdfs_fdw. dbuser is the username for creating SERVER.

    Run the following command to delete the user:

    1
    DROP USER dbuser;
    

    You can run the \du command to query for the user and check whether the user has been deleted.