I've started to learn about Postgres lately and the very first thing you need to do with Postgres is to install it on your computer! And me, being a Windows user, found it challenging to find documentation that walks you through it all in one place. So I thought I'd piece together what I learned.
Step 1: Download the installer from the Postgres website here and follow the instructions to install it
Step 2: Once it's installed, you'll need to add two folders to your PATH. (Found in Control Panel > System and Security > System > Advanced System Settings > Environment Variables)
For me Postgres installed into the folder: "C:\Program Files\PostgreSQL\12". So in your PATH you want to add both the bin and lib folder. So for example for me it was:
"C:\Program Files\PostgreSQL\12\bin"
"C:\Program Files\PostgreSQL\12\lib"
From this point on, we're talking about connecting through the command prompt. If you'd rather use a gui, pgAdmin is a good one to install and will be easier to use.
Step 3: Open up Command Prompt and to start up Postgres, type in the command:
pg_ctl -D "C:\Program Files\PostgreSQL\12\data" start
Note that if you are already connected and you want to restart instead, you can type "restart" instead of "start". And the same goes for stopping the server if it's already initialized. You can replace the above command where it says "start" with "stop"
Step 4: To login, use the following command:
psql -U <username>
Note that the default username upon installation is "postgres". Also, the <> are to show a variable. So if you were just using the default, then your command would be "psql -U postgres"
You'll be prompted for a password at that time. And if successfully logged in, you should see
postgres=#
Congrats! You're now logged into Postgres and can run whatever commands you need to from here on out.
Comments