Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

update docs/postgres with how to upgrade database #10582

Closed
f1-outsourcing opened this issue Aug 11, 2021 · 6 comments
Closed

update docs/postgres with how to upgrade database #10582

f1-outsourcing opened this issue Aug 11, 2021 · 6 comments
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. X-Needs-Info This issue is blocked awaiting information from the reporter

Comments

@f1-outsourcing
Copy link

getting this error, with using new docker image. There should be a cli tool to verify/upgrade the database.

    SELECT setval('presence_stream_sequence', (
        SELECT GREATEST(MAX(stream_id), 0) FROM presence_stream
    ));

See docs/postgres.md for more information.

https://github.com/matrix-org/synapse/blob/develop/docs/postgres.md

@erikjohnston erikjohnston added the T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. label Aug 23, 2021
@richvdh
Copy link
Member

richvdh commented Sep 2, 2021

getting this error

which error?

@richvdh richvdh added the X-Needs-Info This issue is blocked awaiting information from the reporter label Sep 2, 2021
@richvdh
Copy link
Member

richvdh commented Sep 10, 2021

There should be a cli tool to verify/upgrade the database.

see #10793.

I'm going to close this, pending clearer information about what the problem is. We can reopen it if you can share the actual error you're seeing.

@richvdh richvdh closed this as completed Sep 10, 2021
@hungrymonkey
Copy link
Contributor

hungrymonkey commented Oct 25, 2021

@richvdh, I made a mistake recovering my installation. Here is one scenario for this error to happen. The SQL command works

Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: 2021-10-25 01:06:23,784 - root - 339 - WARNING - main - Server /usr/local/lib/python3.8/site-packages/synapse/app/ho>
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: 2021-10-25 01:06:23,957 - synapse.storage.util.sequence - 173 - WARNING - main - Postgres sequence presence_stream_s>
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: 2021-10-25 01:06:23,958 - synapse.app._base - 163 - ERROR - main - Exception during startup
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: Traceback (most recent call last):
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/app/homeserver.py", line 363, in setup
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     hs.setup()
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/server.py", line 311, in setup
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     self.datastores = Databases(self.DATASTORE_CLASS, self)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/__init__.py", line 76, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     main = main_store_class(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/__init__.py", line 178, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/events_bg_updates.py", line 80, in __i>
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/roommember.py", line 1136, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/room.py", line 1415, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/room.py", line 1030, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/room.py", line 73, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/registration.py", line 1784, in __init>
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/stream.py", line 320, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     super().__init__(database, db_conn, hs)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/presence.py", line 65, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     self._presence_id_gen = MultiWriterIdGenerator(
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/util/id_generators.py", line 309, in __init__
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     self._sequence_gen.check_consistency(
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:   File "/usr/local/lib/python3.8/site-packages/synapse/storage/util/sequence.py", line 180, in check_consistency
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     raise IncorrectDatabaseSetup(
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: synapse.storage.engines._base.IncorrectDatabaseSetup:
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: Postgres sequence 'presence_stream_sequence' is inconsistent with associated
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: table 'presence_stream'. This can happen if Synapse has been downgraded and
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: then upgraded again, or due to a bad migration.
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: To fix this error, shut down Synapse (including any and all workers)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: and run the following SQL:
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     SELECT setval('presence_stream_sequence', (
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:         SELECT GREATEST(MAX(stream_id), 0) FROM presence_stream
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:     ));
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: See docs/postgres.md for more information.
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: ******************************************************************************
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  Error during initialisation:
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  Postgres sequence 'presence_stream_sequence' is inconsistent with associated
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  table 'presence_stream'. This can happen if Synapse has been downgraded and
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  then upgraded again, or due to a bad migration.
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  To fix this error, shut down Synapse (including any and all workers)
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  and run the following SQL:
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:      SELECT setval('presence_stream_sequence', (
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:          SELECT GREATEST(MAX(stream_id), 0) FROM presence_stream
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:      ));
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  See docs/postgres.md for more information.
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]:  There may be more information in the logs.
Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: ******************************************************************************
Oct 25 01:06:24 ip-10-0-1-246 systemd[1]: matrix-synapse.service: Main process exited, code=exited, status=1/FAILURE
Oct 25 01:06:24 ip-10-0-1-246 systemd[1]: matrix-synapse.service: Failed with result 'exit-code'.

@squahtx
Copy link
Contributor

squahtx commented Oct 25, 2021

Could you post the full version of this line? It is cut off

Oct 25 01:06:23 ip-10-0-1-246 matrix-synapse[1162293]: 2021-10-25 01:06:23,957 - synapse.storage.util.sequence - 173 - WARNING - main - Postgres sequence presence_stream_s>

@richvdh
Copy link
Member

richvdh commented Oct 25, 2021

folks, please don't use github issues for support requests - particularly not unrelated, closed issues.

@hungrymonkey
Copy link
Contributor

hungrymonkey commented Oct 25, 2021

@richvdh I kinda want to give more content to this closed bug. I already fixed it a long time ago because the error shows the fix which is quite nice. I want to provide more content any case anyone decides to google this github issue. I should had made it clear in my initial post. My bad.

https://xkcd.com/979/

I am in the group who dislikes the xkcd above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. X-Needs-Info This issue is blocked awaiting information from the reporter
Projects
None yet
Development

No branches or pull requests

5 participants