PostgreSQL Cluster
A PostgreSQL cluster is a collection of several databases that all run under the very same PostgreSQL service or instance.
Locating the database server files
Cluster files are initially stored in a location referred to as data directory:
SHOW data_directory;
$PGDATAis where the database files live. You can also useinitdbto create the database directory:initdb -D <path>
Cluster Management with pg_ctl
Starting and Stopping the Cluster
# wait for all connections...
pg_ctl stop -m s[mart]
# force disconnect
pg_ctl stop -m f[ast]
# SIGQUIT
pg_ctl stop -m i[mmediate]
Restarts
Reload
The Console (psql)
Most commonly used options:
| Options |
|---|
--host or -h |
--port or -p |
--username or -u |
--dbname or -d |
The command \? shows all \ commands available. Some useful commands are:
# lists all databases in the cluster
\l
# adds additional information
\l+
# switches to a different database in the cluster
\c <dbname>
to gather information about database objects (in the current database), use
different variations of \d:
-- tables
\dt
-- sequences
\ds
-- indexes
\di
-- schemas
\dn
-- functions
\df
-- users/roles
\du
-- extensions installed
\dx