To create a new database from template1 in PostgreSQL, you can use the CREATE DATABASE SQL command. Here’s the syntax:
CREATE DATABASE new_database_name TEMPLATE template1;
Example
If you want to create a new database named my_new_database, you would run:
CREATE DATABASE my_new_database TEMPLATE template1;
Steps to Execute
-
Open psql: Connect to your PostgreSQL server using the
psqlcommand-line interface.psql -U your_username -d postgres -
Run the Command: Execute the
CREATE DATABASEcommand as shown above. -
Verify Creation: You can list all databases to confirm that your new database has been created:
\l
This will create a new database based on the structure and objects present in template1. If you have any further questions, feel free to ask!
