0

I am new to postgreSQL, just an FYI.

What I want to do: Log my stored procedure errors to a table.

What I want: SP name and parameters at the least, errors that terminate the SP or cause it to malfunction.

What I do not want: Syntax errors, and having to go to a 3rd party(doing logic in code, or output CSV to a file).

Right now I am running SQL server and I have a way to catch errors but it first goes to my code, then to a table and the error handling is not great. I am converting to postgres and want to be able to send the error right to the table without having to go to an 3rd party, and also send the parameters if possible. Does anyone have any info on this or know if its even possible?

Louis Royster
  • 111
  • 1
  • 12
  • 1
    Cannot be done (unless ...) writes/inserts to the log table are part of the transaction, so they will be undone when the transaction is rolled back. – wildplasser Oct 21 '15 at 18:45
  • 2
    It can be done through DBLink because that uses a different transaction, see e.g. here: http://stackoverflow.com/a/25428060/330315 and here: http://postgresql.nabble.com/autonomous-transactions-td1978453.html –  Oct 21 '15 at 18:52
  • Theoretically, if I did use code is this possible then? Also would I be able to pass in the parameters then? – Louis Royster Oct 21 '15 at 18:53

1 Answers1

1

PostgreSQL supports native logging to CSV files, which can be easily imported to database. There's even proposed schema and import command in docs.

Tometzky
  • 22,573
  • 5
  • 59
  • 73
  • Yeah I was trying to get around this and just log straight to the database. After a little research, and a headache it looks like this is going to be the best way to go. – Louis Royster Oct 23 '15 at 12:26