How to create a new database from template1?

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

  1. Open psql: Connect to your PostgreSQL server using the psql command-line interface.

    psql -U your_username -d postgres
  2. Run the Command: Execute the CREATE DATABASE command as shown above.

  3. 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!

0 Comments

no data
Be the first to share your comment!