I think this patch's Command->lines would benefit from using PQExpBuffer (or maybe StringInfo?) for the command string instead of open-coding string manipulation and allocation.
I'm not sure that Command->first_line is really all that useful. It seems we go to a lot of trouble to keep it up to date. Isn't it easier to chop Command->lines at the first newline when it is needed? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services