Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"database already exists" when restoring #33

Open
ramonakira opened this issue Sep 2, 2014 · 3 comments
Open

"database already exists" when restoring #33

ramonakira opened this issue Sep 2, 2014 · 3 comments

Comments

@ramonakira
Copy link

When trying to restore the database, I get the following error:

sqlalchemy.exc.ProgrammingError: (ProgrammingError) database "d-demo" already exists
 '\n                ALTER DATABASE "stellar_d-demo_f9182c358a0a063cc6d6ec785140ec94_slave"  RENAME TO "d-demo"\n            ' {}

What am I missing? When I remove the database using pgAdmin before restoring, all is fine.

@ramonakira
Copy link
Author

Apparently Postgresql needs database-names escaped when they contain "-". And, apparently sqlalchemy does not do this automatically.

If I add database = '%s%s%s' % ('"', database, '"') to def remove_database() in operations.py, things are working for me again. Do you know of any way to maybe using configuration tell Sqlalchemy to escape databasenames?

@Teemu Teemu reopened this Nov 3, 2016
@mikeywaites
Copy link

mikeywaites commented Oct 31, 2017

Hey, I'm also seeing this issue with subsequent restore calls.

Traceback (most recent call last):
  File "/usr/local/bin/stellar", line 11, in <module>
    load_entry_point('stellar==0.4.3', 'console_scripts', 'stellar')()
  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 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/stellar/command.py", line 126, in restore
    app.inline_slave_copy(snapshot)
  File "/usr/local/lib/python2.7/site-packages/stellar/app.py", line 198, in inline_slave_copy
    table.get_table_name('slave')
  File "/usr/local/lib/python2.7/site-packages/stellar/operations.py", line 65, in copy_database
    from_database
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 906, in execute
    return self._execute_text(object, multiparams, params)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
    statement, parameters
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 200, 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 1139, in _execute_context
    context)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) database "stellar_cb87a70f797de380" already exists
 [SQL: '\n                CREATE DATABASE "stellar_cb87a70f797de380" WITH TEMPLATE "stellar_486d7ebb93677a14";\n

I'm sure when testing this earlier in the week i was able to call restore multiple times without any issue :/

Update: re-creating the snapshot and removing the old ones seem to have resolved the issue. Perhaps it's possible that the stellar_data table got in a weird state or something ? Will leave this here in case you want to pick this up.

Update 2: Issue has resurfaced already :/ I'll see if i can find a way to consistently re-produce this error.

@kiview
Copy link

kiview commented Jan 21, 2019

I'm seeing the same problem on PostgreSQl 9.6.11 running inside a Docker container.

In my case, this seems to be caused by #62.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants