Updated on 2023-10-23 GMT+08:00
PURGE
Function
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.
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 reason_table_space tablespace. openGauss=# CREATE TABLESPACE REASON_TABLE_SPACE1 owner tpcds RELATIVE location 'tablespace/tsp_reason1'; -- Create the tpcds.reason_t1 table in the tablespace. openGauss=# 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. openGauss=# 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. openGauss=# 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. openGauss=# CREATE INDEX index_t1 on tpcds.reason_t1(r_reason_id); openGauss=# DROP TABLE tpcds.reason_t1; openGauss=# DROP TABLE tpcds.reason_t2; openGauss=# DROP TABLE tpcds.reason_t3; -- View the recycle bin. openGauss=# 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. openGauss=# PURGE TABLE tpcds.reason_t3; openGauss=# 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. openGauss=# PURGE INDEX tindex_t1; openGauss=# 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. openGauss=# PURGE recyclebin; openGauss=# SELECT rcyname,rcyoriginname,rcytablespace FROM GS_RECYCLEBIN; rcyname | rcyoriginname | rcytablespace -----------------------+---------------+--------------- (0 rows)
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