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,都做了 ...
随机推荐
- Java-并发入门
本文由@呆代待殆原创,转载请注明出处:http://www.cnblogs.com/coffeeSS/ Java中实现多线程的方法 实现Runnable接口 实现Runnable接口里的run()方法 ...
- Redux 中间件的执行顺序理解
Redux.applyMiddleware(thunk, middleware1) 和 Redux.applyMiddleware(middleware1, thunk) 的区别: <!DOCT ...
- Graph Valid Tree -- LeetCode
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- HDU 6040 Hints of sd0061(nth_element)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...
- [ARC103F]Distance Sums
题意:有一棵树,对于每个点$i$,给出了它到其他点的距离和$i$,现在要还原这棵树,保证$d_i$两两不同 一个点从$u$移到相邻节点$v$时,若删掉$(u,v)$后$u$这边的连通块大小为$siz_ ...
- 【Splay】【启发式合并】hdu6133 Army Formations
题意:给你一颗树,每个结点的儿子数不超过2.每个结点有一个权值,一个结点的代价被定义为将其子树中所有结点的权值放入数组排序后,每个权值乘以其下标的和.让你计算所有结点的代价. 二叉树的条件没有用到. ...
- 【贪心】【set】zoj3963 Heap Partition
贪心地从前往后扫,每到一个元素,就查看之前的元素中小于等于其的最大的元素是否存在,如果存在,就将它置为其父亲.如果一个结点已经是两个儿子的父亲了,就不能在set中存在了,就将他删除.如果然后将当前元素 ...
- Learning Note: SQL Server VS Oracle–Database architecture
http://www.sqlpanda.com/2013/07/learning-note-sql-server-vs.html This is my learning note base on t ...
- java界面编程(3) ------ 控制布局
本文是自己学习所做笔记,欢迎转载,但请注明出处:http://blog.csdn.net/jesson20121020 在java 中,组件放置在窗口上的方式可能与其它的GUI系统都不同样.首先,它全 ...
- 二、ELKStack集群架构设计
一.ELKStack介绍与入门实践 二.Elasticsearch 集群架构图 服务器配置:Centos6.6 x86_64 CPU:1核心 MEM:2G (做实验,配置比较低一些) 注:这里配置el ...