简体   繁体   English

postgres ALTER TABLE被阻止

[英]postgres ALTER TABLE being blocked

Im running Postgres 8.3 and I am having trouble running AN ALTER TABLE ADD COLUMN statement which seems to be blocked by an AccessShareLock when I run this query 我正在运行Postgres 8.3,但在运行ALTER TABLE ADD COLUMN语句时遇到问题,当我运行此查询时,该语句似乎被AccessShareLock阻止

SELECT t.relname,l.locktype,page,virtualtransaction,pid,mode,granted FROM pg_locks l, pg_stat_all_tables t WHERE l.relation=t.relid ORDER BY relation asc;

The table's name is dealer. 该表的名称是经销商。

    relname      | locktype | page | virtualtransaction |  pid  |        mode         | granted
dealer           | relation |      | 2/40               | 12719 | AccessExclusiveLock | f
dealer           | relation |      | -1/154985751       |       | AccessShareLock     | t

I also ran 我也跑了

SELECT * FROM pg_prepared_xacts    

That returned 那回来了

transaction |                                             gid                                              |           prepared            |  owner   |      database      
  154985751 | 131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM= | 2014-09-19 08:01:49.650957+10 | user     | database

The transaction id 154985751 looks similar to the virtualtransaction in the pg_locks table -1/154985751 事务ID 154985751看起来类似于pg_locks表-1/154985751中的virtualtransaction

I ran this command to view any processes that may be running queries on the database 我运行了此命令以查看可能正在数据库上运行查询的所有进程

ps axu | grep postgres | grep -v idle 

and have confirmed there are no other processes running queries on the database. 并确认没有其他进程在数据库上运行查询。

The log file shows this after the query has been run 查询运行后,日志文件显示此内容

2014-11-14 17:25:00.794 EST (pid: 12719) LOG:  statement: BEGIN;
2014-11-14 17:25:00.794 EST (pid: 12719) LOG:  statement: ALTER TABLE dealer ADD bullet1 varchar;
2014-11-14 17:25:01.795 EST (pid: 12719) LOG:  process 12719 still waiting for AccessExclusiveLock on relation 2321398 of database 2321293 after 1000.133 ms
2014-11-14 17:25:01.795 EST (pid: 12719) STATEMENT:  ALTER TABLE dealer ADD bullet1 varchar;

What could be causing the AccessShareLock on the dealer table? 是什么原因导致发牌人桌上的AccessShareLock? Im guessing it has something to do with the transaction 154985751 is there a way to terminate a transaction with using the virtual id? 我猜测它与事务有关154985751是否可以使用虚拟ID终止事务?

You have a prepared transaction in place. 您已准备好交易。 Prepared transactions - those where PREPARE TRANSACTION but not COMMIT PREPARED or ROLLBACK PREPARED has been run - hold locks, just like normal running transactions do. 准备的事务-已运行“ COMMIT PREPARED PREPARE TRANSACTION但未执行“ COMMIT PREPARED或“ ROLLBACK PREPARED事务-保持锁定,就像正常运行的事务一样。

Prepared transactions may be used by XA transaction managers, JTA, etc, not necessarily directly by your app. XA事务管理器,JTA等可以使用预准备的事务,而您的应用不必直接使用。 Many queuing systems use them too. 许多排队系统也使用它们。 If you don't know what the transaction is and you commit it or roll it back you may disrupt something that is relying on two-phase commit. 如果您不知道事务是什么,然后提交或回滚它,则可能会破坏依赖于两阶段提交的事务。


If you are certain that you know what it is you can: 如果您确定自己知道这是什么,则可以:

COMMIT PREPARED '131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM='

or 要么

ROLLBACK PREPARED '131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM='

depending on whether you wish to commit or abort the prepared xact. 取决于您是要提交还是中止准备好的xact。

You can't inspect the transaction to see what it did/does, you need to figure out what app/tool created it and why if you don't know what it is. 您无法检查事务以查看其执行的操作,您需要弄清楚是什么应用程序/工具创建了它,以及为什么不知道它是什么。


The identifier looks suspiciously like [number]_[base64]_[base64] so lets see what we can do with that: 标识符看起来像[number]_[base64]_[base64]一样可疑,因此让我们看看该怎么做:

postgres=> SELECT decode((string_to_array('131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM=','_'))[2], 'base64');
                              decode                              
------------------------------------------------------------------
 \x312d613332303361373a623032333a35343130663433313a31633565383939
(1 row)

postgres=> SELECT decode((string_to_array('131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM=','_'))[3], 'base64');
                            decode                            
--------------------------------------------------------------
 \x613332303361373a623032333a35343130663433313a31633565383963
(1 row)

Hm, looks like ASCII or similar, lets see: 嗯,看起来像ASCII或类似的东西,让我们看看:

postgres=> SELECT convert_from(decode((string_to_array('131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM=','_'))[2], 'base64'), 'utfpostgres=> SELECT convert_from(decode((string_to_array('131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM=','_'))[2], 'base64'), 'utf-8');
          convert_from           
---------------------------------
 1-a3203a7:b023:5410f431:1c5e899
(1 row)

postgres=> SELECT convert_from(decode((string_to_array('131075_MS1hMzIwM2E3OmIwMjM6NTQxMGY0MzE6MWM1ZTg5OQ==_YTMyMDNhNzpiMDIzOjU0MTBmNDMxOjFjNWU4OWM=','_'))[3], 'base64'), 'utf-8');
         convert_from          
-------------------------------
 a3203a7:b023:5410f431:1c5e89c
(1 row)

Looks vaguely GUID/UUID-ish, with odd formatting and grouping. 看起来含糊不清GUID / UUID-ish,带有奇数格式和分组。

Maybe those identifiers will help you figure out where the xact came from. 也许这些标识符可以帮助您确定xact的来源。


BTW, 8.3 is exceedingly obsolete. 顺便说一句,8.3已经过时了。 Plan your upgrade. 计划升级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM