-
Notifications
You must be signed in to change notification settings - Fork 0
PostgreSQL path
To set the path to PostgreSQL binaries located at C:\Program Files\PostgreSQL\16\bin in PowerShell, you need to add it to the system's PATH environment variable. This can be done temporarily (just for the session you're currently using) or permanently (which affects all future PowerShell sessions).
To temporarily add the PostgreSQL bin directory to your PATH for the duration of your current PowerShell session, you can use the following command:
$env:PATH += ";C:\Program Files\PostgreSQL\16\bin"This command appends the PostgreSQL bin directory to the existing PATH variable for the current session. The change will be lost once you close the PowerShell window.
To permanently add the directory to your PATH, you need to modify the system environment variable. This can be done using the System Properties or via PowerShell. Here’s how to do it through PowerShell:
-
Open PowerShell as Administrator - Right-click on PowerShell and select "Run as administrator" to ensure you have the necessary permissions to change system settings.
-
Get the current PATH variable and store it in a variable:
$currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
-
Add the PostgreSQL bin directory to the PATH variable:
$newPath = $currentPath + ";C:\Program Files\PostgreSQL\16\bin"
-
Set the updated PATH variable:
[System.Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine")
This command updates the PATH environment variable for the machine, which means it will affect all users and all sessions. After executing this, you might need to restart your PowerShell session or your computer to apply the changes.
After updating the PATH, you can verify that it has been set correctly by opening a new PowerShell window (not the same one if you set it permanently, as it won't pick up environment changes without a restart) and running:
Get-Command psqlThis command should return the path to psql.exe if the PATH has been set correctly. If it doesn't return anything, ensure there were no typos and that PostgreSQL is indeed installed in the specified directory.