After putting the redash server (on an AWS EC2 instance) behind an elastic load balancer, our ability to send emails has disappeared. Running bin/run ./manage.py send_test_email just hangs and no email is sent/received. With that failure, I decided to run bin/run ./manage.py status, which resulted in the following traceback. I’ve not touched postgres at all, so not sure what happened. Thoughts?

Traceback (most recent call last):
  File "/opt/redash/current/manage.py", line 58, in <module>
    manager.run()
  File "/usr/local/lib/python2.7/dist-packages/flask_script/__init__.py", line 405, in run
    result = self.handle(sys.argv[0], sys.argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/flask_script/__init__.py", line 384, in handle
    return handle(app, *positional_args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask_script/commands.py", line 145, in handle
    return self.run(*args, **kwargs)
  File "/opt/redash/current/manage.py", line 29, in status
    print json.dumps(get_status(), indent=2)
  File "/opt/redash/redash.0.10.1.b1834/redash/monitor.py", line 9, in get_status
    status['queries_count'] = models.Query.select().count()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2621, in count
    return self.aggregate(convert=False) or 0
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2614, in aggregate
    return self._aggregate(aggregation).scalar(convert=convert)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2380, in scalar
    row = self._execute().fetchone()
  File "/opt/redash/redash.0.10.1.b1834/redash/metrics/database.py", line 50, in metered_execute
    result = real_execute(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2371, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/opt/redash/redash.0.10.1.b1834/redash/metrics/database.py", line 22, in execute_sql
    result = super(MeteredPostgresqlExtDatabase, self).execute_sql(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 369, in execute_sql
    self.commit()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2922, in __exit__
    reraise(new_type, new_type(*exc_value.args), traceback)
  File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 358, in execute_sql
    cursor = self.get_cursor()
  File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 345, in get_cursor
    return self.get_conn().cursor()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3022, in get_conn
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3004, in connect
    self.initialize_connection(self.__local.conn)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2922, in __exit__
    reraise(new_type, new_type(*exc_value.args), traceback)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3002, in connect
    **self.connect_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 373, in _connect
    conn = super(PostgresqlExtDatabase, self)._connect(database, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3316, in _connect
    conn = psycopg2.connect(database=database, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
peewee.OperationalError: FATAL:  role "ubuntu" does not exist

Postgres uses the user you’re logged in to the server with as the user to login with. This is why you need to run the command prefixed with sudo -u redash.

As for the email issue - what provider are you using? Where you on ec2 before or some other host?

Thanks @arikfr. I was able to resolve this issue tonight. We’re using Amazon SES and the security group settings on the reDash EC2 instance were insufficient to talk to SES. And, I’ll take your advice and run the command with the prefix you suggested.

Cheers.
dmill

I encountered the same issue and sudo -u redash bin/run ./manage.py send_test_mail won’t work? Can you please help?

Here is the output of bin/run ./manage.py status:
/opt/redash/current bin/run ./manage.py status
[2018-05-22 09:21:03,956][PID:2119][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[2018-05-22 09:21:03,972][PID:2119][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
Traceback (most recent call last):
File “/opt/redash/current/manage.py”, line 9, in
manager()
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/flask/cli.py”, line 345, in main
return AppGroup.main(self, *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/flask/cli.py”, line 229, in decorator
return __ctx.invoke(f, *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/opt/redash/redash.4.0.1.b4038/redash/cli/init.py”, line 47, in status
print(json.dumps(get_status(), indent=2))
File “/opt/redash/redash.4.0.1.b4038/redash/monitor.py”, line 10, in get_status
status[‘queries_count’] = models.db.session.query(models.Query).count()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 3031, in count
return self.from_self(col).scalar()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 2785, in scalar
ret = self.one()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 2756, in one
ret = self.one_or_none()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 2726, in one_or_none
ret = list(self)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 2797, in iter
return self._execute_and_instances(context)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 2818, in _execute_and_instances
close_with_result=True)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 2827, in _get_bind_args
**kw
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.py”, line 2809, in _connection_from_session
conn = self.session.connection(**kw)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py”, line 966, in connection
execution_options=execution_options)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py”, line 971, in _connection_for_bind
engine, execution_options)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py”, line 403, in _connection_for_bind
conn = bind.contextual_connect()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py”, line 2103, in contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py”, line 2142, in _wrap_pool_connect
e, dialect, self)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py”, line 1456, in _handle_dbapi_exception_noconnection
exc_info
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py”, line 202, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py”, line 2138, in _wrap_pool_connect
return fn()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 387, in connect
return _ConnectionFairy._checkout(self)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 766, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 516, in checkout
rec = pool._do_get()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 1138, in _do_get
self._dec_overflow()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py”, line 60, in exit
compat.reraise(exc_type, exc_value, exc_tb)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 1135, in _do_get
return self._create_connection()
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 333, in _create_connection
return _ConnectionRecord(self)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 461, in init
self.__connect(first_connect_check=True)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py”, line 651, in __connect
connection = pool._invoke_creator(self)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py”, line 105, in connect
return dialect.connect(*cargs, **cparams)
File “/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py”, line 392, in connect
return self.dbapi.connect(*cargs, **cparams)
File “/usr/local/lib/python2.7/dist-packages/psycopg2/init.py”, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: role “ubuntu” does not exist

You’re getting this error because you didn’t prefix it with sudo -u redash.

As you can see, I actually did add the prefix. Now the problem is gone as I created another EC2 instance.

You did it for the send_test_email command, but not for the status command.

Got it. Thanks a lot.