Solved

Connecting to Postgres Database from C Program

Posted on 2007-03-28
6
286 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
  • 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now