Skip to content

Instantly share code, notes, and snippets.

@BexTuychiev
Last active July 21, 2020 04:28
Show Gist options
  • Save BexTuychiev/ddc9dac18fbb019b4214462ec8d424ed to your computer and use it in GitHub Desktop.
Save BexTuychiev/ddc9dac18fbb019b4214462ec8d424ed to your computer and use it in GitHub Desktop.
import psycopg2
try:
# Establish a connection
connection = psycopg2.connect(user='nufavqtimheyhv',
password="33913ed88ebcb400c1b353a07b9f11e8480c4b4ea437820a2c7dc04e09b98e7c",
port=5432, host='ec2-3-208-50-226.compute-1.amazonaws.com',
database='da1fvg7qnm795d')
# Create a cursor object
cursor = connection.cursor()
print("Connection Successful")
except (Exception, psycopg2.Error) as error:
print("Error while connecting to PostgreSQL", error)
finally:
if connection:
# Always a good practice to close open connections
connection.close()
print("PostgreSQL connection is closed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment