Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98428
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Warrick <kwpolska@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Problems connecting to PostgreSQL |
| Date | Sun, 8 Nov 2015 09:36:38 +0100 |
| Lines | 59 |
| Message-ID | <mailman.119.1446971807.16136.python-list@python.org> (permalink) |
| References | <87wptt5qg4.fsf@Equus.decebal.nl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de BRC22xbtA59LkGiiFB58jA/G2nD49necprOAewlTiVww== |
| Return-Path | <kwpolska@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'configure': 0.04; 'matches': 0.07; 'postgresql': 0.07; 'cc:addr:python-list': 0.09; 'alter': 0.09; 'created,': 0.09; 'postgres': 0.09; '\xe2\x80\x94': 0.09; 'user.': 0.15; 'also:': 0.16; 'conn': 0.16; 'doesn\xe2\x80\x99t': 0.16; 'ipv6': 0.16; 'md5': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Problems': 0.16; 'sudo': 0.16; 'used:': 0.16; 'wrote:': 0.16; 'settings': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'permission': 0.20; 'denied': 0.22; 'role,': 0.22; 'cc:no real name:2**0': 0.22; 'this:': 0.23; 'unix': 0.24; 'header:In-Reply- To:1': 0.24; 'chris': 0.26; 'followed': 0.27; 'message- id:@mail.gmail.com': 0.27; 'host': 0.28; "skip:' 10": 0.28; 'peer': 0.29; 'silence': 0.29; 'checks': 0.30; 'role': 0.32; 'worked': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'things': 0.38; 'received:209': 0.38; 'skip:p 20': 0.38; 'your': 0.60; 'skip:u 10': 0.61; 'default': 0.61; 'different': 0.63; 'cecil': 0.84; 'skip:/ 30': 0.84; 'westerhof': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=IyqrBmZka1sAI8bjOR5A7d1F0unfR8EAtHYfC8LDvjE=; b=TNWYnpyYAk2N5FGYhxJ752FA+PY+m9O3/QQDx9Yd4E9xGXQ/tdRTlt8nCmkmhd4pqW AvAoAuIyXN6JHJY/EarmFhTPRj/KSNqlS89VRYi13JeJhi44xEReNFr0z4zhktC1yFPf uZthjo9+y4pggiyLCflEN3pQkqHgn6gegRDdaoso2wG8AmXqjCsTqv55ZFnOowx4qykk BvHRCqoVFUcURMWgQX8MDEnlLPBh8quudZiTWLXwTL3LChdpikWnO49XLuhLP5IuG3Bz XHZ1HNswRWZ7ZaPUlYyPbGCD34aJe++a6x9/zvwmcOJW6pbW2km4JlA6nb6CgeSBYmrw Kldw== |
| X-Received | by 10.31.171.140 with SMTP id u134mr22912130vke.30.1446971798682; Sun, 08 Nov 2015 00:36:38 -0800 (PST) |
| In-Reply-To | <87wptt5qg4.fsf@Equus.decebal.nl> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:98428 |
Show key headers only | View raw
On 8 November 2015 at 00:40, Cecil Westerhof <Cecil@decebal.nl> wrote:
> I followed http://zetcode.com/db/postgresqlpythontutorial/.
>
> I used:
> sudo -u postgres createuser stressTest
> this create the role, but also gave:
> could not change directory to "/root": Permission denied
> and I did not get the questions.
This is not an error, just a warning — and it comes from sudo,
postgres doesn’t care. To silence it, you need to work from a
different directory than /root. The commands actually worked just
fine.
> Then I used:
> sudo -u postgres createdb stressTest -O stressTest
> This gave also:
> could not change directory to "/root": Permission denied
>
> The database is created, but when I execute:
> conn = psycopg2.connect(database = postgres_database, user = 'stressTest')
> I get:
> psycopg2.OperationalError: FATAL: Peer authentication failed for user "stressTest"
>
> What do I need to do to get things working?
You need to configure your PostgreSQL database to use md5
authentication, and set a password for your user.
# cd /
# sudo -u postgres psql
postgres=# ALTER ROLE stressTest WITH PASSWORD 'swordfish';
postgres=# \q
# vim /var/lib/postgres/data/pg_hba.conf
Change host settings to look like this:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Then you can connect using:
conn = psycopg2.connect(database='stressTest', user='stressTest',
password='swordfish', host='localhost')
Documentation:
http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
http://www.postgresql.org/docs/current/static/auth-methods.html
http://www.postgresql.org/docs/current/static/sql-alterrole.html
(basically, the default peer authentication checks your Unix user name
to see if it matches 'stressTest', and fails)
--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Problems connecting to PostgreSQL Cecil Westerhof <Cecil@decebal.nl> - 2015-11-08 00:40 +0100
Re: Problems connecting to PostgreSQL Chris Angelico <rosuav@gmail.com> - 2015-11-08 10:54 +1100
Re: Problems connecting to PostgreSQL Chris Warrick <kwpolska@gmail.com> - 2015-11-08 09:36 +0100
Re: Problems connecting to PostgreSQL Cecil Westerhof <Cecil@decebal.nl> - 2015-11-09 13:59 +0100
csiph-web