Could I use a copy of the database directory instead of using initdb? I have an offline Windows software that is installed locally on each user's computer. Each installation uses its own standalone PostgreSQL database. To create the database on each user's computer, the software uses the initdb command and then creates the tables and keys using normal SQL.

I want to avoid using the initdb command on each user's computer because sometimes this command fails (especially when the user uninstalls the Microsoft Visual C ++ 2010 x86 Redistributable).

I was thinking of embedding a copy of the initial database directory in the installer, so I did not have to use initdb. Would this work? Is there a better alternative?

Note: All users use the exact same version of PostgreSQL and the same database structure. However, they use different versions of Windows.
You can do so - a given initdb will produce a datadir compatible with builds of the same postgres.

But.

If initdb fails, the rest of postgres probably will too. So you won't really be solving anything. You should instead bundle the MSVC redist in your installer.

BTW, if you install PostgreSQL bundled in an app, please use a non-default port, do NOT use the default port 5432. Thanks!