New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew-postgresql-upgrade-database: add new command. #21244

Merged
merged 4 commits into from Jan 8, 2018

Conversation

Projects
None yet
5 participants
@MikeMcQuaid
Copy link
Member

MikeMcQuaid commented Dec 1, 2017

This works nicely for me so let's throw it threw the review process and ask some users to test and see how it goes.

@MikeMcQuaid

This comment has been minimized.

Copy link
Member Author

MikeMcQuaid commented Dec 1, 2017

Actually, I think I make this an external command instead.

@seebq

This comment has been minimized.

Copy link

seebq commented Dec 1, 2017

If this works, great, I would support it (coming from this gist):

https://gist.github.com/giannisp/ebaca117ac9e44231421f04e7796d5ca

Untested but I would approve!

@stale

This comment has been minimized.

Copy link

stale bot commented Dec 22, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Dec 22, 2017

@MikeMcQuaid MikeMcQuaid removed the stale label Dec 24, 2017

@MikeMcQuaid MikeMcQuaid changed the title postgresql: autoupgrade in post_install. brew-postgresql-upgrade-database: add new command. Jan 8, 2018

@ilovezfs ilovezfs removed the do not merge label Jan 8, 2018

@MikeMcQuaid MikeMcQuaid merged commit 25d5a9e into Homebrew:master Jan 8, 2018

1 check failed

continuous-integration/jenkins/ghprb Build finished.
Details

@MikeMcQuaid MikeMcQuaid deleted the MikeMcQuaid:pg_upgrade branch Jan 8, 2018

@mhw

This comment has been minimized.

Copy link

mhw commented Jan 8, 2018

Hmm; the documentation says brew postgresql-upgrade-database, but the file containing the script is named brew-postgresql-data-upgrade.rb so you need to use brew postgresql-data-upgrade instead. On the plus side, the upgrade script worked fine for me once I figured out how to run it.

@MikeMcQuaid

This comment has been minimized.

Copy link
Member Author

MikeMcQuaid commented Jan 9, 2018

@mhw Oops, thanks, fixed in d474d48.

@olivierlacan

This comment has been minimized.

Copy link
Contributor

olivierlacan commented Feb 7, 2018

@MikeMcQuaid This is so nice I finally upgraded an old PG upgrade guide I had lying around into a post that mentions this new command.

Thanks so much for putting the work into this. I remember thinking "why doesn't this exist" for years and that was the primary motivation behind that old brain dump of a Gist.

I did find that if postmaster.pid is locked, which stops or prevents the upgrade, re-running the commands tends to die at the topmost version-checking conditional even if the old data directory hasn't been upgraded yet.

I solved the issue by remove postmaster.pid and opening the /usr/local/var/log/pg_upgrade_server.log file which had the full upgrade command:

-----------------------------------------------------------------
  pg_upgrade run on Wed Feb  7 07:45:02 2018
-----------------------------------------------------------------

command: "/usr/local/Cellar/postgresql/9.5.0/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/usr/local/var/postgres.old" -o "-p 50432 -c autovacuum=off -c autovacuum_freeze_max_age=2000000000  -c listen_addresses='' -c unix_socket_permissions=0700" start >> "pg_upgrade_server.log" 2>&1
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start....FATAL:  pre-existing shared memory block (key 5432001, ID 65536) is still in use
HINT:  If you're sure there are no old server processes still running, remove the shared memory block or just delete the file "postmaster.pid".
 stopped waiting
pg_ctl: could not start server
Examine the log output.

I just re-ran the command at the top which did the trick.

I think not being able to re-run the upgrade command stems from the fact that call to mv the datadir to old_datadir and initialize the new datadir happen much earlier than the actual pg_ctl upgrade command which then fails due to postmaster.pid, leaving the upgrade process in a state the script can't recover from.

ohai "Moving #{name} data from #{datadir} to #{old_datadir}..."
FileUtils.mv datadir, old_datadir
moved_data = true
(var/"postgres").mkpath
system "#{bin}/initdb", "#{var}/postgres"
initdb_run = true

Maybe it would help to check for postmaster.pid before running the initdb command?

@MikeMcQuaid

This comment has been minimized.

Copy link
Member Author

MikeMcQuaid commented Feb 9, 2018

@olivierlacan Thanks for the kind words!

Maybe it would help to check for postmaster.pid before running the initdb command?

Seems like a good idea. Could you try and open a pull request (as you seem to understand this better than I do)? This document should help and we're happy to walk you through anything else.

Thanks!

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.