Postgres Cygwin Install-as-Service on XP Pro/Home Mini HOWTO
Postgres Cygwin Install-as-Service on XP Pro/Home Mini HOWTO
От:
Kevin Wong <kevin-wong@usa.net>
Дата:
Windows XP Home and Professional behave slightly different, compared to Windows NT/2000, especially on issues of services and security models. Therefore, the original instructions for installing postgres as a service don't quite work with XP Home or Pro.
Here's what I've learned so far, which may be of great help to those struggling with the same problem.
Windows XP Professional:
I haven't tried Postgres on Cygwin for XP Pro myself yet, but I believe that you just need to follow all of the instructions in the /usr/doc/Cygwin/postgresql-X.X.X-Readme file, as you would for Windows NT or 2000.
BUT!!!! Swap Excerpted Steps 7 and 8. "initdb" won't actually run successfully without ipc-daemon running in the background first, in my experience.
Windows XP Home:
Because Windows XP Home has a number of differences from XP Pro, primarily in user accounts/management, you can't simply follow the standard NT/2000 install-as-service instructions. You have to do a few things differently.
In case you're wondering or are confused, the following is an excerpt from the /usr/doc/Cygwin/postgresql-7.2.1.README file, which is the additional readme for Cygwin-specific issues for postgres. Note all of the standard, non-Cygwin-specific docs are found in /usr/doc/postgresql-7.2.1.
***************
BEGIN EXCERPT
***************
The following is the NT services Cygwin PostgreSQL installation procedure:
1. Install the cygipc ipc-daemon as a NT service:
# ipc-daemon --install-as-service
2. Create the "postgres" user account:
# cmd /c lusrmgr.msc # [3]
# mkpasswd -l -u postgres >>/etc/passwd
3. Grant the "postgres" user the "Log on as a service" user right:
# cmd /c secpol.msc [4]
4. Install postmaster as a NT service:
# cygrunsrv --install postmaster --path /usr/bin/postmaster --args "-D /usr/share/postgresql/data -i" --dep ipc-daemon --termsig INT --user postgres --shutdown
5. Create the PostgreSQL data directory:
# mkdir /usr/share/postgresql/data
6. Change ownership of the PostgreSQL data directory:
# chown postgres /usr/share/postgresql/data
7. Initialize PostgreSQL (*when running under the "postgres" account*):
$ initdb -D /usr/share/postgresql/data
8. Start the cygipc ipc-daemon:
# net start ipc-daemon
9. Start postmaster:
# net start postmaster
10. Connect to PostgreSQL:
# psql -U postgres template1
*************
END EXCERPT
*************
Compared to the excerpt, XP Home has a few differences, again, because of its limited security model.
You must do all of the following from within a a Cygwin shell, logging into Windows XP Home as an administrative user (any non-guest user), preferably your normal user account. The account that was used to install Cygwin is ideal due to some default filename/permissions that Cygwin used during installation of itself, and of the postgres package.
I do everything on my machine as "kwong", so it was a natural choice to log-in as kwong and launch a Cygwin shell under that user id. That's the user account I use in the examples below. Substitute the appropriate user account for your own installation.
Exerpted Step 1 works just fine.
Excerpted Step 2 and Step 3 don't work at all under XP Home, again due to limitations. Skip them completely.
Excerpted Step 4 is very close, but doesn't quite work due to some funky file/directory/login permissions. That's why the discussion above about using the same user that had installed Cygwin and postgres to begin with...
So, instead of the command used in Excerpted Step 4, use this:
$ cygrunsrv --install "Cygwin postgres" --path /usr/bin/postmaster --args "-D /usr/share/postgresql/data -i" --dep ipc-daemon --termsig INT --user kwong --shutdown
Note, I'm assuming (as does the original readme) that you're going to be using "/usr/share/postgres/data" as the data directory for postgres. Again, note the username used here. It's best if the user that runs the postgres service is the same one that installed postgres/Cygwin to begin with. Otherwise, you need to get into lengthy manual permission juggling in the postgres data directories.
Excerpted Steps 5 and 6 are fine.
Swap Excerpted Steps 7 and 8. "initdb" won't actually run successfully without ipc-daemon running in the background first.
Excerpted Step 9 should be replaced with:
$ net start "Cygwin postgres"
I named my service a bit differently than in the original instructions, to better match the naming conventions of other Cygwin services.
Excerpted Step 10 should be replaced with:
$ psql template1
You don't have to provide the username in launching psql, as we're already logged-in as the user that created the databases. Again, this is a limitation of XP Home security.-- ********** This message is directed in confidence solely to the person(s) identified. This message may also be subject to privilege and all rights to that privilege are expressly claimed. If you have received this message in error, please notify the sender(s) and destroy the message immediately. ********** Kevin Wong, LL.B E-Mail: kevin-wong@usa.net
Re: Postgres Cygwin Install-as-Service on XP Pro/Home Mini
От:
Jason Tishler <jason@tishler.net>
Дата:
Kevin,
On Tue, Nov 05, 2002 at 12:09:24AM -0700, Kevin Wong wrote:
> BUT!!!! Swap Excerpted Steps 7 and 8. "initdb" won't actually run
> successfully without ipc-daemon running in the background first, in my
> experience.
Oops! Thanks for the above. I'm amazed at how long I had this and the
numbering screwed up!
> Windows XP Home:
>
> Because Windows XP Home has a number of differences from XP Pro,
> primarily in user accounts/management, you can't simply follow the
> standard NT/2000 install-as-service instructions. You have to do a
> few things differently.
Since I don't have access to XP Home, would you be willing to help me
get this right? If so, then I will add a XP Home section to the README.
Combining my limited Windows 9x experience and your XP Home Cygwin
PostgreSQL installation steps, it sounds like a "blending" of the basic
and NT services installation is appropriate. Does the following make
sense *and* work:
1. Install the cygipc ipc-daemon as a NT service:
$ ipc-daemon --install-as-service
2. Install postmaster as a NT service:
$ cygrunsrv --install postmaster --path /usr/bin/postmaster --args "-D /usr/share/postgresql/data -i" --dep ipc-daemon --termsig INT --shutdown
3. Create the PostgreSQL data directory:
$ mkdir /usr/share/postgresql/data
4. Start the cygipc ipc-daemon:
$ net start ipc-daemon # [1]
5. Initialize PostgreSQL
$ initdb -D /usr/share/postgresql/data
6. Start postmaster:
$ net start postmaster # [1]
7. Connect to PostgreSQL:
$ psql template1
[1] Cygwin's bin directory (e.g., C:\Cygwin\bin) must be added to the
Windows NT/2000/XP's system PATH and the machine rebooted for the
SCM to find cygwin1.dll.
Note that the ipc-daemon and postmaster services are installed to run
under whatever user account XP Home uses for services.
Thanks,
Jason
--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6