Multiple schema support for initdb

728 views
Skip to first unread message

jaso...@blueapron.com

unread,
Sep 14, 2015, 10:27:18 AM9/14/15
to Airflow
We're using multiple schemas within Postgresql and would like the airflow tables to live outside the default 'public', if possible.  Any easy way to do this with the built-in cmd?

Maxime Beauchemin

unread,
Sep 14, 2015, 2:22:12 PM9/14/15
to Airflow
The schema should be specified in your SQL_ALCHEMY_CONN uri in your config file.

SQL_ALCHEMY_CONN = postgres://myuser:myp...@mydb.myhost.com:3306/myschema

Refer to the SQL Alchemy docs for more details.

jaso...@blueapron.com

unread,
Sep 14, 2015, 2:46:15 PM9/14/15
to Airflow
Hi Maxime,

By schema, I meant a single database with multiple schemas (which is something Postgres supports).  In my case,

   SQL_ALCHEMY_CONN = postgres://myuser:mypass@mydb.myhost.com:3306/db_name

works, but that doesn't allow me to specify a schema within that database as outlined here (http://docs.sqlalchemy.org/en/rel_0_9/core/metadata.html#specifying-the-schema-name).

Maxime Beauchemin

unread,
Sep 14, 2015, 3:00:47 PM9/14/15
to Airflow
Gotcha. I don't think there's any way to do this now unless there's some sort of magic unknown binding of the kind SQL_ALCHEMY_CONN = postgres://myuser:mypass@mydb.myhost.com:3306/db_name/schema_name (which is a pattern I've seen used for Presto's catalog concept). Beyond that I'd tag as "need_help" and "cant_recreate" as a Github issue as Airbnb doesn't need the feature and we don't have Postgres databases laying around for testing.

Max

Andrey Oskin

unread,
Sep 15, 2015, 4:37:55 PM9/15/15
to Airflow
According to http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html there is no official way to specify postgres schema in connection string. Usual way is changing search_path after connection initialized:

"
>>> engine = create_engine("postgresql://scott:tiger@localhost/test")
>>> with engine.connect() as conn:
...     conn.execute("SET search_path TO test_schema, public")
"

Or, if you do not want to change airflow code, you may change default search_path per user on database side by executing something like
"ALTER ROLE username SET search_path = schema1,schema2,schema3,etc;"

jaso...@blueapron.com

unread,
Sep 15, 2015, 9:32:19 PM9/15/15
to Airflow
Interesting approach on the database side.  Thanks for the tip!

Maxime Beauchemin

unread,
Sep 16, 2015, 12:17:47 PM9/16/15
to Airflow
I added a note in the docs for the next wave of installers:
Reply all
Reply to author
Forward
0 new messages