From fc08fd901e86bf046dd1c4c9b8318d97279b7b0f Mon Sep 17 00:00:00 2001 From: Mathan Date: Sat, 25 Nov 2023 23:31:27 -0500 Subject: [PATCH] postgres integration --- docs/postgres_setup.md | 25 +++++++++++++++++++++++++ evadb/catalog/sql_config.py | 13 ++++++++----- evadb/database.py | 15 ++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 docs/postgres_setup.md diff --git a/docs/postgres_setup.md b/docs/postgres_setup.md new file mode 100644 index 0000000000..854070b45b --- /dev/null +++ b/docs/postgres_setup.md @@ -0,0 +1,25 @@ +## INSTRUCTIONS TO SET UP POSTGRES DATABASE + +These were the steps followed on a Mac system to install postgres and configure it: + +1. Install postgres + ``` brew install postgresql``` +2. Start PostgresSQL: +```brew services start postgressql``` +3. Create a user and database: + + Username: evadb + + Password: password + + - ```psql postgres``` + - ```CREATE ROLE evadb WITH LOGIN PASSWORD 'password';``` + - ```ALTER ROLE evadb CREATEDB;``` + - ```\q``` +4. Login as your new user + + ``` psql -d postgres -U evadb``` +5. create the database evadb + + ```CREATE DATABASE evadb;``` +6. ```pip install psycopg2``` \ No newline at end of file diff --git a/evadb/catalog/sql_config.py b/evadb/catalog/sql_config.py index fed6630f3e..79e1ecdeed 100644 --- a/evadb/catalog/sql_config.py +++ b/evadb/catalog/sql_config.py @@ -71,11 +71,14 @@ def __init__(self, uri): # set echo=True to log SQL # Default to SQLite. - connect_args = {"timeout": 1000} - self.engine = create_engine( - self.worker_uri, - connect_args=connect_args, - ) + # connect_args = {"timeout": 1000} + # self.engine = create_engine( + # self.worker_uri, + # connect_args=connect_args, + # ) + + # Postgres version + self.engine = create_engine(self.worker_uri) if self.engine.url.get_backend_name() == "sqlite": # enforce foreign key constraint and wal logging for sqlite diff --git a/evadb/database.py b/evadb/database.py index 9c22d5b9ff..47c11fcaed 100644 --- a/evadb/database.py +++ b/evadb/database.py @@ -41,10 +41,23 @@ def catalog(self) -> "CatalogManager": return self.catalog_func(self.catalog_uri) -def get_default_db_uri(evadb_dir: Path): +def get_default_db_uri_sqlite(evadb_dir: Path): # Default to sqlite. return f"sqlite:///{evadb_dir.resolve()}/{DB_DEFAULT_NAME}" +def get_default_db_uri(evadb_dir: Path): + """ + Generates a PostgreSQL connection URI for the local database. + + Returns: + str: A PostgreSQL connection URI. + """ + user = "evadb" + password = "password" + host = "localhost" + port = 5432 # Default PostgreSQL port + db_name = "evadb" + return f"postgresql://{user}:{password}@{host}:{port}/{db_name}" def init_evadb_instance( db_dir: str, host: str = None, port: int = None, custom_db_uri: str = None