更改查询需要很长时间

时间:2018-05-15 18:35:16

标签: postgresql locking ddl

我只是尝试在我的数据库中的一个表中添加一列,但这是永远的。

alter table xxx add column frame_weight float;
我环顾四周,似乎可能有锁。我尝试了下面提到的步骤。

select * from pg_locks ;

 locktype  | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction |  pid  |      mode       | granted | fastpath 
-----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-------+-----------------+---------+----------
relation   |    16387 |    60737 |      |       |            |               |         |       |          | 3/136193           | 17977 | AccessShareLock | t       | t
relation   |    16387 |    60748 |      |       |            |               |         |       |          | 3/136193           | 17977 | AccessShareLock | t       | t
relation   |    16387 |    60781 |      |       |            |               |         |       |          | 3/136193           | 17977 | AccessShareLock | t       | t
relation   |    16387 |    60733 |      |       |            |               |         |       |          | 3/136193           | 17977 | AccessShareLock | t       | t
relation   |    16387 |    60774 |      |       |            |               |         |       |          | 3/136193           | 17977 | AccessShareLock | t       | t
virtualxid |          |          |      |       | 3/136193   |               |         |       |          | 3/136193           | 17977 | ExclusiveLock   | t       | t
relation   |    16387 |    11069 |      |       |            |               |         |       |          | 2/4820             | 20752 | AccessShareLock | t       | t
virtualxid |          |          |      |       | 2/4820     |               |         |       |          | 2/4820             | 20752 | ExclusiveLock   | t       | t
relation   |    16387 |    60741 |      |       |            |               |         |       |          | 3/136193           | 17977 | AccessShareLock | t       | f

select * from pg_stat_activity where pid = 17977;

 datid | datname |  pid  | usesysid | usename | application_name | client_addr | client_hostname | client_port |         backend_start         |          xact_start           |          query_start          |         state_change          | waiting | state  | query                                                
-------+---------+-------+----------+---------+------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+---------+--------+--------
 16387 | xx      | 17977 |    16385 | xx      |                  | 127.0.0.1   |                 |       50626 | 2018-05-10 20:13:06.001069-04 | 2018-05-10 20:13:06.251093-04 | 2018-05-10 20:13:06.251369-04 | 2018-05-10 20:13:06.251372-04 | f       | active | SELECT  

select pg_cancel_backend (17977);
pg_cancel_backend 
-------------------
 t
(1 row)

然后我给出了终止命令 -

select pg_terminate_backend (17977);
 pg_terminate_backend 
----------------------
 t
(1 row)

尝试完所有后,alter命令仍然需要很长时间。有人可以建议可能出错的地方吗?

如果您不喜欢这个问题,请不要贬低。只需告诉我,我将删除它。我是一个绝对的初学者,在这个社区的贡献或学习方面,我非常伤心。谢谢!

最佳

0 个答案:

没有答案