Hi,
I switch to docker everything is up and works well I have my pgadmin I am able to create my model insert data etc.
I’m even able to connect Hasura image to my db.
There is my docker compose
version: '3.7'
services:
# TimescaleDB/PostgreSQL database
timescale:
image: timescale/timescaledb:latest-pg12
restart: unless-stopped
env_file:
- .env
volumes:
- type: volume
source: timescale_volume # the volume name
target: /var/lib/postgresql/data # the location in the container where the data is stored
read_only: false
ports:
- 0.0.0.0:5432:5432
networks:
- timescale_network
# PGAdmin for administering the TimescaleDB/PostgreSQL database with SQL
pgadmin:
image: "dpage/pgadmin4:latest"
restart: unless-stopped
env_file:
- .env
environment:
PGADMIN_LISTEN_PORT: 9000
ports:
# Use 0.0.0.0 to make this DB admin app accessible from "http://localhost:9000"
- 0.0.0.0:9000:9000
volumes:
# So the database server settings get saved and stored even if the container is replaced or deleted
- pgadmin:/var/lib/pgadmin
networks:
- timescale_network
graphql-engine:
image: hasura/graphql-engine:v2.25.0
ports:
- "8080:8080"
depends_on:
- "timescale"
restart: always
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://admin:xxxxxxxxxxx@timescale:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
networks:
- timescale_network
networks:
# The network the above containers share, for accessing the database
timescale_network:
# Creates a named volume to persist our database data
volumes:
helheim:
timescale_volume:
pgadmin:
Now I would like to create engine with sqlAlchemy or even psycopg2 and I get the following errors :
CONNECTION = "dbname=dbname user=admin password=xxxxxxxx host=timescale port=5432 sslmode=require"
with psycopg2.connect(CONNECTION) as conn:
cursor = conn.cursor()
OperationalError: could not translate host name "timescale" to address: Host name lookup failure
or with
engine = sa.create_engine('postgresql+psycopg2://admin:xxxxxxxxx@timescale:5432?sslmode=require', echo=True)
connection = engine.connect()
OperationalError: (psycopg2.OperationalError) could not translate host name "timescale" to address: Host name lookup failure (Background on this error at: https://sqlalche.me/e/20/e3q8)
SQLAlchemy: 2.0.17
psycopg2: 2.9.6
I also try connect my mage-ai pipeline to my timescaleDB the connection seems to by unstable with the native connector.
@data_loader
def load_data_from_postgres(*args, **kwargs):
"""
Template for loading data from a PostgreSQL database.
Specify your configuration settings in 'io_config.yaml'.
Docs: https://docs.mage.ai/design/data-loading#postgresql
"""
query = 'SELECT * FROM public."Underlyings" ORDER BY id ASC ' # Specify your SQL query here
config_path = path.join(get_repo_path(), 'io_config.yaml')
config_profile = 'default'
with Postgres.with_config(ConfigFileLoader(config_path, config_profile)) as loader:
return loader.load(query)
~\.conda\envs\ymir\lib\site-packages\mage_ai\io\base.py in conn(self)
330 return self._ctx
331 except AttributeError:
--> 332 raise ConnectionError(
333 'No connection currently open. Open a new connection to access this property.'
334 )
ConnectionError: No connection currently open. Open a new connection to access this property.
Mage-ai io_config.yaml
POSTGRES_CONNECT_TIMEOUT: 10
POSTGRES_DBNAME: postgres
POSTGRES_SCHEMA: public # Optional
POSTGRES_USER: admin
POSTGRES_PASSWORD: ********
POSTGRES_HOST: timescale
POSTGRES_PORT: 5432
mage-ai 0.8.98
Sorry for this newbie error, but i try to find out solution in google nothing solve it yet. I think something block the connection from outside the docker but i checked my postgresql.conf inside my docker and
listen_addresses is set to ‘*’ so it should works…