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?
The
service
command runs a System V-style init script. In this case you are running a script namedpostgreql
in the/etc/init.d
directory. This script likely has been written especially for Ubuntu and has the proper configuration information in it.