cookiecutter-django icon indicating copy to clipboard operation
cookiecutter-django copied to clipboard

Postgresql Docker Update breaks docker configuration

Open burhan opened this issue 9 years ago • 3 comments

If the posgresql version is updated, any existing directories become invalid and docker-compose can no longer bring the container up; results in the following error:

Creating projectname_django_1
Attaching to projectname_postgres_1, projectname_django_1
postgres_1 | FATAL:  database files are incompatible with server
postgres_1 | DETAIL:  The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 9.5rc1.
projectname_postgres_1 exited with code 1
django_1   | /usr/local/lib/python3.5/site-packages/django/core/management/base.py:265: RemovedInDjango110Warning: OptionParser usage for Django management commands is deprecated, use ArgumentParser instead
django_1   |   RemovedInDjango110Warning)
django_1   |
django_1   | Performing system checks...
django_1   |
django_1   | System check identified no issues (0 silenced).
django_1   | Traceback (most recent call last):
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
django_1   |     self.connect()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 171, in connect
django_1   |     self.connection = self.get_new_connection(conn_params)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection
django_1   |     connection = Database.connect(**conn_params)
django_1   |   File "/usr/local/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
django_1   |     conn = _connect(dsn, connection_factory=connection_factory, async=async)
django_1   | psycopg2.OperationalError: could not translate host name "postgres" to address: Name or service not known
django_1   |
django_1   |
django_1   | The above exception was the direct cause of the following exception:
django_1   |
django_1   | Traceback (most recent call last):
django_1   |   File "/app/manage.py", line 10, in <module>
django_1   |     execute_from_command_line(sys.argv)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
django_1   |     utility.execute()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 342, in execute
django_1   |     self.fetch_command(subcommand).run_from_argv(self.argv)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
django_1   |     self.execute(*args, **cmd_options)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
django_1   |     output = self.handle(*args, **options)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django_extensions/management/utils.py", line 57, in inner
django_1   |     ret = func(self, *args, **kwargs)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django_extensions/management/commands/runserver_plus.py", line 332, in handle
django_1   |     inner_run()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django_extensions/management/commands/runserver_plus.py", line 250, in inner_run
django_1   |     self.check_migrations()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django_extensions/management/commands/runserver_plus.py", line 339, in check_migrations
django_1   |     executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 20, in __init__
django_1   |     self.loader = MigrationLoader(self.connection)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 49, in __init__
django_1   |     self.build_graph()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 176, in build_graph
django_1   |     self.applied_migrations = recorder.applied_migrations()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
django_1   |     self.ensure_schema()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
django_1   |     if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 231, in cursor
django_1   |     cursor = self.make_debug_cursor(self._cursor())
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 204, in _cursor
django_1   |     self.ensure_connection()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
django_1   |     self.connect()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/utils.py", line 95, in __exit__
django_1   |     six.reraise(dj_exc_type, dj_exc_value, traceback)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
django_1   |     raise value.with_traceback(tb)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
django_1   |     self.connect()
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/base/base.py", line 171, in connect
django_1   |     self.connection = self.get_new_connection(conn_params)
django_1   |   File "/usr/local/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection
django_1   |     connection = Database.connect(**conn_params)
django_1   |   File "/usr/local/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
django_1   |     conn = _connect(dsn, connection_factory=connection_factory, async=async)
django_1   | django.db.utils.OperationalError: could not translate host name "postgres" to address: Name or service not known
django_1   |
projectname_django_1 exited with code 1

burhan avatar Jan 06 '16 12:01 burhan

Upgrades between major postgres versions are always a bit tricky because they often change internal files: http://www.postgresql.org/docs/9.5/static/upgrading.html

There's nothing we can do about it on our side to prevent that (other than writing a behemoth of an upgrade file/ stick on postgres 9.4 forever). The normal use case of cookiecutter-django, in my view, is to start a project based on the template and go on from there on your own.

Sure, it's always a good idea to look what's happening on upstream but once you upgrade a major component you can't expect that everything just works.

What do you think?

jayfk avatar Jan 06 '16 15:01 jayfk

Having gone through it myself (a postgresql upgrade) - I have to agree; however for the sake of the audience I think the documentation/guide should be updated and add this as a FAQ. Thoughts?

burhan avatar Jan 06 '16 17:01 burhan

@burhan do you have some notes on your experience going through an upgrade? Is there anything specific to cookiecutter-django worth mentioning or is it just a matter of linking to the PostgreSQL upgrade page?

browniebroke avatar Sep 16 '18 12:09 browniebroke

@browniebroke I've gone through the process myself and have few notes to share (#4898).

The specific part to cookiecutter-django is the use of postgres backup and postgres restore ...sql.gz commands.

The restore needs to be performed on upgraded and running postgres container with previous data volume removed, otherwise the reported could not translate host name "postgres" to address error will be thrown.

SukiCZ avatar Mar 01 '24 12:03 SukiCZ