今天这篇贴子讲述的问题我以前也遇到过,只因发生在一测试环境下,所以没有深究,今天在一生产环境下也遇到了这个问题,所以应该重视了,这个问题困扰了我一阵子,事情是这样的,在生产库上有一个 SQL 非常奇怪,从SQL语句来看,很像是PostgreSQL SERVER 内部执行的,可事实却不是,下面看下今天的分析步骤。
查询数据库会话
连接到数据库里查询,如下:
1 2 3 4 5 6 7 8 9 10
postgres=# select procpid,datname,client_addr,client_port,current_query from pg_stat_activity where current_query !='<IDLE>'; 25858 | uims | XXX.XXX.XXX.XXX | 57791 | SELECTNULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME, CASE n.nspname ~ '^pg_' OR n.nspname = 'information_schema' WHENtrueTHENCASEWHEN n.nspname = 'pg_catalog' OR n.nspname = 'info rmation_schema' THENCASE c.relkind WHEN'r' THEN'SYSTEM TABLE' WHEN'v' THEN'SYSTEM VIEW' WHEN'i' THEN'SYSTEM INDEX' EL SE NULLENDWHEN n.nspname = 'pg_toast' THENCASE c.relkind WHEN'r' THEN'SYSTEM TOAST TABLE' WHEN'i' THEN'SYSTEM TOAST IN DEX' ELSENULLENDELSECASE c.relkind WHEN'r' THEN'TEMPORARY TABLE' WHEN'i' THEN'TEMPORARY INDEX' ELSENULLEND E ND WHENfalseTHENCASE c.relkind WHEN'r' THEN'TABLE' WHEN'i' THEN'INDEX' WHEN'S' THEN'SEQUENCE' WHEN'v' THEN'VIEW' EL SE NULLENDELSENULLEND AS TABLE_TYPE, d.description AS REMARKS FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c LEFT J OIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class')
SELECTNULLAS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME, CASE n.nspname ~ '^pg_'OR n.nspname = 'information_schema' WHENtrueTHEN CASE WHEN n.nspname = 'pg_catalog'OR n.nspname = 'information_schema'THEN CASE c.relkind WHEN'r'THEN'SYSTEM TABLE' WHEN'v'THEN'SYSTEM VIEW' WHEN'i'THEN'SYSTEM INDEX' ELSENULL END WHEN n.nspname = 'pg_toast'THEN CASE c.relkind WHEN'r'THEN'SYSTEM TOAST TABLE' WHEN'i'THEN'SYSTEM TOAST INDEX' ELSENULL END ELSE CASE c.relkind WHEN'r'THEN'TEMPORARY TABLE' WHEN'i'THEN'TEMPORARY INDEX' ELSENULL END END WHENfalseTHEN CASE c.relkind WHEN'r'THEN'TABLE' WHEN'i'THEN'INDEX' WHEN'S'THEN'SEQUENCE' WHEN'v'THEN'VIEW' ELSENULL END ELSENULL ENDAS TABLE_TYPE, d.description AS REMARKS FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c LEFTJOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) LEFTJOIN pg_catalog.pg_class dc ON (d.classoid = dc.oid AND dc.relname='pg_class');