Setting Windows PATH for Postgres tools

Viewed 148271

I cannot access PostgreSQL through the command line in Windows. Although I am able to create and update the databases, access them through PGAdminIII, and push to Heroku, I am unable to access them directly through my command line using the psql command.

When I try to create a database by using the command

$ createdb mydb

as explained in the PG documentation, I get the message

createdb: command not found

The documentation suggests that in this case, "PostgreSQL was not installed properly. Try calling the command with an absolute path instead." Sure enough, I am able to create a database by entering the direct path to the file:

$ c:/postgreSQL/9.1/bin/createdb mydb

Does this mean that the path can be reconfigured to connect correctly? Or do I need to reinstall? I've reinstalled several times, and have not been able to set the correct path. I currently have both the /bin and /lib paths addedto my system and user(:Umezo) paths, but still no access from the command line.

User variables for umezo
variable name: Path
variable value: C:\PostgreSQL\9.1\bin; C:\PostgreSQL\9.1\lib

System variables
variable name: Path
variable value: C:\PostgreSQL\9.1\bin; C:\PostgreSQL\9.1\lib

Any information or feedback regarding how I can fix my installment would be appreciated.

My info is as below:

I mostly followed these sources here and here. I installed a 32 bit version of 9.1 because some sources suggested issues with 64 bit.

PG download version: Installer Version 9.1 Win x86-32
Operating System: Windows 7 (64 bit)

pg_hba.conf

#TYPE     DATABASE     USER     CIER-ADDRESS     METHOD
# IPv4 local connections:
host      all          all      127.0.0.1/32     md5
# IPv6 local connections:
host      all          all      ::1/128          md5    

postgresql.conf

# - Connection Settings -
listen_addresses = '*'
port = 5432
max_connections = 100

pg_ident.conf

# *Everything is commented out*

Login Role Umezo #from properties window in PGAdminIII

Properties/Role name: Umezo
Properties/Can login: "check"
Role privileges: all categories "check"
9 Answers

Set path For PostgreSQL in Windows:

  1. Searching for env will show Edit environment variables for your account
  2. Select Environment Variables
  3. From the System Variables box select PATH
  4. Click New (to add new path)

Change the PATH variable to include the bin directory of your PostgreSQL installation.
then add new path their....[for example]

C:\Program Files\PostgreSQL\12\bin

After that click OK

Open CMD/Command Prompt. Type this to open psql

psql -U username database_name

For Example psql -U postgres test

Now, you will be prompted to give Password for the User. (It will be hidden as a security measure).

Then you are good to go.

In order to connect my git bash to the postgreSQL, I had to add at least 4 environment variables to the windows. Git, Node.js, System 32 and postgreSQL. This is what I set as the value for the Path variable: C:\Windows\System32;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\PostgreSQL\12\bin; and It works perfectly.

Set Environment in Windows

Our createdbfile exists in this marked folder .so copy this folder path and paste inside environment variables setting under system variables.

enter image description here

start -> Environment Variables

enter image description here

select Environment variable

enter image description here

Create a new environment variable like this

enter image description here

Add environment variable postgres as %postgres% in the path variable

enter image description here

Now check by taking a new command prompt and typing conda (close already opened terminal or cmd)

enter image description here

Now live

Related