question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

notice / notification logging from PostgreSQL is not working

See original GitHub issue

Issue Description

Im trying to use afterConnect hook to intercept notice and notiification events from a PostgreSQL database

What are you doing?

const config = {
  username: 'username',
  password: 'password',
  database: 'database',
  host: 'host',
  dialect: 'postgres',
  logging: true,
  pool: {
    max: 1,
    min: 1,
    acquire: 30000,
    idle: 10000
  }
}

const sequelize = new Sequelize(config);

sequelize.addHook('afterConnect', (client) => {
  //never fired
  client.on('notice', msg => {
    console.log('notice:', msg)
  })
  //never fired
  client.on('notification', msg => {
    console.log(msg.channel)
    console.log(msg.payload)
  })
});

await sequelize.query('any query that triggers a notice or notification');

What do you expect to happen?

I wanted to the notice or notification event called at least once

What is actually happening?

The events are never fired

No output

Additional context

Add any other context or screenshots about the feature request here.

Environment

  • Sequelize version: sequelize@5.19.4
  • Node.js version: v9.11.1
  • Operating System: Ubuntu 16.04

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s): pg@7.12.1
  • I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don’t know how to start, I would need guidance.
  • No, I don’t have the time, although I believe I could do it if I had the time…
  • No, I don’t have the time and I wouldn’t even know how to start.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gv-beeminingcommented, Oct 10, 2019

@gv-beemining Looking at it’s log output, looks like indeed your console.logs didn’t run. Are you sure they would work with the connector library directly (i.e. without sequelize)?

yes, i tried without sequelize, the library in this case is pg (example code):

 const client = new `Client()
    client.on('notice', msg => console.warn('notice:', msg))
    client.on('notification', msg => {
      console.log(msg.channel) 
      console.log(msg.payload)  
    })
    await client.connect();
    await client.query("DO language plpgsql $$ BEGIN RAISE NOTICE 'hello, world!'; END $$;");

in this snippet the console.log actually run

1reaction
gv-beeminingcommented, Oct 10, 2019

repo query updated, tests passed, Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL: Documentation: 15: NOTIFY
The NOTIFY command sends a notification event together with an optional “payload” string to each client application that has previously executed LISTEN channel ......
Read more >
Raise NOTICE, Raise INFO not saved to logs in POSTGRES
My intention here is to store the notice , info from this procedure to postgres logs (txt files) that are stored in the...
Read more >
Not able to print raise notice output in log file tried with all ...
1 Answer 1 · Its working but its not printing result in log file like if I am giving \o \tmp\Logfile. · @SamirMjs...
Read more >
PostgreSQL Logs Explained: Logging Configuration Tutorial
NOTICE : Offers useful information to users like identifier truncation; WARNING: Delivers warnings of likely problems; ERROR: Registers errors, ...
Read more >
PostgreSQL LISTEN/NOTIFY
It's possible for our trigger to notify an external client. ... commit log is serialized, so there's no extra work for PostgreSQL here....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found