I would like to know correct way of starting/stopping postgres database. There are two ways
pg_ctl start/stop
service postgresql start/stop
I would like to know how they are different from each other, which one should I use? are their any pros/cons.
I check online but didnt get satisfactory answer.
Thanks in advance
pg_ctl is a utility for initializing a PostgreSQL database cluster, starting, stopping, or restarting the PostgreSQL database server (postgres), or displaying the status of a running server.
Postgres service allows you to provision PostgreSQL databases instances and store your data in them. PostgreSQL is an object-oriented relational database management system to store data securely for retrieval at the request of other software applications.
To start:
brew services start postgresql
To stop:
brew services stop postgresql
To start:
pg_ctl start -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log
To stop:
pg_ctl stop -D /usr/local/var/postgres -m smart
See: https://www.postgresql.org/docs/current/app-pg-ctl.html
If you view /etc/init.d/postgres${VER}
file, you will find out, that when you run service postgresql start/stop
it runs pg_ctl $OPTIONS start/stop
. The only difference is that service gives you handy way to store environmental variables and enable/disable autostart.
All above can be done manually, using pg_ctl
and some scripting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With