[comment]: # ({e26480a0-e26480a0})
# 3 Aggiornamento del database alle chiavi primarie

[comment]: # ({/e26480a0-e26480a0})

[comment]: # ({70ef924c-53564572})
### Panoramica

Questa sezione fornisce istruzioni per aggiornare manualmente le tabelle nelle installazioni esistenti in modo da usare chiavi primarie.

L'aggiornamento alle chiavi primarie ottimizza il modo in cui i dati vengono indicizzati e accessi, il che può velocizzare le query e risparmiare spazio.
Migliora inoltre la gestione dei dati e la sincronizzazione nelle configurazioni in cluster, aiutando la scalabilità e garantendo che il sistema rimanga affidabile anche in caso di guasto di alcuni server.

::: noteimportant
Le istruzioni fornite in questa pagina sono pensate per utenti esperti e potrebbero dover essere adattate alla configurazione specifica.
L'aggiornamento alle chiavi primarie può richiedere molto tempo e molte risorse.
Assicurarsi che sia disponibile spazio libero su disco sufficiente; a seconda delle dimensioni del database e dei dati memorizzati, il processo può richiedere fino a 2,5 volte lo spazio attualmente utilizzato dalle tabelle history.
:::

Le chiavi primarie vengono utilizzate per tutte le tabelle nelle nuove installazioni a partire da Zabbix 6.0.

Non esiste un aggiornamento automatico del database alle chiavi primarie; tuttavia, le installazioni esistenti possono essere aggiornate manualmente **dopo** aver aggiornato Zabbix server alla versione 6.0 o successiva.

::: noteimportant
A partire da Zabbix 7.0, l'aggiornamento delle tabelle alle chiavi primarie aggiorna anche le tabelle in modo che utilizzino tipi di dati a doppia precisione.
<br><br>
Se si utilizza Zabbix 7.0, le tabelle usano già la doppia precisione.
Tuttavia, le istruzioni di questa pagina possono comunque essere seguite per aggiornare le tabelle alle chiavi primarie senza influire sulle tabelle che già usano la doppia precisione.
<br><br>
Se si utilizza Zabbix 6.4 (o versioni precedenti), si consiglia di aggiornare prima le tabelle alla doppia precisione.
Per ulteriori informazioni, vedere [Aggiornamento ai valori numerici di intervallo esteso](/manual/appendix/install/db_float_range).
:::

Le istruzioni sono disponibili per:

* [MySQL](#mysql)
* [PostgreSQL](#postgresql)
* [TimescaleDB](#postgresql-timescaledb)
* [Oracle](#oracle)

[comment]: # ({/70ef924c-53564572})

[comment]: # ({82c37c9e-980f7329})
### Note importanti

Per eseguire l'aggiornamento del database:

1. Arrestare Zabbix server.

Si raccomanda vivamente di arrestare Zabbix server per tutta la durata dell'aggiornamento.
Tuttavia, se strettamente necessario, è possibile eseguire l'aggiornamento mentre il server è in esecuzione (solo per MySQL, MariaDB e PostgreSQL senza TimescaleDB).

2. Eseguire il backup del database.

Se si utilizza PostgreSQL o TimescaleDB, consultare i [problemi noti](/manual/installation/known_issues#database-restore-error-with-postgresqltimescaledb-after-upgrade-from-7.0.0-7.0.4) per il ripristino di un backup PostgreSQL o TimescaleDB creato in Zabbix 7.0.0-7.0.4.

3. Installare il pacchetto zabbix-sql-scripts più recente compatibile con la versione di Zabbix in uso (ad esempio, per RHEL: `dnf install zabbix-sql-scripts`).
4. Eseguire gli script per il proprio database.
5. Avviare Zabbix server.

::: notewarning
Eseguire gli script solo per il database del server. Il proxy non trarrà beneficio da questo aggiornamento.
:::

Se il database utilizza partizioni, contattare l'amministratore del DB o il Supporto Zabbix per assistenza.

I file CSV possono essere rimossi dopo un aggiornamento riuscito alle chiavi primarie.

Facoltativamente, il frontend di Zabbix può essere impostato in [modalità manutenzione](/manual/web_interface/maintenance_mode).

[comment]: # ({/82c37c9e-980f7329})

[comment]: # ({4f99bcf1-1551eb55})
### MySQL

L'esportazione e l'importazione devono essere eseguite in tmux/screen per garantire che la sessione non venga interrotta.

Vedi anche: [Note importanti](#important-notes)

[comment]: # ({/4f99bcf1-1551eb55})

[comment]: # ({b3eb6d02-dc89d749})
#### MySQL 8.0+ con mysqlsh

Questo metodo può essere usato con un server Zabbix in esecuzione, ma si consiglia di arrestare il server per la durata dell'aggiornamento.
MySQL Shell (*mysqlsh*) deve essere [installato](https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install-linux-quick.html) e in grado di connettersi al DB.

* Accedere alla console MySQL come root (consigliato) oppure come qualsiasi utente con privilegi FILE.

* Avviare MySQL con la variabile [local_infile](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_local_infile) abilitata.

* Rinominare le vecchie tabelle e creare le nuove eseguendo `history_upgrade_prepare.sql`.

```bash
mysql -uzabbix -p<password> zabbix < /usr/share/zabbix-sql-scripts/mysql/option-patches/history_upgrade_prepare.sql
```

* Esportare e importare i dati.

Connettersi tramite mysqlsh. Se si utilizza una connessione socket, potrebbe essere necessario specificare il percorso.

```bash
sudo mysqlsh -uroot -S /run/mysqld/mysqld.sock --no-password -Dzabbix
```

Passare alla modalità JavaScript usando:

```mysql
\js
```

Quindi eseguire il codice seguente (CSVPATH può essere modificato secondo necessità):

```javascript
CSVPATH="/var/lib/mysql-files";

util.exportTable("history_old", CSVPATH + "/history.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history.csv", {"dialect": "csv", "table": "history" });

util.exportTable("history_uint_old", CSVPATH + "/history_uint.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_uint.csv", {"dialect": "csv", "table": "history_uint" });

util.exportTable("history_str_old", CSVPATH + "/history_str.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_str.csv", {"dialect": "csv", "table": "history_str" });

util.exportTable("history_log_old", CSVPATH + "/history_log.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_log.csv", {"dialect": "csv", "table": "history_log" });

util.exportTable("history_text_old", CSVPATH + "/history_text.csv", { dialect: "csv" });
util.importTable(CSVPATH + "/history_text.csv", {"dialect": "csv", "table": "history_text" });
```

Se viene visualizzato il messaggio "JavaScript is not supported", l'installazione di MySQL Shell non include il supporto JS. In tal caso, installare il pacchetto ufficiale [MySQL Shell package](https://dev.mysql.com/downloads/shell/) di Oracle (oppure compilarlo dai sorgenti) in modo che la modalità JavaScript sia abilitata.

* Seguire le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

[comment]: # ({/b3eb6d02-dc89d749})

[comment]: # ({3466da92-b132f69b})
#### MariaDB/MySQL 8.0+ senza mysqlsh

Questo metodo di upgrade richiede più tempo e deve essere usato solo se un upgrade con *mysqlsh* non è possibile.

##### Upgrade delle tabelle

* Accedi alla console MySQL come root (consigliato) oppure come qualsiasi utente con privilegi FILE.

* Se esegui la migrazione con un server Zabbix in esecuzione, avvia MySQL con la variabile [local_infile](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_local_infile) abilitata.

* Rinomina le vecchie tabelle e crea le nuove eseguendo `history_upgrade_prepare.sql`:

```bash
mysql -uzabbix -p<password> zabbix < /usr/share/zabbix-sql-scripts/mysql/option-patches/history_upgrade_prepare.sql
```

##### Migrazione con server arrestato

`max_execution_time` (in MySQL) o `max_statement_time` (in MariaDB) devono essere disabilitati prima della migrazione dei dati per evitare timeout durante la migrazione.

Per MySQL:

```sql
SET @@max_execution_time=0;
```

Per MariaDB:

```sql
SET @@max_statement_time=0;
```

```sql
INSERT IGNORE INTO history SELECT * FROM history_old;
INSERT IGNORE INTO history_uint SELECT * FROM history_uint_old;
INSERT IGNORE INTO history_str SELECT * FROM history_str_old;
INSERT IGNORE INTO history_log SELECT * FROM history_log_old;
INSERT IGNORE INTO history_text SELECT * FROM history_text_old;
```

Segui le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

##### Migrazione con server in esecuzione

Verifica per quali percorsi l'importazione/esportazione è abilitata:

```sql
mysql> SELECT @@secure_file_priv;
+-----------------------+
| @@secure_file_priv    |
+-----------------------+
| /var/lib/mysql-files/ |
+-----------------------+
```

Se il valore di *secure_file_priv* è un percorso di directory, l'esportazione/importazione verrà eseguita per i file in quella directory. In questo caso, modifica di conseguenza i percorsi dei file nelle query oppure imposta il valore di *secure_file_priv* su una stringa vuota per il tempo dell'upgrade.

Se il valore di *secure_file_priv* è vuoto, l'esportazione/importazione può essere eseguita da qualsiasi posizione.

Se il valore di *secure_file_priv* è NULL, impostalo sul percorso che contiene i dati esportati delle tabelle ('/var/lib/mysql-files/' nell'esempio sopra).

Per ulteriori informazioni, consulta la [documentazione MySQL](https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_secure_file_priv) o la [documentazione MariaDB](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/server-system-variables#secure_file_priv).

`max_execution_time` (in MySQL) o `max_statement_time` (in MariaDB) devono essere disabilitati prima dell'esportazione dei dati per evitare timeout durante l'esportazione.

Per MySQL:

```sql
SET @@max_execution_time=0;
```

Per MariaDB:

```sql
SET @@max_statement_time=0;
```

```sql
SELECT * INTO OUTFILE '/var/lib/mysql-files/history.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_old;
LOAD DATA INFILE '/var/lib/mysql-files/history.csv' IGNORE INTO TABLE history FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';

SELECT * INTO OUTFILE '/var/lib/mysql-files/history_uint.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_uint_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_uint.csv' IGNORE INTO TABLE history_uint FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';

SELECT * INTO OUTFILE '/var/lib/mysql-files/history_str.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_str_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_str.csv' IGNORE INTO TABLE history_str FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';

SELECT * INTO OUTFILE '/var/lib/mysql-files/history_log.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_log_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_log.csv' IGNORE INTO TABLE history_log FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';

SELECT * INTO OUTFILE '/var/lib/mysql-files/history_text.csv' FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n' FROM history_text_old;
LOAD DATA INFILE '/var/lib/mysql-files/history_text.csv' IGNORE INTO TABLE history_text FIELDS TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\n';
```

Segui le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

[comment]: # ({/3466da92-b132f69b})

[comment]: # ({634df4cd-1139207b})
### PostgreSQL

L'esportazione e l'importazione devono essere eseguite in tmux/screen per garantire che la sessione non venga interrotta.
Per le installazioni con TimescaleDB, saltare questa sezione e procedere a [PostgreSQL + TimescaleDB](#postgresql-timescaledb).

Vedi anche: [Note importanti](#important-notes)

#### Aggiornamento delle tabelle

* Rinominare le tabelle usando `history_upgrade_prepare.sql`:

```bash
sudo -u zabbix psql zabbix < /usr/share/zabbix-sql-scripts/postgresql/option-patches/history_upgrade_prepare.sql
```

#### Migrazione con server arrestato

* Esportare la cronologia corrente, importarla nella tabella temporanea,
  quindi inserire i dati nelle nuove tabelle ignorando i duplicati:

```sql
INSERT INTO history SELECT * FROM history_old ON CONFLICT (itemid,clock,ns) DO NOTHING;

INSERT INTO history_uint SELECT * FROM history_uint_old ON CONFLICT (itemid,clock,ns) DO NOTHING;

INSERT INTO history_str SELECT * FROM history_str_old ON CONFLICT (itemid,clock,ns) DO NOTHING;

INSERT INTO history_log SELECT * FROM history_log_old ON CONFLICT (itemid,clock,ns) DO NOTHING;

INSERT INTO history_text SELECT * FROM history_text_old ON CONFLICT (itemid,clock,ns) DO NOTHING;
```

Vedi i suggerimenti per migliorare le prestazioni di INSERT: [PostgreSQL: Bulk Loading Huge Amounts of Data](https://www.cybertec-postgresql.com/en/postgresql-bulk-loading-huge-amounts-of-data), [Checkpoint Distance and Amount of WAL](https://www.cybertec-postgresql.com/en/checkpoint-distance-and-amount-of-wal).

* Seguire le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

[comment]: # ({/634df4cd-1139207b})

[comment]: # ({e951ec07-7e590ff3})
#### Migrazione con server in esecuzione

* Esporta la cronologia corrente, importala nella tabella temporanea, quindi inserisci i dati nelle nuove tabelle ignorando i duplicati:

```sql
\copy history_old TO '/tmp/history.csv' DELIMITER ',' CSV
CREATE TEMP TABLE temp_history (
    itemid                   bigint                                    NOT NULL,
    clock                    integer         DEFAULT '0'               NOT NULL,
    value                    DOUBLE PRECISION DEFAULT '0.0000'          NOT NULL,
    ns                       integer         DEFAULT '0'               NOT NULL
);
\copy temp_history FROM '/tmp/history.csv' DELIMITER ',' CSV
INSERT INTO history SELECT * FROM temp_history ON CONFLICT (itemid,clock,ns) DO NOTHING;

\copy history_uint_old TO '/tmp/history_uint.csv' DELIMITER ',' CSV
CREATE TEMP TABLE temp_history_uint (
    itemid                   bigint                                    NOT NULL,
    clock                    integer         DEFAULT '0'               NOT NULL,
    value                    numeric(20)     DEFAULT '0'               NOT NULL,
    ns                       integer         DEFAULT '0'               NOT NULL
);
\copy temp_history_uint FROM '/tmp/history_uint.csv' DELIMITER ',' CSV
INSERT INTO history_uint SELECT * FROM temp_history_uint ON CONFLICT (itemid,clock,ns) DO NOTHING;

\copy history_str_old TO '/tmp/history_str.csv' DELIMITER ',' CSV
CREATE TEMP TABLE temp_history_str (
    itemid                   bigint                                    NOT NULL,
    clock                    integer         DEFAULT '0'               NOT NULL,
    value                    varchar(255)    DEFAULT ''                NOT NULL,
    ns                       integer         DEFAULT '0'               NOT NULL
);
\copy temp_history_str FROM '/tmp/history_str.csv' DELIMITER ',' CSV
INSERT INTO history_str (itemid,clock,value,ns) SELECT * FROM temp_history_str ON CONFLICT (itemid,clock,ns) DO NOTHING;

\copy history_log_old TO '/tmp/history_log.csv' DELIMITER ',' CSV
CREATE TEMP TABLE temp_history_log (
    itemid                   bigint                                    NOT NULL,
    clock                    integer         DEFAULT '0'               NOT NULL,
    timestamp                integer         DEFAULT '0'               NOT NULL,
    source                   varchar(64)     DEFAULT ''                NOT NULL,
    severity                 integer         DEFAULT '0'               NOT NULL,
    value                    text            DEFAULT ''                NOT NULL,
    logeventid               integer         DEFAULT '0'               NOT NULL,
    ns                       integer         DEFAULT '0'               NOT NULL
);
\copy temp_history_log FROM '/tmp/history_log.csv' DELIMITER ',' CSV
INSERT INTO history_log SELECT * FROM temp_history_log ON CONFLICT (itemid,clock,ns) DO NOTHING;

\copy history_text_old TO '/tmp/history_text.csv' DELIMITER ',' CSV
CREATE TEMP TABLE temp_history_text (
    itemid                   bigint                                    NOT NULL,
    clock                    integer         DEFAULT '0'               NOT NULL,
    value                    text            DEFAULT ''                NOT NULL,
    ns                       integer         DEFAULT '0'               NOT NULL
);
\copy temp_history_text FROM '/tmp/history_text.csv' DELIMITER ',' CSV
INSERT INTO history_text SELECT * FROM temp_history_text ON CONFLICT (itemid,clock,ns) DO NOTHING;
```

* Segui le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

[comment]: # ({/e951ec07-7e590ff3})

[comment]: # ({f968af25-589d2f09})
### PostgreSQL + TimescaleDB

L'esportazione e l'importazione devono essere eseguite in tmux/screen per garantire che la sessione non venga interrotta.
Zabbix server deve essere arrestato durante l'aggiornamento.

Vedi anche: [Note importanti](#important-notes)

* Rinominare le tabelle usando `history_upgrade_prepare.sql`.
  * Se la compressione è abilitata (nell'installazione predefinita), eseguire lo script da `/usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression`:
    ```bash
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression/history_upgrade_prepare.sql | sudo -u zabbix psql zabbix
    ```
  * Se la compressione è disabilitata, eseguire lo script da `/usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression`:
    ```bash
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression/history_upgrade_prepare.sql | sudo -u zabbix psql zabbix
    ```

* Eseguire gli script di migrazione delle hypertable di TimescaleDB in base alle impostazioni di compressione:
  * Se la compressione è abilitata (nell'installazione predefinita), eseguire gli script da `/usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression`:
    ```bash
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression/history_upgrade.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression/history_upgrade_uint.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression/history_upgrade_log.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression/history_upgrade_str.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression/history_upgrade_text.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/with-compression/trends_upgrade.sql | sudo -u zabbix psql zabbix
    ```
  * Se la compressione è disabilitata, eseguire gli script da `/usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression`:
    ```bash
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression/history_upgrade.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression/history_upgrade_uint.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression/history_upgrade_log.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression/history_upgrade_str.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression/history_upgrade_text.sql | sudo -u zabbix psql zabbix
    cat /usr/share/zabbix-sql-scripts/postgresql/timescaledb/option-patches/without-compression/trends_upgrade.sql | sudo -u zabbix psql zabbix
    ```

Vedi anche: [Suggerimenti](https://www.tigerdata.com/blog/13-tips-to-improve-postgresql-insert-performance) per migliorare le prestazioni di INSERT.

* Seguire le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

[comment]: # ({/f968af25-589d2f09})

[comment]: # ({5bbab9b5-4b428c7c})
### Oracle

::: noteimportant
Il supporto per Oracle DB è deprecato a partire da Zabbix 7.0.
:::

L'esportazione e l'importazione devono essere eseguite in tmux/screen per garantire che la sessione non venga interrotta.
Zabbix server deve essere arrestato durante l'aggiornamento.

Vedi anche: [Note importanti](#important-notes)

#### Aggiornamento delle tabelle

* Installare Oracle Data Pump (disponibile nel pacchetto [Instant Client Tools](https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html)). 

Consultare la [documentazione](https://docs.oracle.com/en/database/oracle/oracle-database/19/sutil/oracle-data-pump-performance-tips.html) di Oracle Data Pump per suggerimenti sulle prestazioni.

* Rinominare le tabelle usando `history_upgrade_prepare.sql`.

```bash
cd /path/to/zabbix-sources/database/oracle/option-patches
sqlplus zabbix/password@oracle_host/service
sqlplus> @history_upgrade_prepare.sql
```

[comment]: # ({/5bbab9b5-4b428c7c})

[comment]: # ({dfc047ec-0dd33561})
#### Migrazione batch delle tabelle history

* Preparare le directory per Data Pump.

Data Pump deve avere i permessi di lettura e scrittura su queste directory.

Esempio:

```bash
mkdir -pv /export/history
chown -R oracle:oracle /export
```

* Creare un oggetto directory e concedere i permessi di lettura e scrittura su questo oggetto all'utente usato per l'autenticazione di Zabbix ('zabbix' nell'esempio seguente). Con il ruolo *sysdba*, eseguire:

```sql
create directory history as '/export/history';
grant read,write on directory history to zabbix;
```

* Esportare le tabelle. Sostituire N con il numero desiderato di thread.

```bash
expdp zabbix/password@oracle_host/service \
    DIRECTORY=history \
    TABLES=history_old,history_uint_old,history_str_old,history_log_old,history_text_old \
    PARALLEL=N
```

* Importare le tabelle. Sostituire N con il numero desiderato di thread.

```bash
impdp zabbix/password@oracle_host/service \
    DIRECTORY=history \
    TABLES=history_uint_old \
 REMAP_TABLE=history_old:history,history_uint_old:history_uint,history_str_old:history_str,history_log_old:history_log,history_text_old:history_text \
    data_options=SKIP_CONSTRAINT_ERRORS table_exists_action=APPEND  PARALLEL=N CONTENT=data_only
```

* Seguire le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

[comment]: # ({/dfc047ec-0dd33561})

[comment]: # ({51b383a5-f0426f06})
#### Migrazione individuale delle tabelle history

* Preparare le directory per Data Pump per ciascuna tabella history.
Data Pump deve avere i permessi di lettura e scrittura su queste directory.

Esempio:

```bash
mkdir -pv /export/history /export/history_uint /export/history_str /export/history_log /export/history_text
chown -R oracle:oracle /export
```

* Creare un oggetto directory e concedere i permessi di lettura e scrittura su questo oggetto all'utente usato per l'autenticazione di Zabbix ('zabbix' nell'esempio seguente). Con il ruolo *sysdba*, eseguire:

```sql
create directory history as '/export/history';
grant read,write on directory history to zabbix;

create directory history_uint as '/export/history_uint';
grant read,write on directory history_uint to zabbix;

create directory history_str as '/export/history_str';
grant read,write on directory history_str to zabbix;

create directory history_log as '/export/history_log';
grant read,write on directory history_log to zabbix;

create directory history_text as '/export/history_text';
grant read,write on directory history_text to zabbix;
```

* Esportare e importare ciascuna tabella. Sostituire N con il numero desiderato di thread.

```bash
expdp zabbix/password@oracle_host:1521/xe DIRECTORY=history TABLES=history_old PARALLEL=N

impdp zabbix/password@oracle_host:1521/xe DIRECTORY=history TABLES=history_old REMAP_TABLE=history_old:history data_options=SKIP_CONSTRAINT_ERRORS table_exists_action=APPEND PARALLEL=N CONTENT=data_only

expdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_uint TABLES=history_uint_old PARALLEL=N

impdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_uint TABLES=history_uint_old REMAP_TABLE=history_uint_old:history_uint data_options=SKIP_CONSTRAINT_ERRORS table_exists_action=APPEND PARALLEL=N CONTENT=data_only

expdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_str TABLES=history_str_old PARALLEL=N

impdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_str TABLES=history_str_old REMAP_TABLE=history_str_old:history_str data_options=SKIP_CONSTRAINT_ERRORS table_exists_action=APPEND PARALLEL=N CONTENT=data_only

expdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_log TABLES=history_log_old PARALLEL=N

impdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_log TABLES=history_log_old REMAP_TABLE=history_log_old:history_log data_options=SKIP_CONSTRAINT_ERRORS table_exists_action=APPEND PARALLEL=N CONTENT=data_only

expdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_text TABLES=history_text_old PARALLEL=N

impdp zabbix/password@oracle_host:1521/xe DIRECTORY=history_text TABLES=history_text_old REMAP_TABLE=history_text_old:history_text data_options=SKIP_CONSTRAINT_ERRORS table_exists_action=APPEND PARALLEL=N CONTENT=data_only
```

* Seguire le [istruzioni post-migrazione](#postmigration) per eliminare le vecchie tabelle.

[comment]: # ({/51b383a5-f0426f06})

[comment]: # ({e73536ae-b041e427})
### Post-migrazione

Per tutti i database, una volta completata la migrazione, procedere come segue:

* Verificare che tutto funzioni come previsto.

* Eliminare le vecchie tabelle:

```sql
DROP TABLE history_old;
DROP TABLE history_uint_old;
DROP TABLE history_str_old;
DROP TABLE history_log_old;
DROP TABLE history_text_old;
```

* Per TimescaleDB, eliminare anche la seguente vecchia tabella:

```sql
DROP TABLE trends_old;
```

[comment]: # ({/e73536ae-b041e427})

[comment]: # ({16ed11f0-8ee7d9aa})
#### Vedi anche

-   [Preparazione della tabella auditlog per il partizionamento](/manual/appendix/install/auditlog_primary_keys)

[comment]: # ({/16ed11f0-8ee7d9aa})
