Postgres uses the SQL language for database operations, so you'll need to use SQL commands to create and manage your database.
Installation
You can download and install it from the official PostgreSQL website.
After the installation, Postgres’s bin
directory must be added to the PATH system variable.
C:\Program Files\PostgreSQL\<version>\bin
To check if the Postgres was installed correctly, open a terminal or command prompt and enter:
psql --version
psql (PostgreSQL) 16.1
Start, stop and restart the Postgres server
Open a terminal or command prompt and navigate to Postgres bin
directory.
cd "C:\Program Files\PostgreSQL\<version>\bin"
Replace <version>
with your actual Postgres version.
To start the server:
pg_ctl -D "C:\Program Files\PostgreSQL\<version>\data" start
To restart the server:
pg_ctl -D "C:\Program Files\PostgreSQL\<version>\data" restart
To stop the server:
pg_ctl -D "C:\Program Files\PostgreSQL\<version>\data" stop
Now, you can open the psql shell to interact with the PostgreSQL database.
Interact with the psql shell
Once the Postgres server is running, now you can interact with the psql shell. Open a terminal or command prompt and enter:
psql --username postgres
Creating a database
Once you're in the psql command-line interface, you can create a new database with the following SQL command:
CREATE DATABASE webtuts_database;
Replace webtuts_database
with the desired name for your database.
Using the database
After creating the database, switch to it using the following command:
\c webtuts_database;