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.
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. When the separation of duties is disabled, the system administrator has this permission by default.
- PURGE INDEX: The user must be the owner of the index and must have the USAGE permission for the schema to which the index belongs. When the separation of duties is disabled, the system administrator has this permission by default.
- PURGE RECYCLEBIN: Common users can clear only the objects owned by themselves in the recycle bin. Additionally, the user must have the USAGE permission of the schema to which the objects belong. When the separation of duties is disabled, the system administrator has this permission by default.
Prerequisites
- The enable_recyclebin parameter has been enabled to enable the recycle bin. Contact an 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 an 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. The table can be schema-qualified.
- INDEX index_name
Clears a specified index in the recycle bin.
- RECYCLEBIN
Clears the objects in the recycle bin.
Examples
-- Create a schema.
m_db=# CREATE SCHEMA tpcds;
-- Create the tpcds.reason_t1 table.
m_db=# CREATE TABLE tpcds.reason_t1
(
r_reason_sk integer,
r_reason_id character(16),
r_reason_desc character(100)
) ;
-- Create the tpcds.reason_t2 table.
m_db=# CREATE TABLE tpcds.reason_t2
(
r_reason_sk integer,
r_reason_id character(16),
r_reason_desc character(100)
) ;
-- Create an index on the tpcds.reason_t1 table.
m_db=# CREATE INDEX index_t1 on tpcds.reason_t1(r_reason_id);
m_db=# CREATE INDEX index_t2 on tpcds.reason_t2(r_reason_id);
m_db=# DROP TABLE tpcds.reason_t1;
m_db=# DROP TABLE tpcds.reason_t2;
-- Check the recycle bin.
m_db=# SELECT rcyname,rcyoriginname,rcytablespace FROM pg_catalog.gs_recyclebin;
rcyname | rcyoriginname | rcytablespace
------------------------------+---------------+---------------
BIN$41512338419D$87EAEB8==$0 | reason_t1 | 0
BIN$4151233841A3$87EBBE0==$0 | index_t1 | 0
BIN$4151233841A0$87EC6A0==$0 | reason_t2 | 0
BIN$4151233841A4$87ED0F0==$0 | index_t2 | 0
(4 rows)
-- Purge the table.
m_db=# PURGE TABLE tpcds.reason_t2;
m_db=# SELECT rcyname,rcyoriginname,rcytablespace FROM pg_catalog.gs_recyclebin;
-- Purge the index.
m_db=# PURGE INDEX tpcds.index_t1;
m_db=# SELECT rcyname,rcyoriginname,rcytablespace FROM pg_catalog.gs_recyclebin;
rcyname | rcyoriginname | rcytablespace
------------------------------+---------------+---------------
BIN$41512338419D$87EAEB8==$0 | reason_t1 | 0
BIN$4151233841A3$87EBBE0==$0 | index_t1 | 0
(2 rows)
-- Purge all objects
m_db=# PURGE recyclebin;
m_db=# SELECT rcyname,rcyoriginname,rcytablespace FROM pg_catalog.gs_recyclebin;
rcyname | rcyoriginname | rcytablespace
---------+---------------+---------------
(0 rows)
-- Delete the schema.
m_db=# DROP SCHEMA tpcds;
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.
For any further questions, feel free to contact us through the chatbot.
Chatbot