From b6e4043565313f0b6ca396180c66d6194ae6c010 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Mon, 31 Oct 2022 15:35:23 +0100 Subject: Add summary and hyphens --- docs/postgresql/index.rhtml | 64 +++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) (limited to 'docs/postgresql/index.rhtml') diff --git a/docs/postgresql/index.rhtml b/docs/postgresql/index.rhtml index d0b6f13..ebe778b 100644 --- a/docs/postgresql/index.rhtml +++ b/docs/postgresql/index.rhtml @@ -1,5 +1,14 @@

PostgreSQL

-

SQL Dump

+ +

Indice

+
    +
  1. SQL Dump
  2. +
  3. Ripristinare il dump
  4. +
  5. Usare pg_dumpall
  6. +
  7. Gestire grandi database
  8. +
+ +

SQL Dump

L'idea dietro a questo metodo di dump è quello di generare un file con comandi SQL che, quando eseguiti dal server, ricrea il database nello stesso stato come quando è stato eseguito il dump. PostgreSQL fornisce uno strumento che si chiama pg_dump che serve @@ -35,7 +44,7 @@ pg_dump dbname > dumpfile quelle operazioni necessitano di un lock esclusivo, come le più diffuse varianti di ALTER TABLE.

-

Ripristinare il dump

+

Ripristinare il dump

Il file creati con pg_dump sono pensati per essere letti dal programma psql. Il comando generico per ripristinare un dump è il seguente: @@ -79,7 +88,7 @@ psql dbname < dumpfile da pg_dump. Come risultato, quando si esegue il ripristino, se si sta usando un template1 personalizzato, si deve creare un database vuoto da template0, come nell'esempio precedente.

-

Usare pg_dumpall

+

Usare pg_dumpall

pg_dump effettua il dump di un singolo database alla volta, non effettua il dump delle informazioni su ruoli e tablespace. Per effettuare il dump di un intero cluster di database, esiste il programma pg_dumpall. L'utilizzo base del comando è il seguente:

@@ -90,53 +99,34 @@ psql dbname < dumpfile
psql -f dumpfile postgres
-

Gestire grandi database

-

Alcuni sistemi operativi hanno i limiti massimi sulla dimensione dei file che potrebbero causare +

Gestire grandi database

+

Alcuni sistemi operativi hanno i limiti massimi sulla dimensione dei file che potrebbero causare problemi creando grandi file con pg_dump. Fortunatamente, pg_dump può scrivere sullo standard output, così lo si può usare insieme agli strumenti standard di Unix per aggirare questo potenziale problema. Ci sono molteplici metodi:

-

Usare dei dump compressi:

-

Si può usare qualsiasi programma di compressione che si preferisce, ad esempio +

Usare dei dump compressi:

+

Si può usare qualsiasi programma di compressione che si preferisce, ad esempio con gzip

 pg_dump dbname | gzip > filename.gz
 
-

Si ripristina con:

+

Si ripristina con:

 gunzip -c filename.gz | psql dbname
 
-

Oppure

+

Oppure:

 cat filename.gz | gunzip | psql dbname
 
- -
-
-Use split. The split command allows you to split the output into smaller files that are acceptable in size to the underlying file system. For example, to make chunks of 1 megabyte:
-
+

Oltre alla creazione di un file gz, è possibile spezzare il dump in più file, usando + il comando split. Questo comando permette di spezzare l'output di pg_dump in file + più piccoli che possono essere salvati da file system che non sono in grado di gestire file di enormi + dimensioni. Per esempio, per creare porzioni di file da 1 megabyte, eseguire:

+
 pg_dump dbname | split -b 1m - filename
-
-Reload with:
-
+
+

Per poi ripristinarlo in questo modo:

+
 cat filename* | psql dbname
-
-Use pg_dump's custom dump format. If PostgreSQL was built on a system with the zlib compression library installed, the custom dump format will compress data as it writes it to the output file. This will produce dump file sizes similar to using gzip, but it has the added advantage that tables can be restored selectively. The following command dumps a database using the custom dump format:
-
-pg_dump -Fc dbname > filename
-
-A custom-format dump is not a script for psql, but instead must be restored with pg_restore, for example:
-
-pg_restore -d dbname filename
-
-See the pg_dump and pg_restore reference pages for details.
-
-For very large databases, you might need to combine split with one of the other two approaches.
-
-Use pg_dump's parallel dump feature. To speed up the dump of a large database, you can use pg_dump's parallel mode. This will dump multiple tables at the same time. You can control the degree of parallelism with the -j parameter. Parallel dumps are only supported for the "directory" archive format.
-
-pg_dump -j num -F d -f out.dir dbname
-
-You can use pg_restore -j to restore a dump in parallel. This will work for any archive of either the "custom" or the "directory" archive mode, whether or not it has been created with pg_dump -j.
-
-
\ No newline at end of file +
-- cgit v1.2.3