Sample Header Ad - 728x90

Monitoring the Postgres query parser

6 votes
1 answer
2873 views
As I understand it, when you send a query to Postgres like: SELECT id FROM table1 WHERE name = $1; Postgres will create a query plan. The plan will be cached for the same query in the same session. But if you create a function: CREATE OR REPLACE FUNCTION get_table1 (parname text) RETURNS bigint LANGUAGE plpgsql AS $$BEGIN RETURN (SELECT id FROM table1 where name = parname); END$$; The query plan will be cached for all future sessions. I'd like to verify this theory by checking how often the query analyzer is invoked. Is there a way to inspect the number of times Postgres parses a query? If possible, I'd like to monitor things like #parses per second and the min/max/avg parse duration.
Asked by Andomar (3515 rep)
Dec 19, 2014, 02:50 PM
Last activity: Jul 17, 2023, 10:35 PM