stellar: There is 1 other session using the database error

I’m getting this error when trying to snapshot a postgres database

/usr/local/lib/python2.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)

Traceback (most recent call last):
  File "/usr/local/bin/stellar", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/stellar/command.py", line 279, in main
    stellar()
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/stellar/command.py", line 60, in snapshot
    app = get_app()
  File "/usr/local/lib/python2.7/site-packages/stellar/command.py", line 28, in get_app
    app = Stellar()
  File "/usr/local/lib/python2.7/site-packages/stellar/app.py", line 45, in __init__
    self.init_database()
  File "/usr/local/lib/python2.7/site-packages/stellar/app.py", line 64, in init_database
    tables_missing = self.create_stellar_database()
  File "/usr/local/lib/python2.7/site-packages/stellar/app.py", line 72, in create_stellar_database
    self.operations.create_database('stellar_data')
  File "/usr/local/lib/python2.7/site-packages/stellar/operations.py", line 57, in create_database
    get_engine_url(raw_conn, database)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy_utils/functions/database.py", line 554, in create_database
    result_proxy = engine.execute(text)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 2075, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 942, in execute
    return self._execute_text(object, multiparams, params)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1104, in _execute_text
    statement, parameters
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1200, in _execute_context
    context)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
    exc_info
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context
    context)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 507, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) source database "template1" is being accessed by other users

DETAIL:  There is 1 other session using the database.
 [SQL: "CREATE DATABASE stellar_data ENCODING 'utf8' TEMPLATE template1"] (Background on this error at: http://sqlalche.me/e/e3q8)

The source database is not being used when doing the backup.

I’m running Mac OS 10.13.4, probably with the default python version (2.7.14)

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 3
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

@jalada Sorry, I posted the wrong version. I’ve updated my original comment.

SQLAlchemy 1.2.6 and above have this issue. It can be worked around for now by downgrading to 1.2.5 (pip install SQLAlchemy==1.2.5 SQLAlchemy-Utils==0.33.1).

I’m getting this too. It appears the issue is caused by an update to SQLAlchemy.

You can work around this by running: pip install SQLAlchemy==1.2.5 SQLAlchemy-Utils==0.33.1

This is workaround for me: connect to postgres db, ie. : su - postgres then connect to db: psql and execute CREATE DATABASE stellar_data ENCODING 'utf8' TEMPLATE template1 owner **$USER**;

where $USER is your DB user name stellar is working with (needs corresponding privileges obviously) Stellar will create missing tables at first snapshot and it work’s for me with SQLAlchemy ==1.3.6

Also happens to me with stellar 0.4.5/Python 3.6.7/Ubuntu 18.04/pip 18.1/PostgreSQL 10.6 Downgrading to SQLAlchemy==1.2.5 and SQLAlchemy-Utils==0.33.1 fixed it

The difference may be the Postgresql version.

I had SQLAlchemy1.2.9 and SQLAlchemy-Utils 0.33.3 and they worked without issue using Postgresql 9.6.

After I upgraded to Postgresql 10.5 I got the same “source database “template1” is being accessed by other users” error as above. (via Homebrew on macOS 10.13.6 using Stellar 0.4.5)

After finding this issue I tested do downgraded to SQLAlchemy 1.2.5 and SQLAlchemy-Utils 0.33.1 as suggested and I got a working stellar again.