[Ilugc] Help with PostgreSQL (psycopg)

  • From: tech@xxxxxxxxxxxxxxx (Ma Siva Kumar)
  • Date: Wed Jul 19 16:15:14 2006

Hi Parthan,

1. To get prompted for password when using psql try the following:
psql mydb --username guest --password

2. To always get password prompt change the authentication method in file  
/usr/local/pgsql/data/pg_hba.conf. (Assuming your installation is at 
/usr/local/pgsql). 

 'trust' will allow any user to connect as any other user by specifing 
--username option. 

3. I am not sure why your python script fails to connect. Are you running your 
python script in the same machine running the database server? 

If connecting over network, you should enable tcp/ip connection in 
postgresql.conf and allow permissions to the ip addresses in pg_hba.conf 
file. 

Best regards, 

Ma Sivakumar


On Wed July 19 2006 1:57 pm, Parthan wrote:

Hello,
I am trying to use PostgreSQL database in Python using psycopg. I have
an issue, not basically with psycopg, but mainly with postgresql. I have
created an account guest, with superuser privileges and permission to
create tables, with a password 'guest'. When i try to use it for
accessig database in my python program, i get an authentication failure
error.

[python code]

from psycopg import connect
connection = connect("dbname=mydb user=guest password=guest")
cursor = connection.cursor()
cursour.execute("SELECT * FROM mytable")
......
......

[/python code]

But this gives me a "fatal error: Authentication failure" for user=guest
incorrect password=guest. I made sure that the password is correct. I
then checked the same using 'pgaccess' a GUI for accessing PostgreSQL
database. I used the same dbname, username and password, and i was able
to access my database, the 'mytable' table was there and had data i had
earlier inserted from the command line.

when i give 'psql mydb' am able to get the 'mydb=>'prompt, and thats how
i created mytable.

Where am i getting worng ? What is the proper method of setting up a
user and password in PostgreSQL. I was earlier using MySQL and i had no
such authentication problems. psql seems to a bit confusing as it
doesn't have a 'user=<uname> password=<pword>' option as in mysql to get
into mysql.

-- 
Integrated Management Tools for leather industry
----------------------------------
http://www.leatherlink.net

Ma Siva Kumar,
BSG LeatherLink (P) Ltd,
Chennai - 600106

Other related posts: