Home > Software design >  How can I point the Postgres service to use a different DB directory?
How can I point the Postgres service to use a different DB directory?

Time:07-13

I'm using Ansible to install/upgrade PostgreSQL silently on Windows via

postgresql-12.x-x-windows-x64.exe --mode unattended --unattendedmodeui none

But this uses C:\Program Files\PostgreSQL\data\ as the service's data directory. How can I now point the service to an different and "existing" data directory? So I don't necessarily want to do an initdb -D I:\CurrentPGDataDir since it already exists? TIA

CodePudding user response:

Create the service with pg_ctl register:

pg_ctl register [-D datadir] [-N servicename] [-U username] [-P password] [-S a[uto] | d[emand] ] [-e source] [-W] [-t seconds] [-s] [-o options]

For details, see the documentation.

If you need to get rid of a service created automatically by the installation procedure, you can use pg_ctl unregister.

  • Related