CREATE INDEX CONCURRENTLY cannot run inside a transaction block

7,228 views
Skip to first unread message

Thomas Guettler

unread,
May 14, 2012, 8:16:18 AM5/14/12
to south...@googlegroups.com
Hi,

I get the error:

CREATE INDEX CONCURRENTLY cannot run inside a transaction block

I use PostgreSQL 9.0 and django 1.3

I tried this patther, but this does not work:
db.commit_transaction()
db.execute('''CREATE INDEX CONCURRENTLY ...''')
db.start_transaction()

(traceback below)

Any hint how to create the index CONCURRENTLY?

Thomas Güttler

Traceback (most recent call last):
File "/home/modwork_eins_d/djangotools/bin/manage.py", line 74, in <module>
execute_manager(etc.settings)
File "/home/modwork_eins_d/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/modwork_eins_d/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/modwork_eins_d/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/modwork_eins_d/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/modwork_eins_d/south/management/commands/migrate.py", line 107, in handle
ignore_ghosts = ignore_ghosts,
File "/home/modwork_eins_d/south/migration/__init__.py", line 219, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/home/modwork_eins_d/south/migration/migrators.py", line 235, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/home/modwork_eins_d/south/migration/migrators.py", line 310, in migrate_many
result = self.migrate(migration, database)
File "/home/modwork_eins_d/south/migration/migrators.py", line 133, in migrate
result = self.run(migration)
File "/home/modwork_eins_d/south/migration/migrators.py", line 107, in run
return self.run_migration(migration)
File "/home/modwork_eins_d/south/migration/migrators.py", line 84, in run_migration
south.db.db.rollback_transaction()
File "/home/modwork_eins_d/south/db/generic.py", line 942, in rollback_transaction
transaction.leave_transaction_management()
File "/home/modwork_eins_d/django/db/transaction.py", line 56, in leave_transaction_management
connection.leave_transaction_management()
File "/home/modwork_eins_d/django/db/backends/__init__.py", line 111, in leave_transaction_management
raise TransactionManagementError("This code isn't under transaction "
django.db.transaction.TransactionManagementError: This code isn't under transaction management


--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

Andrew Godwin

unread,
May 14, 2012, 6:52:59 PM5/14/12
to south...@googlegroups.com
On 14/05/12 13:16, Thomas Guettler wrote:
> Hi,
>
> I get the error:
>
> CREATE INDEX CONCURRENTLY cannot run inside a transaction block
>
> I use PostgreSQL 9.0 and django 1.3
>
> I tried this patther, but this does not work:
> db.commit_transaction()
> db.execute('''CREATE INDEX CONCURRENTLY ...''')
> db.start_transaction()
>
> (traceback below)
>
> Any hint how to create the index CONCURRENTLY?

Nothing off the top of my head - you might need to turn off transaction
management completely, perhaps, as Django's cursor might be
auto-starting one for you.

(Obviously, South will do everything it can to run things inside
transactions, and thus CONCURRENTLY isn't really supported directly)

Andrew

Shai Berger

unread,
May 15, 2012, 3:43:57 AM5/15/12
to south...@googlegroups.com
On Tuesday, May 15, 2012 01:52:59 AM Andrew Godwin wrote:
> On 14/05/12 13:16, Thomas Guettler wrote:
> > Hi,
> >
> > I get the error:
> >
> > CREATE INDEX CONCURRENTLY cannot run inside a transaction block
> >
> > I use PostgreSQL 9.0 and django 1.3
> >
> > I tried this patther, but this does not work:
> > db.commit_transaction()
> > db.execute('''CREATE INDEX CONCURRENTLY ...''')
> > db.start_transaction()
> >
> > (traceback below)
> >
> > Any hint how to create the index CONCURRENTLY?
>
> Nothing off the top of my head - you might need to turn off transaction
> management completely, perhaps, as Django's cursor might be
> auto-starting one for you.
>
Yes, I think something along the lines of:

@django.db.transaction.commit_manually
def concurrently():
db.execute('''CREATE INDEX CONCURRENTLY ...''')

And then call concurrently() from within your migration.

Kien Nguyen Trung

unread,
Jul 9, 2014, 3:10:33 AM7/9/14
to south...@googlegroups.com
Any news from this issue? Using  @django.db.transaction.commit_manually, I still can not adding index concurrenly with South?

Does any hack way to do it.

I dont want to go to my database and type it manually

Andrew Godwin

unread,
Jul 9, 2014, 1:40:46 PM7/9/14
to south...@googlegroups.com
South doesn't have official support for this and never will - it's not being developed futher - but you should be able to do something with Django's transaction management to turn it off inside the migration and run the SQL. Something like transaction.commit() and then exiting transaction management might do it.

Andrew


--
You received this message because you are subscribed to the Google Groups "South Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to south-users...@googlegroups.com.

To post to this group, send email to south...@googlegroups.com.
Visit this group at http://groups.google.com/group/south-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages