0

I'm buliding my own C application on CentOS 5 and postgresql 9.2.

What I'm trying to do is to access shared memory area with shmat function and get the details of pg_stat_activity. I'm not going to use database connection but Direct Memory Access thing.

I've installed gdb and postgresql with source compilation though, I don't know which point I can start with.

Any advice would be appreciated, thanks in advance.

3
  • 2
    First advice: don't do it. Unless you know all about how the PostgreSQL code handles the shared memory, where it gets its definitions from, and how to handle it without interfering with the running DBMS, don't do it. If you do know enough about that, then you probably don't need to ask the question -- you know how to set permissions to be able to connect to the shared memory. Commented Jun 9, 2014 at 16:31
  • 2
    Don't do it. Even if you would succeed, the end product would be very similar to a stripped-down version of the postmaster. An alternative way would be to install a signal handler, and let the CHECK_INTERRUPT (sp?) dump the stuff to a named file or a named pipe. Commented Jun 9, 2014 at 16:50
  • 1
    Thanks Jonathan Leffler for speaking candidly haha. Commented Jun 10, 2014 at 0:29

1 Answer 1

3

First I agree with Jonathan Leffer - when you access a tables (or views) use a query statement - via SPI Server Programming Interface - It is simple, safe, fast, and doesn't consume some additional resources.

If you don't would to use it, look on pg_stat_activity view definition. It is based on calling pg_stat_get_activity function. Source code of this function, can be good start. This function is not too complex as is looking - almost all code is implementation of SRF (Set Returning Functions - function returning table).

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

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.