Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-17-2011, 03:43 PM   #1
LQ Newbie
Registered: Jul 2011
Posts: 8

Rep: Reputation: Disabled
psql and PGPASSWORD and a little php - AWS vps - Ubuntu

I have a shell script that is being called from php.

the shell script needs to execute a sql command using psql . www-data is the user that calls the script, but I need to run the psql as a different user and password.

the script basically runs this:

echo 'Select * from farms;' >> /tmp/x.sql
psql -U joe -d mydb -f /tmp/x.sql > /tmp/log.txt

obviously, this will not work because the password for account joe cannot be found. So I have tried and tried to set the PGPASSWORD. I can even run export PGPASSWORD=thepassword and then printenv and see it there. But it fails when I try it saying:

psql: FATAL: Ident authentication failed for user "joe"

in troubleshooting, I sudo bash'd over to root and tried this at the command line:

export PGPASSWORD=thepassword
psql -U joe -d mydb -f /tmp/x.sql > /tmp/log.txt
--- same error, failed to authenticate.

I also loaded up all of the variables and checked them with printenv:
PGPORT, PGDATABASE, PGUSER, PGPASSWORD, PGHOST . It still says "ident authentication failed".

I can log into this account joe in various ways so I know the password is good.

Any advice will be quite appreciated.
Old 08-17-2011, 06:50 PM   #2
LQ Newbie
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Just figured it out after 3 days.

it was the configuration in my pg_hba.conf . I had to change the 'local' authentication from 'ident' (value after standard install) to 'md5' and it started working. I hope someone finds this helpful one day.
Old 08-17-2011, 07:18 PM   #3
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Thanks for posting the update.

And a silly question: why do you need to create the shell-script
and run it, rather than doing this from within PHP?

Old 08-17-2011, 07:28 PM   #4
LQ Newbie
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
well the shell script is actually much more complicated, doing some stuff that would just get nasty trying to do it from php. I had just chopped it down to simplify things for testing that permissions issue.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amazon AWS windows instance backups linuxlover.chaitanya General 0 05-17-2011 01:15 AM
install CURL for PHP 5 (Godaddy VPS) chetanmadaan Linux - Newbie 6 06-14-2010 05:46 AM
LXer: Perfect Backup Solution with Amazon S3 and aws LXer Syndicated Linux News 1 05-25-2010 08:06 AM
RAM full after dist-upgrade, apache2, php, mysql installation on a VPS motiongrafika Linux - Server 5 02-01-2010 12:18 AM
how to upgrade mysql and php on operational VPS coffee666 Linux - Newbie 1 12-24-2007 11:29 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration