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,都做了 ...
随机推荐
- “玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)
“玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-0 ...
- 服务器Tomcat WAS JBoss
做任何web项目,都离不开服务器,有钱的公司用WebSphere.WebLogic,没钱公司用nginx+tomcat,不要小瞧nginx+tomcat麻雀虽小,五脏俱全. 服务器的知识,在笔试.面试 ...
- Number Sequence HDU - 5014
There is a special number sequence which has n+1 integers. For each number in sequence, we have two ...
- 2016ACM-ICPC网络赛北京赛区 1001 (trie树牌大模拟)
[题目传送门] 1383 : The Book List 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The history of Peking University ...
- [CF340D]Bubble Sort Graph/[JZOJ3485]独立集
题目大意: 给你一个序列,对序列中所有逆序对之间连一条边,问图中最大独立集为多大,有哪些点一定在最大独立集中. 思路: 在纸上画一下发现最大独立集一定是元序列的一个LIS,最大独立集必经点就是所有LI ...
- Problem A: 零起点学算法80——逆序输出(数组练习)
#include<stdio.h> int main() { ]; scanf("%d",&n); ;i<=n;i++){ scanf("%d& ...
- 消除Xcode 5中JosnKit类库的bit masking for introspection of objective-c 警告
Xcode 5中苹果对多个系统框架及相关类库进行了改进.之前建立的项目在Xcode 5中重新编译会产生一些新问题. JosnKit是常用的轻量级Josn解析类,在Xcode 5中: BOOL work ...
- Web安全测试指南--信息泄露
5.4.1.源代码和注释: 编号 Web_InfoLeak_01 用例名称 源代码和注释检查测试 用例描述 在浏览器中检查目标系统返回的页面是否存在敏感信息. 严重级别 中 前置条件 1. 目标we ...
- Oracle10g 创建一个DataBase实例
Oracle10g创建DataBase实例如下:第一步:Oracle - OraDb10g_home1 -> 配置和移植工具 -> 打开Database Configuration Ass ...
- Java中设置classpath、path、JAVA_HOME的作用?
1.classpath是用来找编译后的class文件的,操作系统或者编译器等会在这些目录下寻找对应的.class文件 2.path时用来找命令行执行文件的,操作系统或者其他软件会在这些目录下找对应的命 ...