forked from CCCHH/nix-infra
		
	Add and run script for upgrading PostgreSQL of matrix host
The script is a modified version of the script shown in the PostgreSQL Upgrading section of the NixOS manual. Our version is for upgrading PostgreSQL 14 to 15. Basically do steps 1-3 of the section. Link to the section: https://nixos.org/manual/nixos/stable/#module-services-postgres-upgrading
This commit is contained in:
		
					parent
					
						
							
								87e6735662
							
						
					
				
			
			
				commit
				
					
						0944a1749c
					
				
			
		
					 1 changed files with 29 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -14,4 +14,33 @@
 | 
			
		|||
 | 
			
		||||
    dataDir = "/mnt/data/postgresql/${config.services.postgresql.package.psqlSchema}";
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  # Modified version of the script for upgrading PostgreSQL from here:
 | 
			
		||||
  # https://nixos.org/manual/nixos/stable/#module-services-postgres-upgrading
 | 
			
		||||
  environment.systemPackages = [
 | 
			
		||||
    (let
 | 
			
		||||
      newPostgres = pkgs.postgresql_15;
 | 
			
		||||
    in pkgs.writeScriptBin "upgrade-pg-cluster" ''
 | 
			
		||||
      set -eux
 | 
			
		||||
 | 
			
		||||
      systemctl stop matrix-synapse.service
 | 
			
		||||
      systemctl stop postgresql.service
 | 
			
		||||
 | 
			
		||||
      export NEWDATA="/mnt/data/postgresql/${newPostgres.psqlSchema}"
 | 
			
		||||
 | 
			
		||||
      export NEWBIN="${newPostgres}/bin"
 | 
			
		||||
 | 
			
		||||
      export OLDDATA="${config.services.postgresql.dataDir}"
 | 
			
		||||
      export OLDBIN="${config.services.postgresql.package}/bin"
 | 
			
		||||
 | 
			
		||||
      install -d -m 0700 -o postgres -g postgres "$NEWDATA"
 | 
			
		||||
      cd "$NEWDATA"
 | 
			
		||||
      sudo -u postgres $NEWBIN/initdb -D "$NEWDATA"
 | 
			
		||||
 | 
			
		||||
      sudo -u postgres $NEWBIN/pg_upgrade \
 | 
			
		||||
        --old-datadir "$OLDDATA" --new-datadir "$NEWDATA" \
 | 
			
		||||
        --old-bindir $OLDBIN --new-bindir $NEWBIN \
 | 
			
		||||
        "$@"
 | 
			
		||||
    '')
 | 
			
		||||
  ];
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue