Updated on 2024-05-07 GMT+08:00
PURGE
Description
The PURGE statement can be used to:
- Clear tables or indexes from the recycle bin and release all space related to the objects.
- Clear the recycle bin.
- Clear the objects of a specified tablespace in the recycle bin.
Precautions
-
The permission requirements for performing the PURGE operation are as follows:
- PURGE TABLE: The user must be the owner of the table and must have the USAGE permission on the schema to which the table belongs. By default, the system administrator has this permission.
- PURGE INDEX: The user must be the owner of the index and have the USAGE permission on the schema to which the index belongs. By default, the system administrator has this permission.
- PURGE RECYCLEBIN: Common users can clear only the objects owned by themselves in the recycle bin. In addition, the user must have the USAGE permission of the schema to which the objects belong. By default, the system administrator can clear all objects in the recycle bin.
Prerequisites
- The enable_recyclebin parameter has been enabled to enable the recycle bin. Contact the administrator for details about how to use the parameter.
- The recyclebin_retention_time parameter has been set for specifying the retention period of objects in the recycle bin. The objects will be automatically deleted after the retention period expires. Contact the administrator for details about how to use the parameter.
Syntax
PURGE { TABLE [schema_name.]table_name | INDEX index_name | RECYCLEBIN }
- TABLE [ schema_name. ] table_name
Clears a specified table in the recycle bin.
- INDEX index_name
Clears a specified index in the recycle bin.
Examples
-- Create the tpcds role. gaussdb=# CREATE ROLE tpcds IDENTIFIED BY '*********'; -- Create the reason_table_space tablespace. gaussdb=# CREATE TABLESPACE REASON_TABLE_SPACE1 owner tpcds RELATIVE location 'tablespace/tsp_reason1'; -- Create a schema. gaussdb=# CREATE SCHEMA tpcds; -- Create the tpcds.reason_t1 table in the tablespace. gaussdb=# CREATE TABLE tpcds.reason_t1 ( r_reason_sk integer, r_reason_id character(16), r_reason_desc character(100) ) tablespace reason_table_space1; -- Create the tpcds.reason_t2 table in the tablespace. gaussdb=# CREATE TABLE tpcds.reason_t2 ( r_reason_sk integer, r_reason_id character(16), r_reason_desc character(100) ) tablespace reason_table_space1; -- Create the tpcds.reason_t3 table in the tablespace. gaussdb=# CREATE TABLE tpcds.reason_t3 ( r_reason_sk integer, r_reason_id character(16), r_reason_desc character(100) ) tablespace reason_table_space1; -- Create an index on the tpcds.reason_t1 table. gaussdb=# CREATE INDEX index_t1 on tpcds.reason_t1(r_reason_id); gaussdb=# DROP TABLE tpcds.reason_t1; gaussdb=# DROP TABLE tpcds.reason_t2; gaussdb=# DROP TABLE tpcds.reason_t3; -- View the recycle bin. gaussdb=# SELECT rcyname,rcyoriginname,rcytablespace FROM GS_RECYCLEBIN; rcyname | rcyoriginname | rcytablespace -----------------------+---------------+--------------- BIN$16409$2CEE988==$0 | reason_t1 | 16408 BIN$16412$2CF2188==$0 | reason_t2 | 16408 BIN$16415$2CF2EC8==$0 | reason_t3 | 16408 BIN$16418$2CF3EC8==$0 | index_t1 | 0 (4 rows) -- Purge the table. gaussdb=# PURGE TABLE tpcds.reason_t3; gaussdb=# SELECT rcyname,rcyoriginname,rcytablespace FROM GS_RECYCLEBIN; rcyname | rcyoriginname | rcytablespace -----------------------+---------------+--------------- BIN$16409$2CEE988==$0 | reason_t1 | 16408 BIN$16412$2CF2188==$0 | reason_t2 | 16408 BIN$16418$2CF3EC8==$0 | index_t1 | 0 (3 rows) -- Purge the index. gaussdb=# PURGE INDEX tpcds.index_t1; gaussdb=# SELECT rcyname,rcyoriginname,rcytablespace FROM GS_RECYCLEBIN; rcyname | rcyoriginname | rcytablespace -----------------------+---------------+--------------- BIN$16409$2CEE988==$0 | reason_t1 | 16408 BIN$16412$2CF2188==$0 | reason_t2 | 16408 (2 rows) -- Purge all objects in the recycle bin. gaussdb=# PURGE recyclebin; gaussdb=# SELECT rcyname,rcyoriginname,rcytablespace FROM GS_RECYCLEBIN; rcyname | rcyoriginname | rcytablespace -----------------------+---------------+--------------- (0 rows) -- Delete the schema. gaussdb=# DROP SCHEMA tpcds CASCADE;
Parent topic: SQL Syntax
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot