Skip to content

PostgreSQL path

ganmath edited this page Apr 23, 2024 · 1 revision

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).

Temporary Path Update in PowerShell

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.

Permanent Path Update in PowerShell

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:

  1. Open PowerShell as Administrator - Right-click on PowerShell and select "Run as administrator" to ensure you have the necessary permissions to change system settings.

  2. Get the current PATH variable and store it in a variable:

    $currentPath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
  3. Add the PostgreSQL bin directory to the PATH variable:

    $newPath = $currentPath + ";C:\Program Files\PostgreSQL\16\bin"
  4. 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.

Verification

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 psql

This 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.

Clone this wiki locally