Chapter 3. Creating Databases and Installing Extensions
In this chapter we’ll cover the basics of creating a database, adding various functionality you will need in a database via extensions, establishing privileges to the various objects in a database, and finally backup and restore of data.
Database Creation
Before you can create a database, you must be connected to an existing database. If you haven’t created any databases yet, the only database you will be able to connect to is the postgres database. After you have connected, the minimum SQL command to create a database is as follows:
CREATEDATABASEmydb;
This creates a new database replicated on the template1 database. The role logged-in becomes the owner of the database. Any role having CREATEDB attribute can create new databases. You can also create a database and assign ownership to a different role even if that role doesn’t have CREATEDB attribute:
CREATEDATABASEmydbOWNERleo;
Template Databases
A template database is, as the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access