?
Solved

Connecting to Postgres Database from C Program

Posted on 2007-03-28
6
Medium Priority
?
292 Views
Last Modified: 2010-04-01
Hi Experts,

I need to connect to the Postgres database from a C.  I was able to connect to the database.  Then I tried to execute the following command

create function sendevent() returns trigger as '/usr/lib/pgsql/libevent.so' language 'C';

When I do that I am getting the error message " permission denied for language c"

What am I doing wrong?  Also,  would it be possible to connect from a C++ program?

This is how I am building my program.
gcc -I/usr/include -I/usr/include/libxml2 -I/usr/include/pgsql/server -g -c ConnectDB.c
gcc  -I/usr/include -I/usr/include/libxml2 -I/usr/include/pgsql/server -g -o conn -L/usr/lib -lpq ConnectDB.o
0
Comment
Question by:ambuli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 

Author Comment

by:ambuli
ID: 18813203
Hmm.  some web reference points out that I need to have super user privileges when I do this.  Is it correct?
0
 
LVL 35

Expert Comment

by:ShineOn
ID: 18813409
That would likely be it.
0
 
LVL 35

Expert Comment

by:ShineOn
ID: 18813443
If what you found did the trick, post your solution and post a free question in Community Support asking to have this closed with points refunded.  Be sure to include a link to this question.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 10

Expert Comment

by:ivanovn
ID: 18816385
You need to have USAGE privilege enabled for the user that's attempting to connect using the C language.
You can do this by granting the USAGE privilege as follows:

GRANT USAGE ON LANGUAGE langname TO username
0
 

Author Comment

by:ambuli
ID: 18816528
Thanks ivanovn.  But when I do that, I am getting an error message saying

ERROR:  language "c" is not trusted

0
 
LVL 10

Accepted Solution

by:
ivanovn earned 2000 total points
ID: 18817291
Yes, C language is not trusted in PostgreSQL because of possible security issues (such as the ability of any user to execute C functions on your database).

However, I believe you can fix this if you execute the following:
UPDATE pg_language
SET lanpltrusted = true
WHERE lanname = 'c';
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question