云数据库 GAUSSDB-闪回DROP/TRUNCATE:语法示例
时间:2024-11-13 10:05:00
语法示例
-- PURGE TABLE table_name; -- --查看回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) gaussdb=# DROP TABLE IF EXISTS flashtest; NOTICE: table "flashtest" does not exist, skipping DROP TABLE gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) --创建表flashtest gaussdb=# CREATE TABLE IF NOT EXISTS flashtest(id int, name text) with (storage_type = ustore); CREATE TABLE --插入数据 gaussdb=# INSERT INTO flashtest VALUES(1, 'A'); INSERT 0 1 gaussdb=# SELECT * FROM flashtest; id | name ----+------ 1 | A (1 row) --DROP表flashtest gaussdb=# DROP TABLE IF EXISTS flashtest; DROP TABLE --查看回收站,删除的表被放入回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecs n | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+----------------------+--------------+---------+---------------+-------------------------------+--------------+------------ --+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18591 | 12737 | 18585 | BIN$31C14EB4899$9737$0==$0 | flashtest | d | 0 | 79352606 | 2023-09-13 20:01:28.640664+08 | 79352595 | 7935259 5 | 2200 | 10 | 0 | 18585 | t | t | 225492 | 225492 | 18591 | 12737 | 18588 | BIN$31C14EB489C$12D1BF60==$0 | pg_toast_18585 | d | 2 | 79352606 | 2023-09-13 20:01:28.641018+08 | 0 | 0 | 99 | 10 | 0 | 18588 | f | f | 225492 | 225492 | (2 rows) --查看表flashtest,表不存在 gaussdb=# SELECT * FROM flashtest; ERROR: relation "flashtest" does not exist LINE 1: select * from flashtest; ^ --PURGE表,将回收站中的表删除 gaussdb=# PURGE TABLE flashtest; PURGE TABLE --查看回收站,回收站中的表被删除 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) -- PURGE INDEX index_name; -- gaussdb=# DROP TABLE IF EXISTS flashtest; NOTICE: table "flashtest" does not exist, skipping DROP TABLE --创建表flashtest gaussdb=# CREATE TABLE IF NOT EXISTS flashtest(id int, name text) with (storage_type = ustore); CREATE TABLE --为表flashtest创建索引flashtest_index gaussdb=# CREATE INDEX flashtest_index ON flashtest(id); CREATE INDEX --DROP表 gaussdb=# DROP TABLE IF EXISTS flashtest; DROP TABLE --查看回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecs n | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+----------------------+--------------+---------+---------------+-------------------------------+--------------+------------ --+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18648 | 12737 | 18641 | BIN$31C14EB48D1$9A85$0==$0 | flashtest | d | 0 | 79354509 | 2023-09-13 20:40:11.360638+08 | 79354506 | 7935450 8 | 2200 | 10 | 0 | 18641 | t | t | 226642 | 226642 | 18648 | 12737 | 18644 | BIN$31C14EB48D4$12E236A0==$0 | pg_toast_18641 | d | 2 | 79354509 | 2023-09-13 20:40:11.36112+08 | 0 | 0 | 99 | 10 | 0 | 18644 | f | f | 226642 | 226642 | 18648 | 12737 | 18647 | BIN$31C14EB48D7$9A85$0==$0 | flashtest_index | d | 1 | 79354509 | 2023-09-13 20:40:11.361246+08 | 79354508 | 7935450 8 | 2200 | 10 | 0 | 18647 | f | t | 0 | 0 | (3 rows) --PURGE索引flashtest_index gaussdb=# PURGE INDEX flashtest_index; PURGE INDEX --查看回收站,回收站中的索引flashtest_index被删除 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecs n | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+----------------------+--------------+---------+---------------+-------------------------------+--------------+------------ --+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18648 | 12737 | 18641 | BIN$31C14EB48D1$9A85$0==$0 | flashtest | d | 0 | 79354509 | 2023-09-13 20:40:11.360638+08 | 79354506 | 7935450 8 | 2200 | 10 | 0 | 18641 | t | t | 226642 | 226642 | 18648 | 12737 | 18644 | BIN$31C14EB48D4$12E236A0==$0 | pg_toast_18641 | d | 2 | 79354509 | 2023-09-13 20:40:11.36112+08 | 0 | 0 | 99 | 10 | 0 | 18644 | f | f | 226642 | 226642 | (2 rows) -- PURGE RECYCLEBIN -- --PURGE回收站 gaussdb=# PURGE RECYCLEBIN; PURGE RECYCLEBIN --查看回收站,回收站被清空 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) -- TIMECAPSULE TABLE { table_name } TO BEFORE DROP [RENAME TO new_tablename] -- gaussdb=# DROP TABLE IF EXISTS flashtest; NOTICE: table "flashtest" does not exist, skipping DROP TABLE --创建表flashtest gaussdb=# CREATE TABLE IF NOT EXISTS flashtest(id int, name text) with (storage_type = ustore); CREATE TABLE --插入数据 gaussdb=# INSERT INTO flashtest VALUES(1, 'A'); INSERT 0 1 gaussdb=# SELECT * FROM flashtest; id | name ----+------ 1 | A (1 row) --DROP表 gaussdb=# DROP TABLE IF EXISTS flashtest; DROP TABLE --查看回收站,表被放入回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecs n | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+----------------------+--------------+---------+---------------+-------------------------------+--------------+------------ --+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18658 | 12737 | 18652 | BIN$31C14EB48DC$9B2B$0==$0 | flashtest | d | 0 | 79354760 | 2023-09-13 20:47:57.075907+08 | 79354753 | 7935475 3 | 2200 | 10 | 0 | 18652 | t | t | 226824 | 226824 | 18658 | 12737 | 18655 | BIN$31C14EB48DF$12E46400==$0 | pg_toast_18652 | d | 2 | 79354760 | 2023-09-13 20:47:57.07621+08 | 0 | 0 | 99 | 10 | 0 | 18655 | f | f | 226824 | 226824 | (2 rows) --查看表,表不存在 gaussdb=# SELECT * FROM flashtest; ERROR: relation "flashtest" does not exist LINE 1: select * from flashtest; ^ --闪回drop表 gaussdb=# TIMECAPSULE TABLE flashtest to before drop; TimeCapsule Table --查看表,表被恢复到drop之前 gaussdb=# SELECT * FROM flashtest; id | name ----+------ 1 | A (1 row) --查看回收站,回收站中的表被删除 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) --DROP表 gaussdb=# DROP TABLE IF EXISTS flashtest; DROP TABLE gaussdb=# SELECT * FROM flashtest; ERROR: relation "flashtest" does not exist LINE 1: select * from flashtest; ^ --查看回收站,表被放入回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcy changecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+------------------------------+--------------+---------+---------------+-------------------------------+--------------+---- ----------+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18664 | 12737 | 18652 | BIN$31C14EB48DC$9B4E$0==$0 | flashtest | d | 0 | 79354845 | 2023-09-13 20:49:17.762977+08 | 79354753 | 79354753 | 2200 | 10 | 0 | 18652 | t | t | 226824 | 226824 | 18664 | 12737 | 18657 | BIN$31C14EB48E1$12E680A8==$0 | BIN$31C14EB48E1$12E45E00==$0 | d | 3 | 79354845 | 2023-09-13 20:49:17.763271+08 | 79354753 | 79354753 | 99 | 10 | 0 | 18657 | f | f | 0 | 0 | 18664 | 12737 | 18655 | BIN$31C14EB48DF$12E68698==$0 | BIN$31C14EB48DF$12E46400==$0 | d | 2 | 79354845 | 2023-09-13 20:49:17.763343+08 | 0 | 0 | 99 | 10 | 0 | 18655 | f | f | 226824 | 226824 | (3 rows) --闪回drop表,表名用回收站中的rcyname gaussdb=# TIMECAPSULE TABLE "BIN$31C14EB48DC$9B4E$0==$0" to before drop; TimeCapsule Table --查看回收站,回收站中的表被删除 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) gaussdb=# SELECT * FROM flashtest; id | name ----+------ 1 | A (1 row) --DROP表 gaussdb=# DROP TABLE IF EXISTS flashtest; DROP TABLE --查看回收站,表被放入回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcy changecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+------------------------------+--------------+---------+---------------+-------------------------------+--------------+---- ----------+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18667 | 12737 | 18652 | BIN$31C14EB48DC$9B8D$0==$0 | flashtest | d | 0 | 79354943 | 2023-09-13 20:52:14.525946+08 | 79354753 | 79354753 | 2200 | 10 | 0 | 18652 | t | t | 226824 | 226824 | 18667 | 12737 | 18657 | BIN$31C14EB48E1$1320B4F0==$0 | BIN$31C14EB48E1$12E680A8==$0 | d | 3 | 79354943 | 2023-09-13 20:52:14.526319+08 | 79354753 | 79354753 | 99 | 10 | 0 | 18657 | f | f | 0 | 0 | 18667 | 12737 | 18655 | BIN$31C14EB48DF$1320BAE0==$0 | BIN$31C14EB48DF$12E68698==$0 | d | 2 | 79354943 | 2023-09-13 20:52:14.526423+08 | 0 | 0 | 99 | 10 | 0 | 18655 | f | f | 226824 | 226824 | (3 rows) --查看表,表不存在 gaussdb=# SELECT * FROM flashtest; ERROR: relation "flashtest" does not exist LINE 1: SELECT * FROM flashtest; ^ --闪回drop表,并重命名表 gaussdb=# TIMECAPSULE TABLE flashtest to before drop rename to flashtest_rename; TimeCapsule Table --查看原表,表不存在 gaussdb=# SELECT * FROM flashtest; ERROR: relation "flashtest" does not exist LINE 1: SELECT * FROM flashtest; ^ --查看重命名后的表,表存在 gaussdb=# SELECT * FROM flashtest_rename; id | name ----+------ 1 | A (1 row) --查看回收站,回收站中的表被删除 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) --drop表 gaussdb=# DROP TABLE IF EXISTS flashtest_rename; DROP TABLE --清空回收站 gaussdb=# PURGE RECYCLEBIN; PURGE RECYCLEBIN --查看回收站,回收站被清空 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows) -- TIMECAPSULE TABLE { table_name } TO BEFORE TRUNCATE -- gaussdb=# DROP TABLE IF EXISTS flashtest; NOTICE: table "flashtest" does not exist, skipping DROP TABLE --创建表flashtest gaussdb=# CREATE TABLE IF NOT EXISTS flashtest(id int, name text) with (storage_type = ustore); CREATE TABLE --插入数据 gaussdb=# INSERT INTO flashtest VALUES(1, 'A'); INSERT 0 1 gaussdb=# SELECT * FROM flashtest; id | name ----+------ 1 | A (1 row) --truncate表 gaussdb=# TRUNCATE TABLE flashtest; TRUNCATE TABLE --查看回收站,表的数据被放入回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecs n | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+----------------------+--------------+---------+---------------+-------------------------------+--------------+------------ --+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18703 | 12737 | 18697 | BIN$31C14EB4909$9E4C$0==$0 | flashtest | t | 0 | 79356608 | 2023-09-13 21:24:42.819863+08 | 79356606 | 7935660 6 | 2200 | 10 | 0 | 18697 | t | t | 227927 | 227927 | 18703 | 12737 | 18700 | BIN$31C14EB490C$132FE3F0==$0 | pg_toast_18697 | t | 2 | 79356608 | 2023-09-13 21:24:42.820358+08 | 0 | 0 | 99 | 10 | 0 | 18700 | f | f | 227927 | 227927 | (2 rows) --查看表,表中的数据为空 gaussdb=# SELECT * FROM flashtest; id | name ----+------ (0 rows) --闪回truncate表 gaussdb=# TIMECAPSULE TABLE flashtest to before truncate; TimeCapsule Table --查看表,表中的数据被恢复 gaussdb=# SELECT * FROM flashtest; id | name ----+------ 1 | A (1 row) --查看回收站 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecs n | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+------------------------------+----------------------+--------------+---------+---------------+-------------------------------+--------------+------------ --+--------------+----------+---------------+----------------+---------------+-------------+--------------+----------------+----------- 18703 | 12737 | 18700 | BIN$31C14EB490C$13300228==$0 | pg_toast_18697 | t | 2 | 79356610 | 2023-09-13 21:24:42.872732+08 | 0 | 0 | 99 | 10 | 0 | 18706 | f | f | 0 | 227928 | 18703 | 12737 | 18697 | BIN$31C14EB4909$9E4D$0==$0 | flashtest | t | 0 | 79356610 | 2023-09-13 21:24:42.872792+08 | 79356606 | 7935660 6 | 2200 | 10 | 0 | 18704 | t | t | 0 | 227928 | (2 rows) --drop表 gaussdb=# DROP TABLE IF EXISTS flashtest; DROP TABLE --清空回收站 gaussdb=# PURGE RECYCLEBIN; PURGE RECYCLEBIN --查看回收站,回收站被清空 gaussdb=# SELECT * FROM gs_recyclebin; rcybaseid | rcydbid | rcyrelid | rcyname | rcyoriginname | rcyoperation | rcytype | rcyrecyclecsn | rcyrecycletime | rcycreatecsn | rcychangecsn | rcynamespace | rcyowner | rcytablespace | rcyrelfilenode | rcycanrestore | rcycanpurge | rcyfrozenxid | rcyfrozenxid64 | rcybucket -----------+---------+----------+---------+---------------+--------------+---------+---------------+----------------+--------------+--------------+--------------+----------+-------------- -+----------------+---------------+-------------+--------------+----------------+----------- (0 rows)
support.huaweicloud.com/fg-gaussdb-cent-v8/gaussdb-48-0203.html
看了此文的人还看了
CDN加速
GaussDB
文字转换成语音
免费的服务器
如何创建网站
域名网站购买
私有云桌面
云主机哪个好
域名怎么备案
手机云电脑
SSL证书申请
云点播服务器
免费OCR是什么
电脑云桌面
域名备案怎么弄
语音转文字
文字图片识别
云桌面是什么
网址安全检测
网站建设搭建
国外CDN加速
SSL免费证书申请
短信批量发送
图片OCR识别
云数据库MySQL
个人域名购买
录音转文字
扫描图片识别文字
OCR图片识别
行驶证识别
虚拟电话号码
电话呼叫中心软件
怎么制作一个网站
Email注册网站
华为VNC
图像文字识别
企业网站制作
个人网站搭建
华为云计算
免费租用云托管
云桌面云服务器
ocr文字识别免费版
HTTPS证书申请
图片文字识别转换
国外域名注册商
使用免费虚拟主机
云电脑主机多少钱
鲲鹏云手机
短信验证码平台
OCR图片文字识别
SSL证书是什么
申请企业邮箱步骤
免费的企业用邮箱
云免流搭建教程
域名价格
推荐文章
- GaussDB内核_GaussDB数据库内核_高斯数据库内核_华为云
- RDS for MySQL审计日志_开启日志审计_数据库审计_华为云数据库RDS
- GaussDB数据库SQL语法_SQL语法_CREATE_ALTER
- GaussDB下载免费版_GaussDB怎么样_高斯数据库下载
- GaussDB考试_GaussDB数据库考试_高斯数据库考试_华为云
- GaussDB视频教程_gaussdb查看表结构语句_高斯数据库视频教程_华为云
- GaussDB用法_GaussDB数据库使用方法_高斯数据库如何使用_华为云
- 云数据库RDS for MySQL存储空间自动扩容_存储空间_自动扩容_MySQL云盘
- GaussDB使用技巧_高斯数据库下载_高斯数据库使用技巧_华为云
- 云数据库RDS for MySQL版本升级_MySQL版本_升级数据库版本