DigitalDouble
DigitalDouble

Reputation: 1768

Why is my new PostgreSQL database not empty?

Whenever I create a new database from pgAdmin or using the command line (using CREATE DATABASE database_name), it's not empty.

It contains some tables that are part of a previous project I worked on.

I'm not yet very familiar with Psql so I don't know what I'm doing wrong.

Upvotes: 1

Views: 1133

Answers (1)

user330315
user330315

Reputation:

You probably have created objects in the database template1.

Quote from the manual:

By default, the new database will be created by cloning the standard system database template1. A different template can be specified by writing TEMPLATE name. In particular, by writing TEMPLATE template0, you can create a virgin database containing only the standard objects predefined by your version of PostgreSQL. This is useful if you wish to avoid copying any installation-local objects that might have been added to template1.

So, anything that is in the template1 database will be copied over to the new database when you run create database.

Connect to the template1 database and drop all objects you don't want.

Upvotes: 4

Related Questions