Solved

Connecting to Postgres Database from C Program

Posted on 2007-03-28
6
291 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.

696 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