Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a PostgreSQL equivalent of SQL Server profiler?

I need to see the queries submitted to a PostgreSQL server. Normally I would use SQL Server profiler to perform this action in SQL Server land, but I'm yet to find how to do this in PostgreSQL. There appears to be quite a few pay-for tools, I am hoping there is an open source variant.

like image 665
BozoJoe Avatar asked Mar 12 '10 03:03

BozoJoe


People also ask

Does PostgreSQL have a profiler?

Query Profiler functionality helps trace, recreate, and troubleshoot problems in PostgreSQL Server. With the PostgreSQL Profiler tool, you can quickly and easily identify productivity bottlenecks and thus boost your database performance.

What replaced SQL Profiler?

A new hope: The Extended Events (XE) XE will replace the SQL Profiler in the future versions. By the moment, SQL Server includes Profiler and XE. The XEs is a feature included in SQL Server 2008.


2 Answers

You can use the log_statement config setting to get the list of all the queries to a server

https://www.postgresql.org/docs/current/static/runtime-config-logging.html#guc-log-statement

Just set that, and the logging file path and you'll have the list. You can also configure it to only log long running queries.

You can then take those queries and run EXPLAIN on them to find out what's going on with them.

https://www.postgresql.org/docs/9.2/static/using-explain.html

like image 171
Joshua Smith Avatar answered Oct 21 '22 05:10

Joshua Smith


Adding to Joshua's answer, to see which queries are currently running simply issue the following statement at any time (e.g. in PGAdminIII's query window):

SELECT datname,procpid,current_query FROM pg_stat_activity; 

Sample output:

     datname    | procpid | current_query  ---------------+---------+---------------   mydatabaseabc |    2587 | <IDLE>   anotherdb     |   15726 | SELECT * FROM users WHERE id=123 ;   mydatabaseabc |   15851 | <IDLE>  (3 rows) 
like image 21
vladr Avatar answered Oct 21 '22 07:10

vladr