osm2pgsql creates the tables and indexes in the user default schema, i.e. the first one found in its search path, which is usually
public. By changing this setting, in PostgreSql, one can load the data to a custom schema. It is important to keep the
public schema in the path, as it is required for getting the
--Create the new user
CREATE USER osm_loader WITH ENCRYPTED PASSWORD '*****';
--create the schema
CREATE SCHEMA osm AUTHORIZATION osm_loader;
--Change the search_path.
ALTER ROLE osm_loader SET search_path TO osm, public;
and you can then launch the osm2pgsql tool with the new user
osm2pgsql.exe data.osm.pbf -U osm_loader [... other parameters as needed]
Alternatively, you could change the search path of the user you are currently using. Make sure to change it back once the data is loaded.