What is the difference between “service postgresql

2019-09-05 20:35发布

问题:

On Ubuntu 14.04, if i have the PGDATA environment variable set, the two commands

service postgresql start

And

pg_ctl start

seems to do the same thing: Start the postgres server in the background. Without PGDATA set, "pg_ctl start" needs needs the additional -D /datadir argument in order to start. The service does not need this. Why is this so? What is the difference between the two ways of starting the server? And how can the service start without knowing the data dir?

回答1:

The service command runs a System V-style init script. In this case you are running a script named postgreql in the /etc/init.d directory. This script likely has been written especially for Ubuntu and has the proper configuration information in it.