How to reconnect to head after previously dealing with a broken update?

Had some problems several months ago and ultimately I had to go back to 2.9.0.beta1 and simply could not update any further at that time.

Due to various extenuating circumstances I had to walk way from this project for some time and am just now able to get back to it. I did discover that the root problem turned out to be that the PostgreSQL database server had not been sufficiently and properly upgraded, this has now been resolved and it’s running at PostgresQL 14.x and Discourse is also running on this version of the database now.

Unfortunately when I tried to upgrade again via the normal web admin upgrade user interface it indicated that fatal: HEAD does not point to a branch (full error here):

fatal: HEAD does not point to a branch
#<RuntimeError: RuntimeError>
/var/www/discourse/plugins/docker_manager/lib/docker_manager/upgrader.rb:203:in `run'

I thought I could perhaps do a /var/discourse/launcher rebuild app, but it did not end up working out either and only resulted in the same version starting back up, but I did notice the following output:

$ ./launcher rebuild app
x86_64 arch detected.

WARNING: We are about to start downloading the Discourse base image
This process may take anywhere between a few minutes to an hour, depending on your network speed

Please be patient

2.0.20220818-0047: Pulling from discourse/base
1efc276f4ff9: Pull complete
1b880e64942b: Pull complete
794f6dc9a2ff: Pull complete
Digest: sha256:7734701087766821ffb2ddcef423754798bd345c2ac0d550131c6e6905c268e8
Status: Downloaded newer image for discourse/base:2.0.20220818-0047
I, [2022-09-13T02:09:12.828649 #1]  INFO -- : Replacing # redis with sv start redis || exit 1 in /etc/service/unicorn/run
I, [2022-09-13T02:09:12.829826 #1]  INFO -- : > cd /var/www/discourse/plugins && git clone
Cloning into 'docker_manager'...
I, [2022-09-13T02:09:13.957219 #1]  INFO -- :
I, [2022-09-13T02:09:13.958187 #1]  INFO -- : > cd /var/www/discourse && git fetch --depth=1 origin tag v2.9.0.beta2 --no-tags
 * [new tag]           v2.9.0.beta2 -> v2.9.0.beta2
I, [2022-09-13T02:09:18.214516 #1]  INFO -- :
I, [2022-09-13T02:09:18.215535 #1]  INFO -- : > cd /var/www/discourse && git checkout v2.9.0.beta2
Note: switching to 'v2.9.0.beta2'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 88a85843 FIX: Cooking custom emojis should not use a secure URL (#15929)
I, [2022-09-13T02:09:19.557296 #1]  INFO -- :

I ended up reverting these changes by restoring a backup and thought I should ask for some input here first as to how I could and should get Discourse properly reconnected to HEAD on main and start building again with the most recent beta - and then after I finally get this back up-to-date, I’d like to lock it into a stable release update in the future. I had used betas to resolve a problem I was having this past year, but this has been enough of an adventure for me. :laughing:

Do you want discourse to make backups? You’ll need to contrive to upgrade the postgres stuff inside the container to use pg14. If it’s not too late to go back to PG 13,you’ll be happier if you do.

You should just do a command line rebuild.

Hmm I have a couple thoughts @pfaffman:

  • Thanks for pointing that out. I got so caught up in updating PGSQL that I forgot I needed to move to 13 instead of 14. I think I’m gonna cry!
  • Have you seen anyone successfully downgrade a database from 14 to 13?
  • In theory I should be able to add another cluster for 13 to the server so that both 13 and 14 are running, but I’m pretty much committed to 14 now with several other services now also running on the same server and I just can’t fiddle with them any further - so my only hope is to install a 13 instance and DOWNGRADE the Discourse one…
  • I tried the rebuild command, but it just didn’t work. You are referring to what I shared above, right?: /var/discourse/launcher rebuild app,

So that output contains a “Note”, but that’s not an error. You should expect the “detached head” message every time you check out a version that is not the latest.

1 Like

I know exactly how you feel.

That’s not my area of expertise. It’s much easier to update the container to have pg14 tools. As long as you don’t want to restore to a pg13 site you’ll be fine.

How did it not work? And if this is on your production server, you might want to do this on a test server first.