Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pages/common/pg_ctl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# pg_ctl

> Utility for controlling a PostgreSQL server and database cluster.

- Start a PostgreSQL server:

`pg_ctl -D {{data_directory}} -l {{log_file_name}}`

- Initialize a PostgreSQL database cluster:

`pg_ctl -D {{data_directory}} init`

- Stop a PostgreSQL server:

`pg_ctl -D {{data_directory}} stop`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to be root for the start/stop operations ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it's best practice to not run those as root. If you initialize the db and root owns the data directory then yes you need to be root to stop it, but the recommended way is to actually create a separate 'postgres' user and run it as that user:
su postgres -c 'pg_ctl start -D /usr/local/pgsql/data -l serverlog'
as per: https://www.postgresql.org/docs/9.1/static/server-start.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks.


- Restart a PostgreSQL server:

`pg_ctl -D {{data_directory}} restart`