PostgreSQL Migration – Migrating Postgres Server from Windows to Linux

datafilepostgresqlreplication

Simple question: I want to migrate all of a Postgres server's data, schema, roles, everything from Windows to Linux.

Can I just copy the contents of the %PGDATA% directory in Windows to which the server points to Linux and start the server there pointing PGDATA argument/variable to that directory? In other words, are the data files platform independent to make porting from one OS to another a matter of copying?

I also have developed a script for cloning PG databases, schema+data but, for a variety of reasons, I would prefer to just put the data files on a USB drive and be done with it.

Best Answer

No, you cannot do that. The files in the data directory are not compatible across operating systems (or different architectures).

You will need to use pg_dump and pg_restore