TEXT 25
Tablespaces.txt Guest on 29th April 2021 06:43:01 AM
  1. ===========
  2. Tablespaces
  3. ===========
  4.  
  5. A common paradigm for optimizing performance in database systems is the use of
  6. `tablespaces`_ to organize disk layout.
  7.  
  8. .. _`tablespaces`: http://en.wikipedia.org/wiki/Tablespace
  9.  
  10. .. warning::
  11.     Django does not create the tablespaces for you. Please refer to your
  12.     database engine's documentation for details on creating and managing
  13.     tablespaces.
  14.  
  15.  
  16. Declaring tablespaces for tables
  17. --------------------------------
  18.  
  19. A tablespace can be specified for the table generated by a model by supplying
  20. the :attr:`~django.db.models.Options.db_tablespace` option inside the model's
  21. ``class Meta``. This option also affects tables automatically created for
  22. :class:`~django.db.models.ManyToManyField`\ s in the model.
  23.  
  24. You can use the :setting:`DEFAULT_TABLESPACE` setting to specify a default value
  25. for :attr:`~django.db.models.Options.db_tablespace`. This is useful for setting
  26. a tablespace for the built-in Django apps and other applications whose code you
  27. cannot control.
  28.  
  29. Declaring tablespaces for indexes
  30. ---------------------------------
  31.  
  32. You can pass the :attr:`~django.db.models.Field.db_tablespace` option to a
  33. ``Field`` constructor to specify an alternate tablespace for the ``Field``’s
  34. column index. If no index would be created for the column, the option is
  35. ignored.
  36.  
  37. You can use the :setting:`DEFAULT_INDEX_TABLESPACE` setting to specify
  38. a default value for :attr:`~django.db.models.Field.db_tablespace`.
  39.  
  40. If :attr:`~django.db.models.Field.db_tablespace` isn't specified and you didn't
  41. set :setting:`DEFAULT_INDEX_TABLESPACE`, the index is created in the same
  42. tablespace as the tables.
  43.  
  44. An example
  45. ----------
  46.  
  47. .. code-block:: python
  48.  
  49.     class TablespaceExample(models.Model):
  50.         name = models.CharField(max_length=30, db_index=True, db_tablespace="indexes")
  51.         data = models.CharField(max_length=255, db_index=True)
  52.         edges = models.ManyToManyField(to="self", db_tablespace="indexes")
  53.  
  54.         class Meta:
  55.             db_tablespace = "tables"
  56.  
  57. In this example, the tables generated by the ``TablespaceExample`` model (i.e.
  58. the model table and the many-to-many table) would be stored in the ``tables``
  59. tablespace. The index for the name field and the indexes on the many-to-many
  60. table would be stored in the ``indexes`` tablespace. The ``data`` field would
  61. also generate an index, but no tablespace for it is specified, so it would be
  62. stored in the model tablespace ``tables`` by default.
  63.  
  64. Database support
  65. ----------------
  66.  
  67. PostgreSQL and Oracle support tablespaces. SQLite and MySQL don't.
  68.  
  69. When you use a backend that lacks support for tablespaces, Django ignores all
  70. tablespace-related opt

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.