Skip to content

Instantly share code, notes, and snippets.

@lizTheDeveloper
Created July 13, 2024 02:32
Show Gist options
  • Save lizTheDeveloper/2e4db101355f63497a0457f1d3a6cf4e to your computer and use it in GitHub Desktop.
Save lizTheDeveloper/2e4db101355f63497a0457f1d3a6cf4e to your computer and use it in GitHub Desktop.
## This is a windows powershell script! It needs to be run as admin.
# Install Script for PostgreSQL 16 and pgAdmin4 on Windows
Write-Host "Downloading PostgreSQL 16..."
# Download and install PostgreSQL
Invoke-WebRequest -Uri https://get.enterprisedb.com/postgresql/postgresql-16.0-1-windows-x64.exe -OutFile postgresql-16.0-1-windows-x64.exe
Write-Host "Finished Downloading."
Write-Host "Setting up Postgres with superuser password tempstarbux"
Start-Process -FilePath "postgresql-16.0-1-windows-x64.exe" -ArgumentList "--mode unattended --superpassword tempstarbux --datadir C:\postgresql\data" -Wait
Write-Host "Setting up environment variables"
# Set environment variables
[System.Environment]::SetEnvironmentVariable('PGDATA', 'C:\postgresql\data', [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('PGDATABASE', 'postgres', [System.EnvironmentVariableTarget]::Machine)
Write-Host "Setting Admin Postgres User to postgres"
[System.Environment]::SetEnvironmentVariable('PGUSER', 'postgres', [System.EnvironmentVariableTarget]::Machine)
Write-Host "Setting Admin Postgres Password to postgrespassword"
[System.Environment]::SetEnvironmentVariable('PGPASSWORD', 'postgrespassword', [System.EnvironmentVariableTarget]::Machine)
Write-Host "Setting Port to 5432"
[System.Environment]::SetEnvironmentVariable('PGPORT', '5432', [System.EnvironmentVariableTarget]::Machine)
Write-Host "Setting Host to localhost"
[System.Environment]::SetEnvironmentVariable('PGHOST', 'localhost', [System.EnvironmentVariableTarget]::Machine)
Write-Host "Starting Service"
# Start PostgreSQL service
Start-Service -Name postgresql-x64-16
Write-Host "Service Started"
Write-Host "Downloading pgAdmin4..."
# Download and install pgAdmin4
Invoke-WebRequest -Uri "https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v8.9/windows/pgadmin4-8.9-x64.exe" -OutFile pgadmin4-8.9-x64.exe
Write-Host "Downloaded"
Write-Host "Starting Install..."
Start-Process -FilePath "pgadmin4-8.9-x64.exe" -ArgumentList "/SILENT" -Wait
Write-Host "Finished Install"
Write-Host "Cleaning Up Installers..."
# Clean up
Remove-Item postgresql-16.0-1-windows-x64.exe
Remove-Item pgadmin4-8.9-x64.exe
Write-Host "Done"
Write-Host "PostgreSQL 16 and pgAdmin4 installation completed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment