Skip to content

docs(postgraphile): document how to view PostgreSQL notices - #3207

Open
cpruijsen wants to merge 4 commits into
graphile:mainfrom
cpruijsen:fix/issue-3040
Open

cpruijsen wants to merge 4 commits into
graphile:mainfrom
cpruijsen:fix/issue-3040

Conversation

@cpruijsen

Copy link
Copy Markdown

Add a PostgreSQL notice example to
postgraphile/website/postgraphile/debugging.md.
The example shows how to see raise notice messages from PL/pgSQL functions
on the server. It attaches a notice listener to each new pool client and
passes the pool to makePgService.
It also handles pool and client connection errors.

The warning tells the caller to release the pool.
When the caller supplies a pool, makePgService ignores connection options.

PostgreSQL connection termination checks failed without the error handlers and
passed with both handlers.

Fixes #3040.

@changeset-bot

changeset-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ce361cc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@benjie

benjie commented Oct 14, 2026

Copy link
Copy Markdown
Member

An easier approach might be to use DEBUG=@dataplan/pg:PgExecutor - this will output notices alongside queries and results.

@cpruijsen

Copy link
Copy Markdown
Author

I made DEBUG=@dataplan/pg:PgExecutor the first approach, with a link to the existing DEBUG section. It logs a NOTICES section for each query. I kept a shorter pg.Pool notice listener as the option for handling notices in code.

@benjie

benjie commented Oct 19, 2026

Copy link
Copy Markdown
Member

Great! When it comes to handling them in code, note that PgExecutor makes available notices as part of PgClientResult, so depending on where/how this is to be used it might make sense to use that rather than doing a listener that requires a specific postgres adaptor (pg module, in this case).

/**
* Any non-exception server messages (e.g. RAISE NOTICE/INFO/WARNING).
* Empty if none were raised.
*/
notices?: readonly PgNotice[];

Comment on lines +242 to +245
pool.on("error", (error) => console.error(error));
pool.on("connect", (client) => {
client.on("error", (error) => console.error(error));
client.on("notice", (msg) => console.dir(msg));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend making these console statements more useful - include more context. Having random objects output without context can be confusing and hard to debug.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ce361cc. Each handler now logs a label, and a notice prints as PostgreSQL NOTICE: <message> (<where>). I also point to notices on PgClientResult first, since it does not depend on the adaptor.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: indicate how to debug notices from postgres

2 participants