Closed jayzeng closed 9 years ago
I've faced the same error. After reading sqlalchemy's document a little I tried to pass postgresql+psycopg2://ubuntu:@/testdb?host=/var/run/postgresql
, but it asks me my db name again Please enter the name of the database (eg. projectdb):
and returns another error if I type the db name:
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/testdb/.s.PGSQL.5432"?`
The socket file should be at /var/run/postgresql/.s.PGSQL.5432.
database_exists
and other methods in stellar's code do not seem supporting additional params like specifying unix socket. After created a user with alter user newuser createdb
and allowed tcp access in pg_hba.conf, postgresql+psycopg2://newuser:newpass@localhost:5432/
is working in my case.
I'm not sure if this is related, but this worked for me:
postgresql://postgres@127.0.0.1:5432/
e.g. add the username of the database and use the IP instead of hostname localhost
.
@ramonakira I tried what you suggested with no luck. Got the exact same error.
Has anyone else gotten this to work? I've tried a variety of URLs, including the full one postgresql://joshma@localhost:5432/mydb
and it won't work, while psql -h localhost -p 5432 -U joshma mydb
works fine.
@nobuf :+1:
postgresql+psycopg2://newuser:newpass@localhost:5432/
has worked for me too
The root of this problem is: https://github.com/fastmonkeys/stellar/blob/master/stellar/command.py#L160
If you print the OperationalError exception what you get most of the time is database does not exists
and that's due to the trailing slash that's added in the URL that contains the database name.
If the URL does not contain the database name, then it's like sqlalchemy tries to find the database having the same name as the user, so if you do not have a database named <user>
, it fails to connect as well.
I'll see if I can come up with a patch that keeps the original idea of the author while allowing to connect to a specific database.
@pypingou thanks for the patch, that worked for me
I am also having problems getting it to work with a database that requires authentication to work. I have tried various formats:
postgresql://user:pass@localhost:5432/
postgresql://user:pass@localhast:5432/dbname
postgresql+psycopg2://user:pass@localhost:5432/
postgresql+psycopg2://user:pass@localhost:5432/dbname
No matter what though I get the same error:
Could not connect to database: postgresql+psycopg2://user:pass@localhost:5432/dbname
Make sure database process is running and try again.
Please enter the url for your database.
The server is running and I am able to connect to it with the psql
command, and my app connects to it fine as well.
Can someone tell me what's going on here?
lects/postgresql/psycopg2.py", line 422, in dbapi
import psycopg2
File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
@vendion see #31
@glennmartinez you seem to be missing some libraries: libssl perhaps?
This was fixed by @pypingou's PR (thanks!).
Feel bad to ask this question, but I am having trouble of connecting to psql, here are the steps:
On the other hand, I can manually connect to this api.
Did I miss anything?