22

I'm following these instructions (https://github.com/assemblymade/assemblycoins) to get a postgresql server connected.

I am told to: "set DATABASE_URL local variable to postgres database url"

I'm not too sure where to find this, it doesn't seem like an easy thing to find. (Sorry, i'm pretty new to Postgresql if this is a real amateur question)

For a bit more context, I installed postgresql from Enterprise DB and can successfully run a postgresql database on PGAdmin.

1

5 Answers 5

12

You can display your connection info if logged into postgres shell with command:

\conninfo

this will display the database you are connected to as well as the user logged on

9

See The docs The general form for a connection URI is:

postgresql://[user[:password]@][netloc][:port][,...][/dbname][?param1=value1&...]

You probably need to set you environment variable DATABASE_URL to something like

set DATABASE_URL=user:password@localhost/dbname
3

Looking at file main.py line 22 contains "os.environ['DATABASE_URL']" you should set the environment variable DATABASE_URL on your computer to a value that is the location of your database. Eg: set DATABASE_URL=C:\Users\Philip\mydatabasefile

7
  • 1
    thanks @Marichyasana. I tried the following: DATABASE_URL= "postgresql://localhost/postgres" under line 22. this matches the information in my current local postgres database. However when I ran "python main.py" I got the error: "KeyError: 'DATABASE_URL". I'm not too sure why it's not processing my database url.
    – pppp
    Commented Oct 13, 2014 at 6:27
  • 3
    @Paul: the comment on line 22 seems like it tells you that the format should be: "postgresql://localhost/"+dbname Is your databasename "postgres", or more likely "myDatabase" Commented Oct 13, 2014 at 10:36
  • I made the change according to the comment in Line 22. so it now looks like DATABASE_URL="postgresql://localhost/"+dbname", where dbname is set to "postgres" (this is the name of my database, at least according to pgadmin) I still get the same KeyError when running python main.py
    – pppp
    Commented Oct 13, 2014 at 16:33
  • Did you change the file or the environment variable? Commented Oct 13, 2014 at 17:14
  • I don't have postgres so I'm unable to make more suggestions. Commented Oct 13, 2014 at 17:27
2

postgres://[user]:[password]@[host]:[port]/[database] this is the method i often use

1
  • Simple, concise, and to the point!
    – tamouse
    Commented Apr 6, 2023 at 17:39
1

This is the most up to date URI format for sqlalchemy

Replace the following variables: 1. username 2. password 3. dbname

URI postgresql+psycopg2://username:password@localhost/dbname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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