Database is copied keeping its internal structure intact which means all schemas and their tables and other objects are copied and made available in the new database. The above query instructs PostgreSQL engine to create a new database named ' demo2' using the template of the existing database ' demo'. Let us take a look at the below query query to explain the scenario. This statement copies the source_database to the target_database. PostgreSQL helps to achieve the same using the CREATE DATABASE statement as shown below: Basic Syntax: CREATE DATABASE target_database Copy database within the same serverĪt times it is required to create an exact copy of an existing database within the same server for development or testing purposes.
We will discuss both in this article.įirst we will discuss the process of copying a PostgreSQL database on the same server or from a server to another and then we will talk about various ways of copying an existing table to a new table in PostgreSQL.
There are two variants of 'COPY' statement, copy a database and copy a table. In this article, we will discuss the 'COPY' functionality of PostgreSQL database which is one of the most important and often used features in practical world.