Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Perl and Postgres

Posted on 2006-04-19
5
Medium Priority
?
717 Views
Last Modified: 2012-08-13
Hi,

I need to Create a Postgres Database using Perl Script.

I know how to create Postgres Database using Linux Shell command line but for that I need to login as Postgres user, now when I try to do that in perl script it gives access denied.

Can anyone please let me know how do I create a Postgres database using Perl

Thanks

VIkasumit
0
Comment
Question by:VIkasumit
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 16495263
The most common way is ti use the DBI module and then the driver for your database, DBD::Postgres.  What code do you have so far and where does it fail?
0
 
LVL 4

Author Comment

by:VIkasumit
ID: 16495316
Hi,

I am using Shell commands to create the Database, the reason is quite simple that my Perl Installation doesn't have POSTGRES driver and I am not willing to install that. My whole application use that driver just for creating db once. Rest it make User to use phpPgAdmin to manage DB,

anyways, my perl script fails when I do this

#! /usr/bin/perl

$db=`su postgres`; #gives permission denied , Script fails here and hence next line doesn't fire
$db=`createdb xxxxx`; #incomplete line its Postgres Shell script to create DB using psql command

I want that createdb to run as postgres user where as my Perl make it run as root, Also I am not able to authoirze the POSTGRES user i.e. I am not able to login to POSTgre Interface using script.

Hope I am clear

VIkasumit
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 16495368
Okay, see what you want now. I think what you need is to run the postgres command in batch mode from a system call, not interactively as you seem to be.  I don't know the exact postgre command format so will use mysql syntax as an example instead

system("postgres --user='su; --password='pw' -e \"createdb dbase_name\" ");

And then add more sytem calls for each sql statement you want to run.
0
 
LVL 4

Author Comment

by:VIkasumit
ID: 16495482
Hi,

Thanks for let me know what exactly I should ask.... :o) I miss the term "batch command"/"system call" from my  vocabulary .

can you please explain "postgres --user='su; "
and --password='pw'

you mean you aer running postgres with "su" user ?? If thats what you are try than sorry, it will not work as when I try correct command

"psql -Upostgres -Wpassword -c 'CREATE DATABASE dbname';" it give me Authentication failure when run through scripts but if I run it directly on SSH console it works fine

Thanks for you time on question though.

VIkasumit
0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 2000 total points
ID: 16495547
yes you need the one line form. Does this work from perl?
system("psql -Upostgres -Wpassword -c 'CREATE DATABASE dbname;' ");
If it runs from console it should run in Perl if you are using the same host.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

581 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