Обсуждение: C function extending postgres

Поиск
Список
Период
Сортировка

C function extending postgres

От
Theo Galanakis
Дата:
<p><font face="Arial" size="2">#include "postgres.h"</font><br /><font face="Arial" size="2">#include
"fmgr.h"</font><br/><font face="Arial" size="2">#include "proc.h"</font><p><font face="Arial"
size="2">PG_FUNCTION_INFO_V1(get_process_total);</font><p><fontface="Arial" size="2">Datum</font><br /><font
face="Arial"size="2">get_process_total(PG_FUNCTION_ARGS)</font><br /><font face="Arial" size="2">{</font><br />       
<fontface="Arial" size="2">float ret;</font><br />        <font face="Arial" size="2">ret = proc_cpu_user() +
proc_cpu_nice()+ proc_cpu_system() - proc_cpu_idle();</font><br />        <font face="Arial"
size="2">PG_RETURN_FLOAT4(ret);</font><br/><font face="Arial" size="2">}</font><p><font face="Arial" size="2">Hi
,</font><p>       <font face="Arial" size="2">I'm getting the following error when attempting to call the above
function,I have included the -I path when compiling, and have compiled a similar function to execute and printf to
linuxwithout a problem :</font><p><font face="Arial" size="2">Returned by postgres:</font><br />        <br />       
<fontface="Arial" size="2">ERROR:  could not load library "/usr/lib/pgsql/processinfo.so":
/usr/lib/pgsql/processinfo.so:undefined symbol: proc_cpu_idle</font><p><font face="Arial" size="2">Compiling:</font><br
/>       <font face="Arial" size="2">cc -g -I /usr/local/pgsql/include -I /usr/local/pgsql/include/server -I
/usr/local/include-fpic -c processinfo.c</font><p>        <font face="Arial" size="2">cc -g -I /usr/local/pgsql/include
-I/usr/local/pgsql/include/server -I /usr/local/include -shared -o processinfo.so processinfo.o</font><p><font
face="Arial"size="2">Here is the postgres create function:</font><br /><font face="Arial" size="2">CREATE FUNCTION
get_process_total()RETURNS float4</font><br /><font face="Arial" size="2">    AS '$libdir/processinfo',
'get_process_total'</font><br/><font face="Arial" size="2">LANGUAGE 'c' STABLE STRICT;</font><p><font face="Arial"
size="2">TEST:</font><br/><font face="Arial" size="2">select * from get_process_total()</font><p><font face="Arial"
size="2">Yourhelp would be greatly appreciated.</font><p><font face="Arial" size="2">Theo</font><table><tr><td
bgcolor="#ffffff"><fontcolor="#000000">______________________________________________________________________<br />
Thisemail, including attachments, is intended only for the addressee<br /> and may be confidential, privileged and
subjectto copyright. If you<br /> have received this email in error, please advise the sender and delete<br /> it. If
youare not the intended recipient of this email, you must not<br /> use, copy or disclose its content to anyone. You
mustnot copy or <br /> communicate to others content that is confidential or subject to <br /> copyright, unless you
havethe consent of the content owner.<br /></font></td></tr></table> 

Re: C function extending postgres

От
Jonathan Daugherty
Дата:
#     ERROR:  could not load library "/usr/lib/pgsql/processinfo.so":
# /usr/lib/pgsql/processinfo.so: undefined symbol: proc_cpu_idle

My guess that you're not linking against the library that containts
'proc_cpu_idle' when you build your .so.  What's the build platform?

--  Jonathan Daugherty Command Prompt, Inc. - http://www.commandprompt.com/ PostgreSQL Replication & Support Services,
(503)667-4564
 


Re: C function extending postgres

От
Theo Galanakis
Дата:
<p><font size="2">Thanks for your feedback.</font><p><font size="2">I'm actually trying to use a system metrics library
from<a href="http://www-usr.inf.ufsm.br/~veiga/liblproc/index-en.html"
target="_blank">http://www-usr.inf.ufsm.br/~veiga/liblproc/index-en.html</a></font><p><fontsize="2">I have tried to
linkthe library however I'm still getting the same message.</font><p><font size="2">cc -g -I /usr/local/pgsql/include
-I/usr/local/pgsql/include/server -I /usr/local/include -fpic -c processinfo.c</font><br /><font size="2">cc -g -I
/usr/local/pgsql/include-I /usr/local/pgsql/include/server -I /usr/local/include -shared -llproc -Wall
-L/usr/local/include/-o processinfo.so processinfo.o</font><br /><br /><p><font size="2">-----Original
Message-----</font><br/><font size="2">From: Jonathan Daugherty [<a
href="mailto:cygnus@cprogrammer.org">mailto:cygnus@cprogrammer.org</a>]</font><br /><font size="2">Sent: Tuesday, 22
March2005 11:21 AM</font><br /><font size="2">To: pgsql-sql@postgresql.org</font><br /><font size="2">Subject: Re:
[SQL]C function extending postgres</font><br /><p><font size="2">#       ERROR:  could not load library
"/usr/lib/pgsql/processinfo.so":</font><br/><font size="2"># /usr/lib/pgsql/processinfo.so: undefined symbol:
proc_cpu_idle</font><p><fontsize="2">My guess that you're not linking against the library that containts
'proc_cpu_idle'when you build your .so.  What's the build platform?</font><p><font size="2">-- </font><br /><font
size="2"> Jonathan Daugherty</font><br /><font size="2">  Command Prompt, Inc. - <a
href="http://www.commandprompt.com/"target="_blank">http://www.commandprompt.com/</a></font><br /><font size="2"> 
PostgreSQLReplication & Support Services, (503) 667-4564</font><p><font size="2">---------------------------(end of
broadcast)---------------------------</font><br/><font size="2">TIP 5: Have you checked our extensive
FAQ?</font><p><fontsize="2">               <a href="http://www.postgresql.org/docs/faq"
target="_blank">http://www.postgresql.org/docs/faq</a></font><table><tr><tdbgcolor="#ffffff"><font
color="#000000">______________________________________________________________________<br/> This email, including
attachments,is intended only for the addressee<br /> and may be confidential, privileged and subject to copyright. If
you<br/> have received this email in error, please advise the sender and delete<br /> it. If you are not the intended
recipientof this email, you must not<br /> use, copy or disclose its content to anyone. You must not copy or <br />
communicateto others content that is confidential or subject to <br /> copyright, unless you have the consent of the
contentowner.<br /></font></td></tr></table> 

Re: C function extending postgres

От
Jonathan Daugherty
Дата:
# I'm actually trying to use a system metrics library from
# http://www-usr.inf.ufsm.br/~veiga/liblproc/index-en.html

Have you added the path of the lproc library to your /etc/ld.so.conf?

--  Jonathan Daugherty http://www.parsed.org


Re: C function extending postgres

От
Theo Galanakis
Дата:
<p><font size="2">Sorted Jonathan, thankyou for your help.</font><p><font size="2">-----Original Message-----</font><br
/><fontsize="2">From: Jonathan Daugherty [<a href="mailto:cygnus@cprogrammer.org">mailto:cygnus@cprogrammer.org</a>]
</font><br/><font size="2">Sent: Tuesday, 22 March 2005 4:32 PM</font><br /><font size="2">To:
pgsql-sql@postgresql.org</font><br/><font size="2">Subject: Re: [SQL] C function extending postgres</font><br
/><p><fontsize="2"># I'm actually trying to use a system metrics library from</font><br /><font size="2"># <a
href="http://www-usr.inf.ufsm.br/~veiga/liblproc/index-en.html"
target="_blank">http://www-usr.inf.ufsm.br/~veiga/liblproc/index-en.html</a></font><p><fontsize="2">Have you added the
pathof the lproc library to your /etc/ld.so.conf?</font><p><font size="2">-- </font><br /><font size="2">  Jonathan
Daugherty</font><br/><font size="2">  <a href="http://www.parsed.org"
target="_blank">http://www.parsed.org</a></font><p><fontsize="2">---------------------------(end of
broadcast)---------------------------</font><br/><font size="2">TIP 2: you can get off all lists at once with the
unregistercommand</font><br /><font size="2">    (send "unregister YourEmailAddressHere" to
majordomo@postgresql.org)</font><table><tr><tdbgcolor="#ffffff"><font
color="#000000">______________________________________________________________________<br/> This email, including
attachments,is intended only for the addressee<br /> and may be confidential, privileged and subject to copyright. If
you<br/> have received this email in error, please advise the sender and delete<br /> it. If you are not the intended
recipientof this email, you must not<br /> use, copy or disclose its content to anyone. You must not copy or <br />
communicateto others content that is confidential or subject to <br /> copyright, unless you have the consent of the
contentowner.<br /></font></td></tr></table>