yesodweb / yesodweb/persistent

Handle postgres notices

Open
#1,173 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

It seems like libpq by default sends notices to the terminal, which leads to a lot of logs, e.g. in testing:

NOTICE:  drop cascades to 2 other objects
DETAIL:  drop cascades to table person
drop cascades to table post

postgresql-libpq provides enableNoticeReporting/disableNoticeReporting, but they operate on postgresql-libpq's Connection type, which withPostgresqlPool (and co) don't directly expose.

A workaround would be to call postgresql-simple.connect directly and call disableNoticeReporting and use openSimpleConn, but it doesn't seem straightforward to get back a Pool SqlBackend.

The approach that makes the most sense to me is to use the MonadLogger instance and send notice reportings through the logger function. Something like

open' modConn getVer cstr logFunc = do
    conn <- PG.connectPostgreSQL cstr

    {- add this -}
    enableNoticeReporting conn
    let noticeLoop = getNotice conn >>= \case
            Just bs -> logFunc ... bs >> noticeLoop
            Nothing -> return ()
    forkIO noticeLoop
    {- end -}

    modConn conn
    ver <- getVer conn
    smap <- newIORef $ Map.empty
    return $ createBackend logFunc ver smap conn

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the PostgreSQL backend entry points around withPostgresqlPool, open', and createBackend, then read how the MonadLogger function is passed through connection setup. Review the postgresql-libpq notice APIs and determine how notices should reach the logger without being printed to the terminal. Done means notices are handled through the logger while pooled connections continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, postgresql
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.