• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. Querying External Data
  5. Querying Data on OBS
  6. Deleting Resources

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. Perform the following operations:

  1. Deleting the Foreign Table and Target Table
  2. Deleting the Created Foreign Server
  3. Deleting the Database and the User to Which the Database Belongs

    If you have performed steps in (Optional) Creating a User and a Database and Granting the User Foreign Table Permissions, delete the database and the user to which the database belongs.

Deleting the Foreign Table and Target Table

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

    DROP TABLE product_info;

    If the following information is displayed, the table has been deleted.

    DROP TABLE

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

    DROP FOREIGN TABLE product_info_ext_obs;

    If the following information is displayed, the table has been deleted.

    DROP FOREIGN TABLE

Deleting the Created Foreign Server

  1. Use the user who created the foreign server to connect to the database where the foreign server is located.

    In this example, common user dbuser is used to create the foreign server in mydatabase. You need to connect to the database through the database client provided by DWS. 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:
      \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:
      gsql -d mydatabase -h 192.168.2.30 -U dbuser -p 8000 -r

      Enter the password as prompted.

  2. Delete the created foreign server.

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

    DROP SERVER obs_server;

    The database is deleted if the following information is displayed:

    DROP SERVER

    View the foreign server.

    SELECT * FROM pg_foreign_server WHERE srvname='obs_server';

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

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

Deleting the Database and the User to Which the Database Belongs

If you have performed steps in (Optional) Creating a User and a Database and Granting the User Foreign Table Permissions, perform the following steps to delete the database and the user to which the database belongs.

  1. Delete the customized database.

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

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

    \c postgres

    Enter your password when prompted.

    Run the following command to delete the customized database:

    DROP DATABASE mydatabase;

    The database is deleted if the following information is displayed:

    DROP DATABASE

  2. Switch to the administrator and delete the common user created in this example.

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

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

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

    The name of FOREIGN DATA WRAPPER must be dfs_fdw. dbuser is the user name for creating SERVER.

    Run the following command to delete the user:

    DROP USER dbuser;
    DROP ROLE

      

    You can run the following command to query the user and check whether the user has been deleted:

    SELECT * FROM pg_user;