Migrare il database PostgreSQL usando le funzionalità di esportazione e importazioneMigrate your PostgreSQL database using export and import
Database di Azure per PostgreSQL-server singolo
database di Azure per PostgreSQL-server flessibile
È possibile usare pg_dump per estrarre un database PostgreSQL in un file di script e psql importare i dati nel database di destinazione da quel file.You can use pg_dump to extract a PostgreSQL database into a script file and psql to import the data into the target database from that file.
PrerequisitiPrerequisites
Per proseguire con questa guida, si richiedono:To step through this how-to guide, you need:
- Un server di Database di Azure per PostgreSQL con le regole del firewall per consentire l'accesso e il database sottostante.An Azure Database for PostgreSQL server with firewall rules to allow access and database under it.
- Utilità della riga di comando pg_dump installatapg_dump command-line utility installed
- Utilità della riga di comando psql installatapsql command-line utility installed
Seguire questi passaggi per esportare e importare il database PostgreSQL.Follow these steps to export and import your PostgreSQL database.
Creare un file di script usando pg_dump che contiene i dati da caricareCreate a script file using pg_dump that contains the data to be loaded
Per esportare un database PostgreSQL disponibile in locale o in una macchina virtuale in un file di script SQL, eseguire il comando seguente nell'ambiente esistente:To export your existing PostgreSQL database on-premises or in a VM to a sql script file, run the following command in your existing environment:
pg_dump –-host=<host> --username=<name> --dbname=<database name> --file=<database>.sql
Se, ad esempio, si dispone di un server locale e di un database denominato TestDB :For example, if you have a local server and a database called testdb in it:
pg_dump --host=localhost --username=masterlogin --dbname=testdb --file=testdb.sql
Importare i dati nel Database di Azure per PostgreSQL di destinazioneImport the data on target Azure Database for PostgreSQL
È possibile usare la riga di comando psql e il parametro- dbname, ovvero -d, per importare i dati nel server Database di Azure per PostgreSQL e caricare i dati dal file SQL.You can use the psql command line and the --dbname parameter (-d) to import the data into the Azure Database for PostgreSQL server and load data from the sql file.
psql --file=<database>.sql --host=<server name> --port=5432 --username=<user> --dbname=<target database name>
In questo esempio vengono usati l'utility PSQL e il file di script testdb.sql dal passaggio precedente per importare i dati nel database mypgsqldb disponibile nel server di destinazione mydemoserver.postgres.database.azure.com.This example uses psql utility and a script file named testdb.sql from previous step to import data into the database mypgsqldb on the target server mydemoserver.postgres.database.azure.com.
Per server singolo, utilizzare questo comandoFor Single Server, use this command
psql --file=testdb.sql --host=mydemoserver.database.windows.net --port=5432 --username=mylogin@mydemoserver --dbname=mypgsqldb
Per il server flessibile, utilizzare questo comandoFor Flexible Server, use this command
psql --file=testdb.sql --host=mydemoserver.database.windows.net --port=5432 --username=mylogin --dbname=mypgsqldb
Passaggi successiviNext steps
- Per eseguire la migrazione di un database PostgreSQL tramite dump e ripristino, vedere eseguire la migrazione del database PostgreSQL tramite dump e Restore.To migrate a PostgreSQL database using dump and restore, see Migrate your PostgreSQL database using dump and restore.
- Per altre informazioni sulla migrazione dei database in Database di Azure per PostgreSQL, vedere Database Migration Guide (Guida alla migrazione di database).For more information about migrating databases to Azure Database for PostgreSQL, see the Database Migration Guide.