Location of PostgresSQL Data Files Windows 7

by | Jan 5, 2019

I recently lost my motherboard but still had a functional HDD. I wanted to re-install Postgres once I got my new machine but needed to continue to use the existing data files from my Postgres database. The data files were in a custom location that I could not recall.

Postgres Environment File

I found that Postgres stores the Posgres data file location of its database in a Postgres environment file called pg_env.bat (along with other useful information).

An example of the file contents is as follows:

REM The script sets environment variables helpful for PostgreSQL

@SET PATH="c:\Program Files\PostgreSQL\10\bin";%PATH%
@SET PGDATA=c:\foldername\PostgresData
@SET PGUSER=postgres
@SET PGLOCALEDIR=c:\Program Files\PostgreSQL\10\share\locale

Postgres Environment File Location

pg_env.bat is located in the Postgres installation directory.
eg c:\Program Files\PostgresSQL\10\pg_env.bat