Solved

Connecting to Postgres Database from C Program

Posted on 2007-03-28
6
285 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

16 Experts available now in Live!

Get 1:1 Help Now