视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
Canrenametablebutcannottruncatetable
2020-11-09 14:36:42 责编:小采
文档


一个表无法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-

下载本文
显示全文
专题