• Tom Lane's avatar
    Make walsenders show their replication commands in pg_stat_activity. · f560209c
    Tom Lane authored
    A walsender process that has executed a SQL command left the text of
    that command in pg_stat_activity.query indefinitely, which is quite
    confusing if it's in RUNNING state but not doing that query.  An easy
    and useful fix is to treat replication commands as if they were SQL
    queries, and show them in pg_stat_activity according to the same rules
    as for regular queries.  While we're at it, it seems also sensible to
    set debug_query_string, allowing error logging and debugging to see
    the replication command.
    
    While here, clean up assorted silliness in exec_replication_command:
    
    * The SQLCmd path failed to restore CurrentMemoryContext to the caller's
    value, and failed to delete the temp context created in this routine.
    It's only through great good fortune that these oversights did not
    result in long-term memory leaks or other problems.  It seems cleaner
    to code SQLCmd as a separate early-exit path, so do it like that.
    
    * Remove useless duplicate call of SnapBuildClearExportedSnapshot().
    
    * replication_scanner_finish() was never called.
    
    None of those things are significant enough to merit a backpatch,
    so this is for HEAD only.
    
    Discussion: https://postgr.es/m/880181.1600026471@sss.pgh.pa.us
    f560209c
walsender.c 103 KB