DEV Community

Adrian Carter
Adrian Carter

Posted on • Updated on

How To Create a Database in PostgreSQL using Git Bash

To create a database in PostgreSQL using Git Bash, you can follow these steps:

Step 1: Install PostgreSQL: If you haven't already, download and install PostgreSQL on your computer. Make sure it's properly installed and running.

Step 2: Open Git Bash: Launch Git Bash on your computer. It provides a command-line interface to execute commands.

Step 3: Access PostgreSQL: In Git Bash, you need to access the PostgreSQL command-line interface (CLI) to create a database. Use the following command to connect:

 psql -U postgres
Enter fullscreen mode Exit fullscreen mode

This assumes that the default username for PostgreSQL is "postgres". If you have a different username, replace "postgres" with your username.

Step 4: Enter Password: After executing the above command, it will prompt you to enter the password for the PostgreSQL user. Type the password and press Enter.

Side Note: For security reasons, when entering your password in the terminal, the characters you type won't be displayed. Nevertheless, the system will register what you type.

Step 5: Create Database: Once you're connected to the PostgreSQL CLI, you can create a database using the following command:

CREATE DATABASE your_database_name;
Enter fullscreen mode Exit fullscreen mode

Replace "your_database_name" with the desired name for your database. Make sure to avoid using spaces or special characters.

Step 6: Verify Creation: To confirm that the database was created successfully, you can list all databases using the command:

\l
Enter fullscreen mode Exit fullscreen mode

This will display a list of all databases, including the one you just created. You can also use pgAdmin4, a management tool for PostgreSQL, to view your existing databases as well.

Step 7: Exit PostgreSQL CLI: When you're finished working with the PostgreSQL CLI, you can exit by typing:

\q
Enter fullscreen mode Exit fullscreen mode

This will return you to the Git Bash command prompt.

That's it! You have now created a database in PostgreSQL using Git Bash. You can use this database for your applications or further database operations.

Top comments (0)