Solved

Connecting to Postgres Database from C Program

Posted on 2007-03-28
6
287 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

777 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