! mkdir -p ~/.postgresql && wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" -O ~/.postgresql/root.crt && chmod 0600 ~/.postgresql/root.crt
--2021-04-01 14:18:53-- https://storage.yandexcloud.net/cloud-certs/CA.pem
Resolving storage.yandexcloud.net (storage.yandexcloud.net)... 213.180.193.243, 2a02:6b8::1d9
Connecting to storage.yandexcloud.net (storage.yandexcloud.net)|213.180.193.243|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3579 (3.5K) [application/x-x509-ca-cert]
Saving to: ‘/root/.postgresql/root.crt’
/root/.postgresql/r 100%[===================>] 3.50K --.-KB/s in 0s
2021-04-01 14:18:53 (118 MB/s) - ‘/root/.postgresql/root.crt’ saved [3579/3579]
import psycopg2
import os
try:
connection = psycopg2.connect(user=os.environ["OUR_POSTGRES_USER"],
password=os.environ["OUR_POSTGRES_PASSWORD"],
host=os.environ["OUR_POSTGRES_HOST"],
port=os.environ["OUR_POSTGRES_PORT"],
database=os.environ["OUR_POSTGRES_DATABASE"])
with connection.cursor() as cursor:
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record)
except (Exception, psycopg2.Error) as error:
print ("Error while connecting to database", error)
You are connected to - ('PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit',)
SELECT * FROM pg_statistic;