PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 11th, 2008, 06:08 AM
vibrations vibrations is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 23 vibrations User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 54 m 55 sec
Reputation Power: 0
Problem in connecting to db through perl

hello,
I am a newbie on the block...
I am trying to connect to to postgres through a perl script.
tried doing the following stuff...


$dbh = DBI->connect('DBI:Pg:dbname=mydb', 'postgres', 'postgres');
if ($dbh) {
print "connected\n";
print "b4 prepare..\n";


$sth = $dbh->prepare("select * from mytable");
print "sth is: $sth\n";
$sth->execute();
print "after execute.. sth: $sth\n";


the problem is that when i try to connect to the mydb through this script it takes the default user to be root and not postgres.

the script runs on 777 and is owned by root, so tried runnig it as:

su -c 'perl testscript.pl' postgres

but it gives the following errors:

bash: /root/.bashrc: Permission denied
DBI connect('dbname=postgres','postgres',...) failed: FATAL 1: Database "postgres" does not exist in the system catalog.
at testscript.pl line 30
Cannot connect to Postgres server: FATAL 1: Database "postgres" does not exist in the system catalog.

db connection failed



and this is the case if the db is owned by any other user than root, in this case the owner of mydb is postgres but it doesnt seem to access the db.. but when the onwer of the db is root thenn it seems to be working...

I am confused as to where the problem lies..is it with the scripts,the permission or missing out on what.. not able to figure it out..
ne help on this would be a honour..[]
thanku

Reply With Quote
  #2  
Old April 11th, 2008, 06:33 AM
pgFrank's Avatar
pgFrank pgFrank is offline
So help me Codd
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Location: Brazil
Posts: 129 pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level)pgFrank User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 17 h 45 m 53 sec
Reputation Power: 18
To me it looks like you're missing some parameters in the connection string. Take a look at this link and give it a try.

I'm not that familiar with Perl, sorry.
__________________
PostgreSQL-manual

Reply With Quote
  #3  
Old April 11th, 2008, 06:56 AM
vibrations vibrations is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 23 vibrations User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 54 m 55 sec
Reputation Power: 0
hey thanks for that prompt help.. i was messing up the synatx
thanku once again.[]

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Problem in connecting to db through perl


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway