PostgreSQL Cluster Management

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
postgresql

PostgreSQL Cluster Management

Use the initdb command to initialize a new data directory for the PostgreSQL cluster.
initdb -D /usr/local/pgsql/data

This command sets up the directory structure and creates default configuration files like postgresql.conf and pg_hba.conf.

Once the cluster is initialized, you can start the PostgreSQL server using pg_ctl.
pg_ctl -D /usr/local/pgsql/data -l logfile start
To stop the server, use:
pg_ctl -D /usr/local/pgsql/data stop
You can also specify the shutdown mode:
pg_ctl -D /usr/local/pgsql/data stop -m fast
  • smart: Waits for sessions to disconnect.

  • fast: Cancels active connections and shuts down cleanly (recommended).

  • immediate: Forceful shutdown, may require recovery.

To check whether the server is running with:
pg_ctl -D /usr/local/pgsql/data status

output

pg_ctl: server is running (PID: 2356)
/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data"

At Learnomate Technologies, we provide the best training on PostgreSQL and other database technologies. For more insights, visit our YouTube channel. Don’t forget to check out our website for more details about our training programs. Follow my Medium account @ankush.thavali for more articles and updates.