Skip to content

Instantly share code, notes, and snippets.

@eliassoares
Created September 12, 2018 12:00
Show Gist options
  • Save eliassoares/43456a7b866263cfc41d78cee5e4fa58 to your computer and use it in GitHub Desktop.
Save eliassoares/43456a7b866263cfc41d78cee5e4fa58 to your computer and use it in GitHub Desktop.
List all databases Postgres
conn = psycopg2.connect("user='eliassoares' host='127.0.0.1' password='mysecretpassword'")
cur = conn.cursor()
cur.execute('SELECT datname FROM pg_database WHERE datistemplate = false;')
rows = cur.fetchall()
print(rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment