While PostgreSQL is commonly considered an RDBMS, or a
"database," it may not be commonly understood what is meant
specifically by the word
database
. A database
within PostgreSQL is an object-relational implementation of what is
formally called a
schema
in SQL99.
Put simply, a database is a stored set of data that is
logically interrelated. Typically, this data can be accessed in a
multiuser environment. This is the case with PostgreSQL, though there
are well-defined rights and restrictions enforced with that
access.
It may not be commonly understood that PostgreSQL can
have
several
databases concurrently
available, each with their own owner, and each with their own unique
tables, views, indices, sequences, and functions.
In order to create a table, function, or any other database
object, you must connect to a specific database via a PostgreSQL
client
. Once connected, you can create an object,
which is then
owned
by the connected database,
and therefore is inaccessible from any other database (though a
client may have several connections open to different
databases).
By keeping fundamental data objects segregated into their own
databases in this fashion, you run a smaller risk of running into a
naming collision by choosing a table name already chosen for another
purpose (e.g., if two users each wanted to have a table called
products for two separate applications). This is because neither
database has any knowledge of the other database's components, and
will not attempt to make any kind of logical relationship between
them. Furthermore, as the same rule applies to object-relational data
objects, users may even create functions and language definitions
within their database that are inaccessible to other users connected
to other databases running within PostgreSQL.
By default, PostgreSQL installs only one functional database, which is called
template1 to represent the
template nature of the database. Any database created after template1 is essentially a clone, inheriting any of its
database objects, including table structure, functions, languages, etc. It is not uncommon to create a default database for
new PostgreSQL users with the same name as their PostgreSQL username, as PostgreSQL will attempt to connect to a database
with the same name as the connecting user if a database name is not specified.