When I run this query from psql shell everything works fine:


but when I try exactly the same query from python (with psycopg2 package) authentication fails when I try to connect with the password.

what can go wrong? I tried simple passwords with no non-ansi characters etc...

  • 2
    Maybe a missing commit from within Python? Aug 23 '17 at 11:21
  • you were right, I will accept if you make this an answer...
    – Mary
    Aug 23 '17 at 11:25
  • Question: Why do you want to change the postgres password so often that you feel the need to automate the process?
    – Phill W.
    Aug 20 '20 at 12:24
  • @PhillW. it's for server provisioning, it involves hundreds of similar tasks, maybe each one of them is done rarely, but together they overwhelm...
    – Mary
    Aug 20 '20 at 15:19

You have two options when running code from Python,

  1. Python has a method called autocommit you either have to turn this on,
  2. or, you have to run a manual COMMIT; after you issue the command.

Without either of those the command will automatically ROLLBACK;

answer inspired by @a_horse_with_no_name in the comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.