2
votes

I am trying to create a dask dataframe from a table in postgres. I would like to pass the application_name = 'myapp' as a standard for monitoring and tracking DB activity.

But when am trying to add the parameter, I getting below error.

ddf = dd.read_sql_table('table', 
                        uri, 
                        schema='schema', 
                        index_col='index_col', 
                        engine_kwargs={'application_name':'myapp'})

TypeError: Invalid argument(s) 'application_name' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.

2
To which function is application_name a valid input, where do you expect this to go? - mdurant
I am expecting SQLAlchemy to use it while creating engine. - Lijo Jose
The exception suggests create_engine() does not want this keyword. Can you create a sqalchemy engine independently? - mdurant
I refered :issue and updated code as engine_kwargs={'connect_args': {'application_name':'myapp'}. Now its working - Lijo Jose

2 Answers

3
votes

It turns out the correct syntax was

ddf = dd.read_sql_table('table', 
                        uri, 
                        schema='schema', 
                        index_col='index_col', 
                        engine_kwargs={'connect_args': {'application_name': 'myapp'})

since the call to make the sqlalchemy engine looks like

engine = create_engine(uri, connect_kwargs={'application_name':' myapp'})
0
votes
  • PostgreSQL Database :

The following works in sqlalchemy==1.3.10

    # Establish database connection via sqlalchemy

    sqlalchemy_connection_kwargs = {'connect_args': {'application_name': 'herles_application'}}

    connection = create_engine(sqlalchemy_connection_string, **sqlalchemy_connection_kwargs)

If you are using psycopg2-binary==2.8.4 native connection

native_connection = psycopg2.connect(user=cred['username'],
                                     password=cred['password'],
                                     host=cred['host'],
                                     port=cred['port'],
                                     database=cred['databaseName'],
                                     application_name="herles_application")