热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

Canrenametablebutcannottruncatetable

一个表无法truncate但是可以rename,这个乍听起来觉得好奇怪,下面模拟该过程。3个session:session1执行truncate和rename操作;session2执行lock表操作;session3进行监控。session1:[gpadmin@wx60contrib]$psqlgtlionspsql(8.2.15)Typehelpfor

一个表无法truncate但是可以rename,这个乍听起来觉得好奇怪,下面模拟该过程。 3个session: session1执行truncate和rename操作; session2执行lock表操作; session3进行监控。 session1: [gpadmin@wx60 contrib]$ psql gtlionspsql (8.2.15)Type help for

一个表无法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-
推荐阅读
author-avatar
ah_落落_181
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有