Create a database user and provide the user with READ access to all the resources which need to be migrated. Run the following commands in a psql
session:
-
Create a new user named
ybvoyager
.CREATE USER ybvoyager PASSWORD 'password';
-
Switch to the database that you want to migrate.
\c <database_name>
-
Grant the
USAGE
permission to theybvoyager
user on all schemas of the database.SELECT 'GRANT USAGE ON SCHEMA ' || schema_name || ' TO ybvoyager;' FROM information_schema.schemata; \gexec
The above
SELECT
statement generates a list ofGRANT USAGE
statements which are then executed bypsql
because of the\gexec
switch. The\gexec
switch works for PostgreSQL v9.6 and later. For older versions, you'll have to manually execute theGRANT USAGE ON SCHEMA schema_name TO ybvoyager
statement, for each schema in the source PostgreSQL database. -
Grant
SELECT
permission on all the tables and sequences.SELECT 'GRANT SELECT ON ALL TABLES IN SCHEMA ' || schema_name || ' TO ybvoyager;' FROM information_schema.schemata; \gexec SELECT 'GRANT SELECT ON ALL SEQUENCES IN SCHEMA ' || schema_name || ' TO ybvoyager;' FROM information_schema.schemata; \gexec
The
ybvoyager
user can now be used for migration.