Running initdb while logged in as Administrator user (Windows)

Started by Daniel Futermanover 17 years ago6 messagesgeneral
Jump to latest
#1Daniel Futerman
daniel.futerman@gmail.com

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.

#2Simon Riggs
simon@2ndQuadrant.com
In reply to: Daniel Futerman (#1)
Re: Running initdb while logged in as Administrator user (Windows)

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

#3Magnus Hagander
magnus@hagander.net
In reply to: Daniel Futerman (#1)
Re: Running initdb while logged in as Administrator user (Windows)

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

#4Daniel Futerman
daniel.futerman@gmail.com
In reply to: Simon Riggs (#2)
Re: Running initdb while logged in as Administrator user (Windows)

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@2ndquadrant.com> wrote:

Show quoted text

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

#5Daniel Futerman
daniel.futerman@gmail.com
In reply to: Magnus Hagander (#3)
Re: Running initdb while logged in as Administrator user (Windows)

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.

#6Merlin Moncure
mmoncure@gmail.com
In reply to: Daniel Futerman (#5)
Re: Running initdb while logged in as Administrator user (Windows)

On Thu, Sep 18, 2008 at 3:47 PM, Daniel Futerman
<daniel.futerman@gmail.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