Thread

  1. postgres_fdw: restore_stats uses current user's mapping instead of table owner's during ANALYZE

    Fujii Masao <masao.fujii@gmail.com> — 2026-05-14T14:30:13Z

    Hi,
    
    I found that ANALYZE on a foreign table with postgres_fdw uses different user
    mappings depending on the restore_stats option. When restore_stats is disabled,
    it uses the foreign table owner's user mapping to sample remote data. However,
    when restore_stats is enabled, it instead uses the user mapping of the role
    running ANALYZE to fetch remote statistics.
    
    As a result, ANALYZE can fail with "user mapping not found" for users who are
    allowed to analyze the foreign table but do not have their own user mapping,
    even if the table owner has a valid one. Using different mappings depending on
    restore_stats also seems confusing and inconsistent to me.
    
    Was this behavior intentional?
    
    The attached patch fixes this by making ANALYZE always use the foreign table
    owner's user mapping, regardless of the restore_stats setting. It also adds
    regression tests covering both restore_stats enabled and disabled cases.
    
    Thoughts?
    
    Regards,
    
    -- 
    Fujii Masao