| At line 1 added 49 lines |
| !!INSTALLAZIONE |
|
| Installare i pacchetti postgresql postgresql-client postgresql-contrib |
|
|
| !!TUNING |
| Per un tuning di base di postgres si può utilizzare questa utility: [pg-tune|http://pgfoundry.org/projects/pgtune/] |
|
| Per una macchina con circa 4GB una configurazione "decente" di postgres potrebbe essere questa: |
|
| %%prettify |
| {{{ |
| maintenance_work_mem = 288MB # pgtune wizard 2010-02-24 |
| checkpoint_completion_target = 0.7 # pgtune wizard 2010-02-24 |
| effective_cache_size = 3584MB # pgtune wizard 2010-02-24 |
| work_mem = 24MB # pgtune wizard 2010-02-24 |
| wal_buffers = 4MB # pgtune wizard 2010-02-24 |
| checkpoint_segments = 8 # pgtune wizard 2010-02-24 |
| shared_buffers = 960MB # pgtune wizard 2010-02-24 |
| max_connections = 200 # pgtune wizard 2010-02-24 |
| }}} |
| /% |
|
|
| Se si aumentano le connessioni e lo shared_buffers di postgres è possibile/probabile che serva aumentare anche la shared memory di linux questo è possibile attraverso questi comandi: |
| %%prettify |
| {{{ |
| cp /etc/sysctl.conf /etc/sysctl.conf-orig |
| vi /etc/sysctl.conf |
| }}} |
| /% |
|
| Aggiungere la riga con il valore appropriato: |
|
| %%prettify |
| {{{ |
| kernel.shmmax = 104857600 |
| }}} |
| /% |
|
| Salvare il file e far ricaricare i parametri al kernel con: |
|
| %%prettify |
| {{{ |
| sysctl -p |
| }}} |
| /% |
|
|
| At line 39 changed one line |
| {{{Installare i pacchetti postgresql postgresql-client postgresql-contrib |
| {{{ |
| At line 105 changed one line |
| pg_dump -c --table db2prod.rub -U dbuser -Fc dbname > dbname.dump |
| //singola tabella |
| pg_dump -c -U DBUSER DBNAME --table SCHEMA.TABLE -Fc > dbtable.dump |
|
| //intero db di uno schema |
| pg_dump -c -U DBUSER DBNAME --schema=SCHEMA -Fc > dbschema.dump |
|
| //intero db (tutti gli schemi) |
| pg_dump -c -U DBUSER DBNAME -Fc > dbname.dump |
| At line 111 changed one line |
| L'opzione -F serve per il formato output del file (c custom, p plain, t tar).\\ |
| L'opzione -F serve per il formato output del file (c custom, t tar).\\ |
| At line 171 added 5 lines |
| Il dump senza -F crea il salvataggio in text plain. |
|
| NB Per il restore del db da plainText utilizzare psql non pg_restore che funziona solo per formati custom o tar. |
|
|
| At line 177 added 3 lines |
|
| ''__Solo per formati custom o tar (opzione -Fc o -Ft sul dump)__''\\ |
|
| At line 118 changed one line |
| pg_restore -c -v -U dbuser -Fc -d dbname dbname.dump |
| //restore singola tabella |
| pg_restore -c -U DBUSER -d DBNAME -t TABLE -v -Fc db.dump |
| ATTENZIONE: sulla singola tabella sembra che non ricrei gli indici (e quindi nemmeno le primary key) |
| //restore singolo schema |
| pg_restore -c -U DBUSER -d DBNAME --schema=SCHEMA -v -Fc db.dump |
| //restore db completo |
| pg_restore -c -U DBUSER -d DBNAME -Fc db.dump |
| At line 120 changed one line |
| L'opzione -c indica a pg_restore di eliminare le tabelle.\\ |
| L'opzione -c indica a pg_restore di eliminare le tabelle (drop) e ricrearla.\\ |
| At line 124 changed one line |
| L'opzione -F serve per il formato input del file (c custom, p plain, t tar).\\ |
| L'opzione -F serve per il formato input del file (c custom, t tar).\\ |
| At line 128 changed one line |
| !!Import di dati |
| L'opzione -v = verbose.\\ |
|
| L'opzione --data-only è per importare i soli dati e non ricrea table.\\ |
|
| ''__Caso Formato text plain :__'' |
|
| At line 205 added 5 lines |
| {{{ psql -U DBUSER DBNAME -f dbname.dump |
| }}} |
|
| !!Import/export di dati |
| %%prettify |
| At line 131 changed one line |
| copy db2prod.deslun from '/var/lib/postgresql/deslun.txt' using delimiters ',' CSV; |
| export da pslq |
| \f ',' |
| \a |
| \t |
| \o outputfile.csv |
| select ..... (your sql select statement) |
| \o |
|
| import da psql |
| copy SCHEMA.TABLE from 'TABLE.vsc' using delimiters ',' CSV; |
|
| se in fase di import (copy) da comando di linea (psql) ottieni un errore tipo |
| ERROR: must be superuser to COPY to or from a file |
|
| usare da linea di comando linux |
| cat TUOFILE.csv | psql -U DBUSER -d DBNAME -c "copy SCHEMA.TABLE from stdin delimiter ',' CSV"; |