Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Postgres Connection

Status
Not open for further replies.

littlesagi

Programmer
Aug 6, 2002
2
IN
Hi,
I got a problem,I have Red hat Linux 7.3 with postgres,PHP and Apache working fine.
The problem is that I'm not able to connect to Postgres database with a Postgres user(which is also a Linux user) from my PHP script.
Its only allowing apache user to connect to any Postgres database.
I did the following ..
Created Linux user 'xyz'
Created a Postgres data base user 'xyz' with create db permission
Created a database 'testdb' by Logging as 'xyz'
Till here everything worked fine.
But when i tried to connect to this database in my PHP script(pg_connect()) I'm getting error ident error for 'xyz'

I hope u gurus will suggest me some solution.

Thanx in Adv.
Ram
 
Hi littlesagi,

Be sure to reboot/restart the postmaster so it can re-evaluate all settings. You can try to localize the problem. I would login to pgsql using the new user name and password like:

psql template1 xyz

When pgsql prompts, enter the new user's password.

I assume you have /var/lib/pgsql/data/pg_hba.conf set to require passwords. I also assume that xyz has been setup as a user of the template1 database.

If this works, it may be that some setting in PHP needs to be changed.

Are you using any front-end tools to set up new users like phpPgAdmin?

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Hi littlesagi,

I just went back and re-read your post. I noticed you can login as xyz and have created a testdb. How are you connecting to your database. Is it by using a php script run in an apache web page. If so, this may indicate the problem is with the apache web server. Does user xyz have insert, select, update, delete, and role privileges. If the database were created by xyz then xyz would be the owner of the testdb. What happen is you change the owner to postgres. Also, have you tried making xyz a user of any other database to see if the same problem would presist there.

Why have you set all the other user up as apache user, but xyz is a regular user? Since there is no problem with xyz connecting from the psql command prompt, some other area to check.

Is access coming remotely or locally. Remember, when accessing a database from a web page, even though you call the web page from a remote location, it is access by apache using the php web page as localhost.

If remotely, have you set the switch in the /var/lib/pgsql/data/postgresql.conf file as follows:

socket tci/ip = true

I'm not familiar with the error message ident error. Is this coming up on a web page or from one of the logs files from postgres, apache, php, etc.

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
I just fixed a similar problem. You have to edit your pg_hda.conf file and remove the ident line. It should look something like this by default:
local all ident sameuser
Comment that out and you should be fine. //Daniel
 
Hi I have not made any corrections yet,but I'm able to connect to database if I change my httpd.conf file and put user as xyz.
Anyway,I'll make the changes as u have suggested.

Thanx
Ram
 
I had a similar problem and added apache as a postgres user (without user and database creation privileges, though) and granted access to the db to the new apache user with GRANT ALL PRIVILEGES ON <table name> TO APACHE.

That worked.

My personnal diagnosis is that apache is the user actually accessing the database when executing the PHP code - might be wrong, though ...

Hope this helps.
John
 
I had a similar problem and added apache as a postgres user (without user and database creation privileges, though) and granted access to the db to the new apache user with GRANT ALL PRIVILEGES ON <table name> TO APACHE.

That worked.

My personnal diagnosis is that apache is the user actually accessing the database when executing the PHP code - might be wrong, though ...

Hope this helps.
John
 
I had a similar problem and added apache as a postgres user (without user and database creation privileges, though) and granted access to the db to the new apache user with GRANT ALL PRIVILEGES ON <table name> TO APACHE.

That worked.

My personnal diagnosis is that apache is the user actually accessing the database when executing the PHP code - might be wrong, though ...

Hope this helps.
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top