0

I'm new to Postgresql and am going to install on A directory for my Application. After building a package including the Application and Postgresql, I should deliver it to other user(by Installer but Postresql is not embedded).

I was wondering if it is okay for me to just copy Postgresql to other directory without any consideration of registry or environment variables on Windows.

Does it work by copying the all of directories to other directory or server?

Sigularity
  • 917
  • 2
  • 12
  • 28
  • Possible duplicate of [Packaging database into application seamlessly for users](http://stackoverflow.com/questions/25269274/packaging-database-into-application-seamlessly-for-users) – Ken Y-N Oct 01 '15 at 00:51
  • I don't mean the embedded Postgresql into the Application. I just want to know how to copy Postgresql to other directory. Because User could choose a different installation directory so I need to copy the pre-installed Postgresql to other directory during installation. – Sigularity Oct 01 '15 at 01:18
  • 1
    So what if you copy it and see? – zerkms Oct 01 '15 at 01:21
  • Why do you want to copy the Postgresql directory if it is already installed? The DLLs, drivers, etc, should already be available, and as with most Windows programs, blindly copying the install directory rarely works. – Ken Y-N Oct 01 '15 at 01:28
  • Before delivering my application to users, I install Postgresql on local desktop. When user tries to install the desktop application with a installer, normally they are going to use other directory. So, in that case, the installer should copy the preInstalled Postgresql to the directory. This is the scenario. I don't want user to install Postgresql again. – Sigularity Oct 01 '15 at 02:14

1 Answers1

0

If you stop the running PostgreSQL service, and you preserve file permissions when copying/moving, and the destination is also a NTFS filesystem, it will work. But you'll have to adjust the service definition or create a new one to start from the new location; PostgreSQL won't know where the data directory is until you tell it.

However.

You should simply initdb PostgreSQL where it needs to be in the first place. There's no need to copy or move the data directory. Ask the user where they want it to be put and then put it there from the start.

I strongly recommend that you bundle PostgreSQL binaries in your installer rather than having the user run a PostgreSQL installer first. Then have your app initdb its own private PostgreSQL data directory for its use.

See Installation of postgresql with NSIS (it doesn't matter if you're not using NSIS, the principles are the same).

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • I agree with your approach about bundling PostgreSQL into the installer. I have one more question. Regarding a registered service, 'pg_ctl.exe' register ... command is enough? No need to create a service manually with 'sc' command? – Sigularity Oct 02 '15 at 07:27
  • @Sigularity Correct, `pg_ctl register` is a helper that sets up the service. You can create it manually with `sc` if you prefer to do it that way; the result will be the same. – Craig Ringer Oct 02 '15 at 08:12
  • Great. My scenario is that: Install my app and PostgreSQL local, then create several tables. Have InnoSetup installer to copy the original one to user-selected directory. Then, Installer will run pg_ctl register command blindly. No need to issue 'initdb' coz I need to keep the previous tables. I will try this whole one. Do you think it is correct? Your advice is very helpful. – Sigularity Oct 02 '15 at 08:22
  • @Sigularity You should `initdb` in the user specified location to make a private PostgreSQL instance for your app, then `pg_ctl register` and start the service. Then have your app create the tables in the new PostgreSQL data directory you created where the user asked. Run a script with `psql` or whatever to create the tables. There should be no need to install then copy. – Craig Ringer Oct 02 '15 at 08:25
  • I should go over 'initdb' more. Thanks a lot for your comment! – Sigularity Oct 02 '15 at 08:53