Re: Running initdb while logged in as Administrator user (Windows)

Lists: pgsql-general
From: "Daniel Futerman" <daniel(dot)futerman(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Running initdb while logged in as Administrator user (Windows)
Date: 2008-09-18 17:29:27
Message-ID: 6ca02fc80809181029y2a2a4f9w43d02e57e8b755ba@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I'm trying to develop an automated PostgreSQL installer for Windows that
uses a silent install of PostgreSQL and batch scripts to initialise the
database cluster (i.e. run initdb) and start/stop the db server. The install
shouldn't install as a service, so initdb needs to be run manually.

The problem I'm having is that initdb cannot be run as an Administrator
user, so I wrote a script that creates a new limited Windows user and I now
want to run initdb using this user, but while still logged in as the
Administrator user.
I've looked at using the RUNAS comand, but the user password has to be
inserted manually when using this. I've also tried to pipe in the password
using echo *** | RUNAS... where *** is the password, but this doesn't seem
to work.

I know there are some apps out there that function as alternatives to RUNAS
but some of them require licences, and I'm looking for a distributable
solution.

How does the PostgreSQL installer work around this when a new limited user
can be specified when installing as a service?

Thanks,
Daniel.


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Daniel Futerman <daniel(dot)futerman(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Running initdb while logged in as Administrator user (Windows)
Date: 2008-09-18 18:18:52
Message-ID: 1221761932.3913.2471.camel@ebony.2ndQuadrant
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


On Thu, 2008-09-18 at 19:29 +0200, Daniel Futerman wrote:

> silent install of PostgreSQL

Please shout about it, don't hide it. And look at stackbuilder.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Daniel Futerman <daniel(dot)futerman(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Running initdb while logged in as Administrator user (Windows)
Date: 2008-09-18 19:35:29
Message-ID: 48D2AD81.8060308@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Daniel Futerman wrote:
> I'm trying to develop an automated PostgreSQL installer for Windows that
> uses a silent install of PostgreSQL and batch scripts to initialise the
> database cluster (i.e. run initdb) and start/stop the db server. The
> install shouldn't install as a service, so initdb needs to be run manually.
>
> The problem I'm having is that initdb cannot be run as an Administrator
> user, so I wrote a script that creates a new limited Windows user and I
> now want to run initdb using this user, but while still logged in as the
> Administrator user.

Actually, in 8.3 (at least, I can't remember if it was in 8.2 as well),
you *can* run it as admin in a lot of cases. It will drop privileges
though, so it can't use the admin permissions.

That said, using a separate account is still best practice.

> I've looked at using the RUNAS comand, but the user password has to be
> inserted manually when using this. I've also tried to pipe in the
> password using echo *** | RUNAS... where *** is the password, but this
> doesn't seem to work.
>
> I know there are some apps out there that function as alternatives to
> RUNAS but some of them require licences, and I'm looking for a
> distributable solution.

Look at psexec from Microsoft (former sysinternals).
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

You'll have to verify what the license says, but given that it's free
and comes from the guys that make Windows, it seems reasonable that it
should be doable.

> How does the PostgreSQL installer work around this when a new limited
> user can be specified when installing as a service?

The installer uses direct Win32 API functions to launch the process as a
different user.

//Magnus


From: "Daniel Futerman" <daniel(dot)futerman(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Running initdb while logged in as Administrator user (Windows)
Date: 2008-09-18 19:39:06
Message-ID: 6ca02fc80809181239i23ea59e0sa2cd4a7c138438b2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Thanks for the suggestion.

Maybe i should rephrase my question :
How does the Postgres (8.3) Installer manage to run initdb (when the
installation is not installed as a service).
When installing Postgres from the command line (the 'silent' install),
initdb can only be run if installing as a service, but I don't require the
service, so have to run initdb after the installation, but cannot do this
with Admistrative privileges.

Does the installer temporarily revoke these privileges in order to run
initdb, and if so, how is this done?

On Thu, Sep 18, 2008 at 8:18 PM, Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:

>
> On Thu, 2008-09-18 at 19:29 +0200, Daniel Futerman wrote:
>
> > silent install of PostgreSQL
>
> Please shout about it, don't hide it. And look at stackbuilder.
>
> --
> Simon Riggs www.2ndQuadrant.com
> PostgreSQL Training, Services and Support
>
>


From: "Daniel Futerman" <daniel(dot)futerman(at)gmail(dot)com>
To: "Magnus Hagander" <magnus(at)hagander(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Running initdb while logged in as Administrator user (Windows)
Date: 2008-09-18 19:47:21
Message-ID: 6ca02fc80809181247v360bd200pcb2f1d5d72cbad26@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

> Look at psexec from Microsoft (former sysinternals).
> http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

> You'll have to verify what the license says, but given that it's free
> and comes from the guys that make Windows, it seems reasonable that it
> should be doable.

This looks like it does exactly what I need :)
Thanks for the tip :)
Will look into the licence.

Daniel.


From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Daniel Futerman" <daniel(dot)futerman(at)gmail(dot)com>
Cc: "Magnus Hagander" <magnus(at)hagander(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Running initdb while logged in as Administrator user (Windows)
Date: 2008-09-19 01:13:17
Message-ID: b42b73150809181813q2e7e1d51m409ccc26948b83a0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Sep 18, 2008 at 3:47 PM, Daniel Futerman
<daniel(dot)futerman(at)gmail(dot)com> wrote:
>> Look at psexec from Microsoft (former sysinternals).
>> http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
>
>> You'll have to verify what the license says, but given that it's free
>> and comes from the guys that make Windows, it seems reasonable that it
>> should be doable.
>
> This looks like it does exactly what I need :)
> Thanks for the tip :)
> Will look into the licence.

back in my windows days, i pulled the same trick with 'sanur'

http://www.commandline.co.uk/sanur/

merlin