16 Jan 2017
|
sql
Using pg_dump
and pg_restore
to save and reload a PostgreSQL database
Test settings:
- origin DB: PostgreSQL 9.5.5, saving
rcwd
took ~5-10 min for an output file of 1.6G
- destination DB: PostgreSQL 9.4.8, restoring
rcwd
took ~5-10 min for an output file of 1.6G
Saving the database
pg_dump -F tar -f $SAVE_FILE $DB_NAME
$SAVE_FILE
file to store the output
$DB_NAME
db to save
-F tar
to save in a tar file
Restoring the database
pg_restore $SAVE_FILE -d $DB_NAME --clean
$SAVE_FILE
file to store the output (file format is inferred from the extension
--clean
erases the database $DB_NAME before restoring the data (fresh start)
Useful links
- pg_dump http://docs.postgresql.fr/9.2/app-pgdump.html
- pg_restore http://docs.postgresql.fr/8.1/app-pgrestore.html
01 Dec 2016
|
vim
Vimdiff for newbies
vimdiff source1 source2
dp
diffput: puts changes under the cursor in the other file
do
diffget: (o => obtain) replace the change under the cursor
by the content of the other file
[c
jump to the previous diff
]c
jump to the next diff
01 Dec 2016
|
sql
Timing queries with MySQL
mysql> SET profiling = 1;
mysql> SELECT batch.rank, celebrity.name from batch, celebrity WHERE batch.celebrity_id = celebrity.id;
...
mysql> SELECT batch.rank, celebrity.name from batch INNER JOIN celebrity ON batch.celebrity_id = celebrity.id;
...
mysql> SHOW PROFILES;
+----------+------------+--------------------------------------------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+--------------------------------------------------------------------------------------------------------+
| 1 | 0.30346450 | SELECT batch.rank, celebrity.name from batch, celebrity WHERE batch.celebrity_id = celebrity.id |
| 2 | 0.17916075 | SELECT batch.rank, celebrity.name from batch INNER JOIN celebrity ON batch.celebrity_id = celebrity.id |
+----------+------------+--------------------------------------------------------------------------------------------------------+
2 rows in set, 1 warning (0.00 sec)
mysql> SET profiling = 0;