Can rename table but can not truncate table
一个表无法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的更多相关文章
- 14.10.5 Reclaiming Disk Space with TRUNCATE TABLE 回收空间使用TRUNCATE TABLE
14.10.5 Reclaiming Disk Space with TRUNCATE TABLE 回收空间使用TRUNCATE TABLE 回收操作系统磁盘空间当truncate 一个InnoDB ...
- [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table
Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...
- SQL Server 2008 R2——TRUNCATE TABLE 无法截断表 该表正由 FOREIGN KEY 约束引用
=================================版权声明================================= 版权声明:原创文章 禁止转载 请通过右侧公告中的“联系邮 ...
- SQLite - TRUNCATE TABLE
https://www.tutorialspoint.com/sqlite/sqlite_truncate_table.htm Unfortunately, no TRUNCATE TABLE in ...
- TRUNCATE TABLE (Transact-SQL)
删除表中的所有行,而不记录单个行删除操作. TRUNCATE TABLE 与没有 WHERE 子句的 DELETE 语句类似:但是,TRUNCATE TABLE 速度更快,使用的系统资源和事务日志资源 ...
- truncate table语句和delete table语句的区别
truncate table 表名 ; delete from 表名; 都是用来删除表中所有的记录,前者删除数据后表的标识列会重新开始编号,它比delete语句使用的系统资源和事务日志资源更少,但是表 ...
- truncate table和delete table 的区别
truncate table和不带 where 的 detele 功能一样,都是删除表中的所有数据. 但TRUNCATE TABLE 速度更快,占用的日志更少,这是因为 TRUNCATE TABLE ...
- MySQL DELETE语句和TRUNCATE TABLE语句的区别
MySQL DELETE语句和TRUNCATE TABLE语句的区别 2010-10-08 16:05 佚名 互联网 字号:T | T 在MySQL数据库中,DELETE语句和TRUNCATE TAB ...
- SQLSERVER truncate table之后是否会重置表的自增值
SQLSERVER truncate table之后是否会重置表的自增值 今天清理业务库数据的时候,开发人员说可以使用truncate table把两个表的所有数据清理掉 这两个表都有自增ID,都做了 ...
随机推荐
- cobol COMP-3最后1位
"C" hex is positive, "D" hex is negative, and "F" hex is unsigned.
- Python开发基础-Day17面向对象编程介绍、类和对象
面向对象变成介绍 面向过程编程 核心是过程(流水线式思维),过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西.主要应用在一旦完成很少修改的地方,如linux ...
- 最优贸易 NOIP 2009 提高组 第三题
题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 为双向通行的道路 ...
- [BZOJ 1058] 报表统计
Link: BZOJ 1058 传送门 Solution: 为了这道题今天下午一直都在和常数大战…… 1.对于询问1,我们记录每个数末位置的数$T[i]$和初始位置$S[i]$ 用平衡树维护所有差值, ...
- xtuoj 1233 coins(dp)
Coins Accepted : 120 Submit : 305 Time Limit : 1000 MS Memory Limit : 65536 KB Coins Problem Des ...
- 【树形dp】Rebuilding Roads
[POJ1947]Rebuilding Roads Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11934 Accep ...
- [SRM568]DisjointSemicircles
题意:$2n$个位置排成一列,有一些位置已经填了数字($0\cdots n-1$中每个数字出现$0$次或$2$次),问是否存在一种填数方案使得用$n$个不相交的半圆可以把相同的数字连起来 首先把所有已 ...
- 【推导】计蒜客17119 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F. Trig Function
题意:给你n,m,让你求cos(nx)的展开式的(cos(x))^m项的系数. 更一般的式子是这样的:. 队友的代码: #include<cstdio> #include<algor ...
- [转]Spring配置之OpenSessionInViewFilter
参考: OpenSessionInViewFilter作用及配置:http://www.yybean.com/opensessioninviewfilter-role-and-configuratio ...
- Android学习进阶路线导航线路(Android源码分享)
转 ...