It's hard to do this automatically, because there could be a need for user intervention. There are three ingredients.
there is a file PG_VERSION, containing 10, 13, or whatever else. The script has to decide what to do based on that.
The command is pg_upgrade: 2x bindir and 2x datadir are mandatory, then first do --check to see if it works, then remove it and maybe use --link to make hardlinks. The hardlink variant is quicker, but there is no way back. So, a question here is, should this be done with a safety net or not. I would say yes.
move the current data dir to data-10 for version 10
execute pg_upgrade (first with --check) but without--link, targeting data
if it works, get rid of the backup in data-10 – otherwise remove data, report the problem, and rename data-10 to data and start the DB as usual. Next time, it will attempt to upgrade again.
configuration files. I haven't checked what docker configures, but there were params we had to change in production. wal_keep_size is new, while wal_keep_segments was removed: sed -i "/^wal_keep_segments/d" {PG_DATA}/postgresql.conf.
Oh, and in general, that new data dir must be setup fresh by the same user as the original database. IDK which one docker has, mabye postgres ? In any case, step one for ne new data dir is initdb -U [username], or maybe just the default, and step two is to copy over postgresql.conf and pg_hba.conf – or well, maybe we just write new config files and forget about copying and changing lines.
It's hard to do this automatically, because there could be a need for user intervention. There are three ingredients.
PG_VERSION
, containing10
,13
, or whatever else. The script has to decide what to do based on that.The command is pg_upgrade: 2x bindir and 2x datadir are mandatory, then first do
--check
to see if it works, then remove it and maybe use--link
to make hardlinks. The hardlink variant is quicker, but there is no way back. So, a question here is, should this be done with a safety net or not. I would say yes.data-10
for version 10pg_upgrade
(first with--check
) but without--link
, targetingdata
data-10
– otherwise removedata
, report the problem, and renamedata-10
todata
and start the DB as usual. Next time, it will attempt to upgrade again.wal_keep_size
is new, whilewal_keep_segments
was removed:sed -i "/^wal_keep_segments/d" {PG_DATA}/postgresql.conf
.Oh, and in general, that new data dir must be setup fresh by the same user as the original database. IDK which one docker has, mabye
postgres
? In any case, step one for ne new data dir isinitdb -U [username]
, or maybe just the default, and step two is to copy overpostgresql.conf
andpg_hba.conf
– or well, maybe we just write new config files and forget about copying and changing lines.