Authentication failed for user "postgres"

Hello, I have an older version (8.14.1) of Sentry hosted on premise, and I am trying to prepare to move to hosting in the cloud.
I’ve been told that I can run the command “Sentry Export” to export our settings and then have those uploaded to the cloud version. This step would help us in the transition and would be one less process to worry about.

However when I ran the script “Sentry Export” on the box I got an error:
authentication failed for user “postgres”

I was not the user that setup this installation so I’m not very familiar with it. And searching here on the forums I didn’t find anything yet. I was hoping someone could point me in the right direction of what I should be investigating to fix this error and get the export file.

As well if anyone has any advice for going from on Prem to the cloud hosting I’d love to hear about it.

Hi @craig and sorry to hear there was a problem with the export command. Can you share more details about your setup and the logs of running this command, including how you run the command? :slight_smile:

Hello, I don’t know much about how it was setup. Do you want specific setup files?

What I do know is that it is running on Ubuntu 16.10, and it was installed using python.

We ran the commands by connecting to the box and running:
Sentry Export /home/stradmin/export.txt
OR
Sudo Sentry Export /home/stradmin/export.txt

We got the below message originally:

>> Beginning export
Traceback (most recent call last):
  File "/usr/local/bin/sentry", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/__init__.py", line 158, in main
    cli(prog_name=get_prog(), obj={}, max_content_width=100)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/decorators.py", line 36, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/commands/backup.py", line 142, in export
    use_natural_keys=True)
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/__init__.py", line 122, in serialize
    s.serialize(queryset, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/base.py", line 41, in serialize
    for obj in queryset:
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/commands/backup.py", line 136, in yield_objects
    for obj in queryset.iterator():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 220, in iterator
    for row in compiler.results_iter():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 713, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 785, in execute_sql
    cursor = self.connection.cursor()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 162, in cursor
    cursor = util.CursorWrapper(self._cursor(), self)
  File "/usr/local/lib/python2.7/dist-packages/sentry/db/postgres/decorators.py", line 42, in inner
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sentry/db/postgres/base.py", line 60, in _cursor
    cursor = super(DatabaseWrapper, self)._cursor()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 132, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 115, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATAL:  Peer authentication failed for user "postgres"

After a quick google we found a stack overflow thread that had a similar issue and they changed a postgres setting in pg_hba.conf from “Peer” to “trusted”. After restarting postgres with the following command we tried to export again:
sudo service postgresql restart

We then got the following error while using “Trusted” authentication

>> Beginning export
Traceback (most recent call last):
  File "/usr/local/bin/sentry", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/__init__.py", line 158, in main
    cli(prog_name=get_prog(), obj={}, max_content_width=100)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/decorators.py", line 36, in inner
    return ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/commands/backup.py", line 142, in export
    use_natural_keys=True)
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/__init__.py", line 122, in serialize
    s.serialize(queryset, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/serializers/base.py", line 41, in serialize
    for obj in queryset:
  File "/usr/local/lib/python2.7/dist-packages/sentry/runner/commands/backup.py", line 136, in yield_objects
    for obj in queryset.iterator():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 220, in iterator
    for row in compiler.results_iter():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 713, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 785, in execute_sql
    cursor = self.connection.cursor()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 162, in cursor
    cursor = util.CursorWrapper(self._cursor(), self)
  File "/usr/local/lib/python2.7/dist-packages/sentry/db/postgres/decorators.py", line 42, in inner
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sentry/db/postgres/base.py", line 60, in _cursor
    cursor = super(DatabaseWrapper, self)._cursor()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 132, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 115, in get_new_connection
    return Database.connect(**conn_params)
  File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATAL:  database "sentry" does not exist

Pretty sure you’ve hit by a recent postgres Docker image upgrade that is actually breaking. Make sure you are on this revision and you should be good: https://github.com/getsentry/onpremise/commit/6979959a710e74038472b4380bb5cc447e853690

BYK, we have no upgraded either postgres or sentry, both are running on an old version of ubuntu 16.10 that is End of Life. Thus items have not been upgraded.

Do we need to upgrade to the latest version of Sentry/Postgres in order to run the export command properly? I’m afraid upgrading our Ubuntu and then changing from out Python install to the docker install might be a fairly complex and labor intensive process. We were hoping to avoid the upgrade by switching to the cloud hosted version of Sentry.

Hi @craig, sorry I didn’t read your initial message carefully enough to note you were on a much older version :slight_smile:

May I ask if this is a Sentry instance actually running? Also can you try upgrading to at least 9.1.2 and try again? We’d love to help you get onboard with sentry.io without any data loss.