How to create a new database in PostgreSQL?
To create a new database in PostgreSQL, you can follow these steps:
- Open the command line interface or use a graphical user interface tool to connect to the PostgreSQL database.
- Use the following command to create a new database:
CREATE DATABASE database_name;
For example, to create a database named “mydatabase”, you can enter the following command:
CREATE DATABASE mydatabase;
- Make sure the database is successfully created. You can use the following command to list all the databases:
\l
This will list all databases, including the newly created ones.
- You can connect to the newly created database using the following command.
\c mydatabase
This will connect to a database called “mydatabase” where you can start creating tables and inserting data.
By following the above steps, you have successfully created a new database in PostgreSQL.