一个表无法truncate可是能够rename,这个乍听起来认为好奇怪,以下模拟该过程。

3个session:

session1运行truncate和rename操作。

session2运行lock表操作;

session3进行监控。

 

session1:

[gpadmin@wx60 contrib]$ psql gtlions
psql (8.2.15)
Type "help" for help. gtlions=# \d test
Table "public.test"
Column | Type | Modifiers
--------+------------------------+-----------
id | integer |
name | character varying(200) |
Indexes:
"idxtestid" btree (id)
"idxtestname" btree (name)
Distributed by: (id) gtlions=# select pg_backend_pid();
pg_backend_pid
----------------
1473
(1 row) gtlions=# truncate table test;
Cancel request sent
ERROR: relation "test" does not exist
gtlions=# alter table test rename to test1;
ALTER TABLE

session2:

[gpadmin@wx60 ~]$ psql gtlions
psql (8.2.15)
Type "help" for help. gtlions=# select pg_backend_pid();
pg_backend_pid
----------------
1555
(1 row) gtlions=# begin;
BEGIN
gtlions=# select * from test limit 10;
id | name
-------+------------
19672 | 19672-asfd
19674 | 19674-asfd
19676 | 19676-asfd
19678 | 19678-asfd
19680 | 19680-asfd
19682 | 19682-asfd
19684 | 19684-asfd
19686 | 19686-asfd
19688 | 19688-asfd
19690 | 19690-asfd
(10 rows) gtlions=# end;
COMMIT

session3:

[gpadmin@wx60 ~]$ psql gtlions
psql (8.2.15)
Type "help" for help. gtlions=# select locktype,relation::regclass,pid,mode,granted,gp_segment_id from pg_locks where pid in (1473,1555) order by pid;
locktype | relation | pid | mode | granted | gp_segment_id
----------+----------+-----+------+---------+---------------
(0 rows) gtlions=# select locktype,relation::regclass,pid,mode,granted,gp_segment_id from pg_locks where pid in (1473,1555) order by pid;
locktype | relation | pid | mode | granted | gp_segment_id
---------------+-------------+------+-----------------+---------+---------------
relation | test | 1555 | AccessShareLock | t | -1
relation | idxtestname | 1555 | AccessShareLock | t | -1
transactionid | | 1555 | ExclusiveLock | t | -1
relation | idxtestid | 1555 | AccessShareLock | t | -1
(4 rows) gtlions=# select locktype,relation::regclass,pid,mode,granted,gp_segment_id from pg_locks where pid in (1473,1555) order by pid;
locktype | relation | pid | mode | granted | gp_segment_id
---------------+-------------+------+---------------------+---------+---------------
transactionid | | 1473 | ExclusiveLock | t | -1
relation | test | 1473 | AccessExclusiveLock | f | -1
transactionid | | 1555 | ExclusiveLock | t | -1
relation | idxtestid | 1555 | AccessShareLock | t | -1
relation | idxtestname | 1555 | AccessShareLock | t | -1
relation | test | 1555 | AccessShareLock | t | -1
(6 rows)

-EOF-

Can rename table but can not truncate table的更多相关文章

  1. 14.10.5 Reclaiming Disk Space with TRUNCATE TABLE 回收空间使用TRUNCATE TABLE

    14.10.5 Reclaiming Disk Space with TRUNCATE TABLE 回收空间使用TRUNCATE TABLE 回收操作系统磁盘空间当truncate 一个InnoDB ...

  2. [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table

    Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...

  3. SQL Server 2008 R2——TRUNCATE TABLE 无法截断表 该表正由 FOREIGN KEY 约束引用

    =================================版权声明================================= 版权声明:原创文章 禁止转载  请通过右侧公告中的“联系邮 ...

  4. SQLite - TRUNCATE TABLE

    https://www.tutorialspoint.com/sqlite/sqlite_truncate_table.htm Unfortunately, no TRUNCATE TABLE in ...

  5. TRUNCATE TABLE (Transact-SQL)

    删除表中的所有行,而不记录单个行删除操作. TRUNCATE TABLE 与没有 WHERE 子句的 DELETE 语句类似:但是,TRUNCATE TABLE 速度更快,使用的系统资源和事务日志资源 ...

  6. truncate table语句和delete table语句的区别

    truncate table 表名 ; delete from 表名; 都是用来删除表中所有的记录,前者删除数据后表的标识列会重新开始编号,它比delete语句使用的系统资源和事务日志资源更少,但是表 ...

  7. truncate table和delete table 的区别

    truncate table和不带 where 的 detele 功能一样,都是删除表中的所有数据. 但TRUNCATE TABLE 速度更快,占用的日志更少,这是因为 TRUNCATE TABLE ...

  8. MySQL DELETE语句和TRUNCATE TABLE语句的区别

    MySQL DELETE语句和TRUNCATE TABLE语句的区别 2010-10-08 16:05 佚名 互联网 字号:T | T 在MySQL数据库中,DELETE语句和TRUNCATE TAB ...

  9. SQLSERVER truncate table之后是否会重置表的自增值

    SQLSERVER truncate table之后是否会重置表的自增值 今天清理业务库数据的时候,开发人员说可以使用truncate table把两个表的所有数据清理掉 这两个表都有自增ID,都做了 ...

随机推荐

  1. POJ 3662 Telephone Lines (分层图)

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6785   Accepted: 2498 D ...

  2. 桌面笔记工具KeepNote

    桌面笔记工具KeepNote   在渗透测试过程中,安全人员经常需要记录各种数据,如输出结果.运行截图.测试心得.这类信息格式多样,可能是图片.文字.文件等.为了便于管理这些内容,Kali Linux ...

  3. 【BZOJ 1150】 1150: [CTSC2007]数据备份Backup (贪心+优先队列+双向链表)

    1150: [CTSC2007]数据备份Backup Description 你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份.然而数据备份的工作是枯燥乏味 的,因此你想设 ...

  4. 【数论】【莫比乌斯反演】【线性筛】bzoj2005 [Noi2010]能量采集

    http://blog.csdn.net/Clove_unique/article/details/51089272 Key:1.连接平面上某个整点(a,b)到原点的线段上有gcd(a,b)个整点. ...

  5. <摘录>cocos2d-x 从环境搭建到win32项目移植android平台

    软件:cocos2d-x-2.2.3:android-ndk-r9d:adt-bundle-windows-x86_64-20131030:python-2.7.6: 1安装配置python 安装没什 ...

  6. winform窗体MaximizeBox

    如果MaximizeBox为false会导致Form2窗体底部不显示. =>解决办法TopMost属性为true. Form2 _frm2 = new Form2(); _frm2.Maximi ...

  7. Java之——redis并发读写锁,使用Redisson实现分布式锁

    原文:http://blog.csdn.net/l1028386804/article/details/73523810 1. 可重入锁(Reentrant Lock) Redisson的分布式可重入 ...

  8. Mac OS X 11年9个版本的历经变化

    本月苹果将发布OS X 10.8 Mountain Lion,是Mac OS X系统在其11年生命长河中的第9个版本.2001年,刚从鬼门关爬回来的苹果决定在OS X上做一个赌注,因为他们已经浪费了1 ...

  9. luci框架-LUA的一个web框架使用

    转自:http://blog.csdn.net/initphp/article/details/17527639 LUCI 这个在百度上搜索除了一篇我的百度文库 luci 的介绍文章之外,前三页都是些 ...

  10. JavaScript -- 清除缓存

    在客户端有一个HTML文件,用来提交输入信息,问题在于:每次按刷新时,发觉并不是整个页面重新被装载,好似是缓存中. 因为文本框中仍出现上次输入的值,只有在地址栏中按回车整个页面才重新装载,应当怎样避免 ...