If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > psql and PGPASSWORD and a little php

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-16-11, 23:45
dcdon dcdon is offline
Registered User
 
Join Date: Aug 2011
Posts: 1
psql and PGPASSWORD and a little php

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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On