0

I am running some C++ code in postgresql. I am trying to print some output to keep track of the execution, but no result. Is there anything I need to add somewhere to enable printf command to work? I am adding the below mentioned files in my code:

#include "postgres.h"

#include <math.h>
#include <limits.h>
#include <inttypes.h>

What I am trying to print:

printf("abc");

Any help would be greatly appreciated, as I have been trying to get some output for the past 2 days. Thanks!

Edit : I am running the postgresql server using SSH. Let me know via comments if any more information is needed.

6
  • Printf works for C++ as well. Commented Apr 4, 2014 at 9:53
  • Try printf("abc\n"); Commented Apr 4, 2014 at 10:07
  • yes, trying now. Let u know soon. Commented Apr 4, 2014 at 10:08
  • Nope. No output either. Is there any settings that have to be changed in postgresql to enable output to screen? Commented Apr 4, 2014 at 10:21
  • 2
    check /var/log/postgresql.log or a similar log file for the string abc... if you are running from a stored procedure, that's where the server log is going (probably)... Commented Apr 4, 2014 at 10:25

3 Answers 3

1

You need to use PostgreSQL's build-in logging system: http://www.postgresql.org/docs/current/static/error-message-reporting.html

From the reference:

elog(INFO, "count=%d", count);

The log level has to match the level you've configured PostgreSQL to write to its log file.

Sign up to request clarification or add additional context in comments.

1 Comment

elog is fine for debug tracing, etc. For production quality code that's meant to produce quality error messages, ereport is often preferable.
0

printf("abc"); will try to write to stdout, but normally Postgresql server runs as a daemon, which means it will close stdout, that is why you cannot see that string at the standard output.

You should use the error report facilities offered by Postgresql to output those message to Postgresql log file, as pointed out by @rygvis.

1 Comment

Depending on the server startup, stderr (as opposed to stdout) often goes to the server log file. But it's much, much, much better to use elog and ereport.
0

you can use fprintf(stderr, "abc\n"); instead of printf("abc");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.