installation hangs if postgres is not listening on default port

Bug #1307265 reported by Michael Hudson-Doyle on 2014-04-14
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
maas (Ubuntu)
Undecided
Unassigned

Bug Description

Hi,

If there is no postgres listening on port 5432 (which can happen when, for example, you install 9.1 on saucy, upgrade to trusty, thereby installing 9.3 and then purging 9.1), and install maas this happens:

Setting up maas-region-controller (1.5+bzr2236-0ubuntu1) ...
Considering dependency proxy for proxy_http:
Module proxy already enabled
Module proxy_http already enabled
Module expires already enabled
Module wsgi already enabled
rsyslog stop/waiting
rsyslog start/running, process 29785
squid-deb-proxy stop/waiting
squid-deb-proxy start/running, process 29839
 * Restarting message broker rabbitmq-server
   ...done.
Creating user "maas_longpoll" ...
...done.
Creating vhost "/maas_longpoll" ...
...done.
Setting permissions for user "maas_longpoll" in vhost "/maas_longpoll" ...
...done.
Changing password for user "maas_workers" ...
...done.
 * Restarting PostgreSQL 9.3 database server
   ...done.
dbconfig-common: writing config to /etc/dbconfig-common/maas-region-controller.conf
creating postgres user maas: success.
verifying creation of user: success.
creating database maasdb: success.
verifying database maasdb exists: success.
dbconfig-common: flushing administrative password
Syncing...
Traceback (most recent call last):
  File "/usr/bin/django-admin", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/usr/lib/python2.7/dist-packages/south/management/commands/syncdb.py", line 90, in handle_noargs
    syncdb.Command().execute(**options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/usr/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 159, in cursor
    cursor = util.CursorWrapper(self._cursor(), self)
  File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 129, in _cursor
    self.ensure_connection()
  File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 124, in ensure_connection
    self.connect()
  File "/usr/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 124, in ensure_connection
    self.connect()
  File "/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 112, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 116, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
    connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?

and then it hangs.

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in maas (Ubuntu):
status: New → Confirmed
Ubfan (ubfan1) wrote :

The Postgresql 9.3 update to Ubuntu 14.04 improperly changed the default port from 5432 to 5433.

Historically, port 5432 has been the default Postgresql port. Some update in 14.04 of Postgresql to 9.3.4-1 apparently decided to use 5433 as the default port. This change breaks things because header files like postgresql.conf have the default,5432, wired into them as both strings and numbers, so while psql will work on the new default port, existing compiled programs using
ecpg preprocessing fail and recompiling/reinking does not fix the problem either (because of the header files with the old default).
(Assuming everything was using the default, when no PGPORT environment variable has been explicitly set).

If you are going to change the port default, you have to do a complete job of altering all the header files, and at least warn users that the new Postgresql upgrade may require a recompile/relink of existing programs.

  A workaround to the ecpg programs (and anything else relying on the headers) is to explicitly set the environment variable PGPORT to 5433, just as if a non-default port is being used. The whole point of a default is that's what you get when you don't specify anything. A better workaround is to edit the 5433 back to 5432 in the postgresql.conf file, and restart.

The suggested fix is to NOT change the default port from 5432 in the first place.

no longer affects: postgresql (Ubuntu)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers