首页 / 数据库 / MySQL / PostgreSQL锁查询与杀掉进程说明
查询表中存在的锁select a.locktype,a.database,a.pid,a.mode,a.relation,b.relnamefrom pg_locks ajoin pg_class b on a.relation = b.oidwhere upper(b.relname) = "TABLE_NAME";以上为查询某表上是否存在锁的SQL语句。查到后发现确实存在锁,如下: locktype | database | pid | mode | relation | relname----------+----------+-------+-----------------+----------+--------- relation | 439791 | 26752 | AccessShareLock | 2851428 |table_name relation | 439791 | 26752 | ExclusiveLock | 2851428 |table_name再根据上面查出来的pid去表pg_stat_activity查询一下该锁对应的SQL语句:select usename,current_query ,query_start,procpid,client_addr from pg_stat_activity where procpid=17509;如下: usename | current_query | query_start | procpid | client_addr -----------+---------------------------------------------------------------------------------------------------------------+-------------------------------+---------+---------------- gpcluster | DELETE FROM TABLE_NAME WHERE A = 1 | 2011-05-14 09:35:47.721173+08 | 17509 | 192.168.165.18(1 row)通过以上可以发现,就是上面的锁导致该语句一直挂在那里。然后把该锁结束掉后,应用很快跑完。然后核查应用的代码,发现代码里面两个事务都没有提交操作。后增加提交操作后,重新跑数,很快跑完。如果要杀死,首先向相关人员确认这个语句是否为关键进程。杀掉方法:在PG数据库mydb服务器中,查询这个进程PID然后Kill掉。> ps -ef|grep 17509postgres 17509 4868 1 Nov18 ? 00:11:19 postgres: postgres mydb 192.168.165.18(56059) SELECT postgres 30832 30800 0 15:18 pts/3 00:00:00 grep 17509> ps -ef|grep 17509postgres 17509 4868 1 Nov18 ? 00:11:19 postgres: postgres mydb 192.168.165.18(56059) SELECT postgres 30838 30800 0 15:19 pts/3 00:00:00 grep 17509> kill -9 17509------------------------------------华丽丽的分割线------------------------------------CentOS 6.3环境下yum安装PostgreSQL 9.3 http://www.linuxidc.com/Linux/2014-05/101787.htmPostgreSQL缓存详述 http://www.linuxidc.com/Linux/2013-07/87778.htmWindows平台编译 PostgreSQL http://www.linuxidc.com/Linux/2013-05/85114.htmUbuntu下LAPP(Linux+Apache+PostgreSQL+PHP)环境的配置与安装 http://www.linuxidc.com/Linux/2013-04/83564.htmUbuntu上的phppgAdmin安装及配置 http://www.linuxidc.com/Linux/2011-08/40520.htmCentOS平台下安装PostgreSQL9.3 http://www.linuxidc.com/Linux/2014-05/101723.htmPostgreSQL配置Streaming Replication集群 http://www.linuxidc.com/Linux/2014-05/101724.htm如何在CentOS 7/6.5/6.4 下安装PostgreSQL 9.3 与 phpPgAdmin http://www.linuxidc.com/Linux/2014-12/110108.htm------------------------------------华丽丽的分割线------------------------------------PostgreSQL 的详细介绍:请点这里
PostgreSQL 的下载地址:请点这里本文永久更新链接地址