xxxxxxxxxx
import psycopg2
try:
# Establish a connection to the PostgreSQL server
connection = psycopg2.connect(
host="your_server_host",
port="your_server_port",
dbname="your_database_name",
user="your_username",
password="your_password"
)
# Perform any desired actions here, e.g. executing queries
# Closing the connection
connection.close()
print("Connection to server successful")
except (Exception, psycopg2.Error) as error:
print("Error connecting to server:", error)