Thread: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
YuanyuanLiu
Date:
Hi, Hackers! Nowadays, I always got problem about postgresql windows service. I find, postgresql usually use the following command to register windows services: /"D:\Program Files (x86)\PostgreSQL\9.4\bin\pg_ctl.exe" runservice -N "postgresql-9.4" -D "D:\Program Files (x86)\PostgreSQL\9.4\data" -w/ But this command always failed, beacause of user privilege,just as a topic described: http://postgresql.nabble.com/pg-ctl-could-not-start-service-quot-pgsql-8-2-quot-error-code-1063-td1880801.html#a1880802 While'pg_ctl start -D ../data' works well, why not to use this command to register postgresql windows service? why to use 'pg_ctl runservice -N "psql" -D ".../data"' ? This is really confused me when I use postgresql in windows. Hope to hear from you! Regards! Liu Yuanyuan -- View this message in context: http://postgresql.nabble.com/Why-not-to-use-pg-ctl-start-D-data-to-register-posgtresql-windows-service-tp5872282.html Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.
Re: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
Michael Paquier
Date:
On Mon, Nov 2, 2015 at 2:54 PM, YuanyuanLiu <liuyuanyuangogo@gmail.com> wrote: > Nowadays, I always got problem about postgresql windows service. > I find, postgresql usually use the following command to register windows > services: > /"D:\Program Files (x86)\PostgreSQL\9.4\bin\pg_ctl.exe" runservice -N > "postgresql-9.4" -D "D:\Program Files (x86)\PostgreSQL\9.4\data" -w/ > But this command always failed, beacause of user privilege, just as a > topic described: > http://postgresql.nabble.com/pg-ctl-could-not-start-service-quot-pgsql-8-2-quot-error-code-1063-td1880801.html#a1880802 > While 'pg_ctl start -D ../data' works well, why not to use this command to > register postgresql windows service? why to use 'pg_ctl runservice -N "psql" > -D ".../data"' ? This is really confused me when I use postgresql in > windows. runservice is not a command that is aimed to be run manually, and that's what your link above refers to. A service should be registered using register, then you should use sc to start the service if you are doing it manually (you may do it automatically that's the default behavior then there is no need to use sc): pg_ctl register -N pg_service_name -D %PGDATA% -S demand sc start pg_service_name Now we could make the code more complicated in the start path to support that. And some users may want to be able to start a server on Windows without having to set up a service that lasts only for the time of a session. For example sometimes I do so for testing purposes. So that's quite handy to not rely on the Windows SCM in this case. -- Michael
Re: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
YuanyuanLiu
Date:
Hi, Michael! Thanks for your reply! I knew that postgresql windows service is made by "pg_ctl register -N serviceName -D dataPath". And command from service, like "D:\Program Files (x86)\PostgreSQL\9.4\bin\pg_ctl.exe" runservice -N "postgres-9.4" -D "D:\Program Files (x86)\PostgreSQL\9.4\data", cannot run manually like command line. I have a conclusion: When we registered postgresql windows service named "postgres-9.4", we can start the postgresql server by manually starting the windows service , runing command "net stop postgres-9.4" (need user with administrator privilege), or runing command "pg_ctl start -D ../path/to/data". The started postgresql service must be stopped in the same session. Is this right ? Looking forward to your reply! Regard! Liu Yuanyuan -- View this message in context: http://postgresql.nabble.com/Why-not-to-use-pg-ctl-start-D-data-to-register-posgtresql-windows-service-tp5872282p5872294.html Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.
Re: Re: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
Michael Paquier
Date:
On Mon, Nov 2, 2015 at 4:27 PM, YuanyuanLiu <liuyuanyuangogo@gmail.com> wrote: > When we registered postgresql windows service named "postgres-9.4", > we can start the postgresql server by manually starting the windows service > , runing command "net stop postgres-9.4" (need user with administrator > privilege), or runing command "pg_ctl start -D ../path/to/data". Yep. Those are two examples to stop a registered service. You could use "sc stop postgres-9.4" as well. Note also that when a service registered is stopped with pg_ctl, SCM will recognize that the service has been stopped. > The started postgresql service must be stopped in the same session. > Is this right ? When a service has been registered to the Windows SCM, a service started with sc or net will persist even if the prompt that started it is closed. Now, if you start a service with "pg_ctl start -d data", even if the service is registered it will *not* by recognized by SCM as started. And this one will stop immediately once the prompt that started it is closed. -- Michael
Re: Re: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
Michael Paquier
Date:
On Mon, Nov 2, 2015 at 9:30 PM, Michael Paquier <michael.paquier@gmail.com> wrote: > On Mon, Nov 2, 2015 at 4:27 PM, YuanyuanLiu <liuyuanyuangogo@gmail.com> wrote: >> When we registered postgresql windows service named "postgres-9.4", >> we can start the postgresql server by manually starting the windows service >> , runing command "net stop postgres-9.4" (need user with administrator >> privilege), or runing command "pg_ctl start -D ../path/to/data". I think you mean "net start" to start the server here and not "net stop". > Yep. Those are two examples to stop a registered service. You could > use "sc stop postgres-9.4" as well. Note also that when a service > registered is stopped with pg_ctl, SCM will recognize that the service > has been stopped. Er... I interpreted "start" by "stop" reading your last sentence. Please ignore this paragraph. -- Michael
Re: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
YuanyuanLiu
Date:
Yup, I think I totally understand now, the registered postgres service is different from "pg_ctl start". To start the postgres windows service needs privileged prompt (to execute net or sc command) or manually(start or stop in windows service list).After the service is started, it can be recognized by the SCM and will persist even if the prompt that started it is closed. While, using "pg_ctl start " needn't privileged prompt(normally prompt also ok), but after a service started, it cannot recognized by the SCM and will stop immediatlly when the prompt that started it is closed. I think registering postgres windows service is aim topersist the service when the prompt that started it need to be closed. I really learned a lot from you, and thank you! Regards! Liu Yuanyuan -- View this message in context: http://postgresql.nabble.com/Why-not-to-use-pg-ctl-start-D-data-to-register-posgtresql-windows-service-tp5872282p5872445.html Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.
Re: Re: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
Michael Paquier
Date:
On Tue, Nov 3, 2015 at 10:46 AM, YuanyuanLiu wrote: > I really learned a lot from you, and thank you! By the way, in the future you may want to ask general questions to pgsql-general, pgsql-hackers is where new features are being discussed and where technical discussions happen :) -- Michael
Re: Why not to use 'pg_ctl start -D ../data' to register posgtresql windows service
From
YuanyuanLiu
Date:
Ok, Michael! Thanks for your kindly remind! Regards! Liu Yuanyuan -- View this message in context: http://postgresql.nabble.com/Why-not-to-use-pg-ctl-start-D-data-to-register-posgtresql-windows-service-tp5872282p5872631.html Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.