I have PostgreSQL 15 installed on a Windows Server 2019 Standard VM. I've installed pgSQL using the default configuration on the C:\ drive. I'm currently using the default data directory of C:...\data. I also have a D:\ drive that I would like to create pgSQL DBs on. I don't want to move the default ...\data directory but only want to create new DBs in the D:\PostgreSQLData directory, which is on the same VM. I didn't see any solution in my initial search on this site. If such solutions already exist here or elsewhere, please send me the link. Otherwise, what are the steps to do this?
Asked
Active
Viewed 1,388 times
1 Answers
1
I would recommend not to keep the data directory in C:\Program Files\PostgreSQL\13\data, because C:\Program Files is for program files, not for changing and growing application data. If I were you, I'd
stop the server
create
D:\dataand make sure that only administrators and the user that runs the PostgreSQL service has access to that directorymove everything in
C:\Program Files\PostgreSQL\13\datatoD:\dataexceptpostgresql.conf,pg_hba.confandpg_ident.confedit
postgresql.confand setdata_directorytoD:\datastart the server
If you don't want to do that, you'd have to create a tablespace:
CREATE TABLESPACE data LOCATION 'C:\data';
and create your new database there
CREATE DATABASE newdb TABLESPACE data;
Laurenz Albe
- 61,070
- 4
- 55
- 90