- SQL shell (command line)
- pgAdmin4 (Graphical interface)
Creating DB using SQL shell
Command that you can use to create a new DB is-
CREATE DATABASE dbname;
- Open SQL shell, provide the user name and password to connect to server.
- Type command CREATE DATABASE testdb; to create a database named testdb.
Please refer https://www.postgresql.org/docs/13/sql-createdatabase.html to see all the options for creating database in PostgreSQL.
You can use the \l command to see the list of DBs in PostgreSQL.
You can switch connections to a new database using \c command.
postgres=# \c testdb You are now connected to database "testdb" as user "postgres".
Creating DB using pgAdmin
In the left pane right click on Databases-Create-Database to open "Create - Database" window.
In the "Create - Database" window enter name of the DB and comment (optional). Click save to create the DB
Once the DB is created you will see the message for the same and the created DB in the left pane under the Databases.
You can verify the SQL that is executed for creating the DB by selecting the created DB in the left pane and selecting the SQL option on the right side.
That's all for this topic PostgreSQL - Create Database. If you have any doubt or any suggestions to make please drop a comment. Thanks!
You may also like-
No comments:
Post a Comment