pg_dump -U <user> -Fc -s <databaseName> > <output>
pg_dump -U <user> -Fc -s <databaseName> -f <output>
pg_dump -U <user> -Fc <databaseName> > <output>
pg_dump -U <user> -Fc <databaseName> -f <output>
pg_dumpall -U <user> -c -f <output>
psql <databaseName> < <dumpFile>
psql <databaseName> -f <dumpFile>
pg_dump -c -U <user> <databaseName> | psql -d <newDatabaseName> -U <user>
For example from version 11 to version 13
service postgresql stop
pg_dropcluster 13 main
pg_upgradecluster 11 main
service postgresql start
\copy <tableName> to 'myDump.dump'
\copy (select * from <tableName> where id = 'myId') to stdout
\copy <tableName> from 'myDump.dump'
- Toggle
pagerinpsql/pgcli
\pset pager
- Change
pager
\pset pager less
- Toggle expanded display
\x
- Delete all data in some tables
truncate table1, table2 cascade
- kill all connections easily
/etc/init.d/postgres restart
- Search for data created in the last X hours/minutes...
select * from <table> where created_at > now() - interval '2 days 2 hours 20 minutes'PostgreSQL offers some tools enabled via its configuration (/etc/postgresql/<versionNumber>/postgresql.conf)
log_lock_waits: Enabling this will instruct the Deadlock Detector to log whenever a statement exceedsdeadlock_timeout. There is no performance overhead enabling this, since the Deadlock Detector should be running anyway, and if it is, then it’s practically free.log_min_duration: This will log queries running for more than X msauto_explain: This is actually a number of configurations (auto_explain.log_min_duration,auto_explain.log_analyzeetc). They control when and howPostgreSQLwill automatically perform anEXPLAINon running queries. Those are useful as a precaution too, to make sure that poorly performing statements will leave traces & query plans for you to debug.log_statement: This is pretty useful. It can enable logging all / most / error statements etc. If you want to find out if something’s wrong with your database, it’s a common practice to set this toallfor some time, gather the output and analyze it with a tool like pgBadger. Logs can be displayed with the following command
# Logs are stored in "/var/log/postgresql/postgresql-<versionNumber>-main.log". For example:
sudo less +f /var/log/postgresql/postgresql-11-main.log
- description:
HypoPGis a PostgreSQL extension adding support for hypothetical indexes.