Packaging database into application seamlessly for users

后端 未结 2 654
囚心锁ツ
囚心锁ツ 2021-01-27 23:27

I want to create a desktop application that uses a relational database (such as postgres - let\'s say my best case scenario is to use postgres in this application).

I wa

相关标签:
2条回答
  • 2021-01-27 23:35

    Short version, you really can't, your best bet is to use SQLite or similar.

    Long version, well, if you really really want to, you can create multiple unattended installers for your database that targets each platform you want, embed it into your application and install it on the first run.

    Now that is just ugly and most users (myself included) would outright never use it.

    You can always mention that your software depends on X and Y and provide information about how to manually install the dependencies.

    0 讨论(0)
  • You're looking for an embedded database.

    This isn't an ideal job for PostgreSQL, but you can use it that way with a bit of care.

    Please don't bundle the installer and run it unattended. Users who later go to install PostgreSQL will be very confused when they see it's already on their computer but they don't know why, who installed it, or what the password is.

    Instead initdb a new datadir inside your app's %APPDATA% or (for multiuser shared) in %PROGRAMDATA%. Set a custom port (don't use the default 5432). Create a new service with pg_ctl register, running as NETWORKSERVICE, or just start/stop on demand with pg_ctl. That way you won't get in the way of any existing PostgreSQL installs or new ones and have a private PostgreSQL just for your app.

    Please offer users the option of instead supplying a connection string for an existing PostgreSQL though. It's a pain if apps insist on using their own embedded copy when you don't want them to.

    Often it's better to look at using SQLite, H2, Derby, Firebird, or one of the other embedded DBs, though.

    0 讨论(0)
提交回复
热议问题