Add upgrade path for postgresql
This commit is contained in:
		
							parent
							
								
									ac52cbc842
								
							
						
					
					
						commit
						b3bed1353f
					
				
					 2 changed files with 37 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -21,6 +21,7 @@
 | 
			
		|||
    ./mail-server.nix
 | 
			
		||||
    ./webmail.nix
 | 
			
		||||
    ./gotosocial.nix
 | 
			
		||||
    ../upgrade/postgresql.nix
 | 
			
		||||
    #./akkoma.nix
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										36
									
								
								nixos/upgrade/postgresql.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								nixos/upgrade/postgresql.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
{
 | 
			
		||||
  config,
 | 
			
		||||
  pkgs,
 | 
			
		||||
  ...
 | 
			
		||||
}: {
 | 
			
		||||
  environment.systemPackages = [
 | 
			
		||||
    (let
 | 
			
		||||
      # XXX specify the postgresql package you'd like to upgrade to.
 | 
			
		||||
      # Do not forget to list the extensions you need.
 | 
			
		||||
      newPostgres = pkgs.postgresql_15.withPackages (pp: [
 | 
			
		||||
        # pp.plv8
 | 
			
		||||
      ]);
 | 
			
		||||
    in
 | 
			
		||||
      pkgs.writeScriptBin "upgrade-pg-cluster" ''
 | 
			
		||||
        set -eux
 | 
			
		||||
        # XXX it's perhaps advisable to stop all services that depend on postgresql
 | 
			
		||||
        systemctl stop postgresql
 | 
			
		||||
 | 
			
		||||
        export NEWDATA="/var/lib/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