Dump database

Custom-format dump (fastest, supports parallel restore)

pg_dump -U myuser -d mydb -F c -f mydb.dump

tool
postgres29 commands
tags
postgres

More postgres commands

  • pg_restore -U myuser -d mydb -j 4 --clean mydb.dump

    Parallel restore with 4 workers, drop existing objects first

  • psql -U myuser -d mydb -c 'VACUUM (VERBOSE, ANALYZE) orders;'

    Reclaim dead tuples and update statistics for query planner

  • psql -U postgres -c "SELECT client_addr, state, sent_lsn, replay_lsn, (sent_lsn - replay_lsn) AS lag_bytes FROM pg_stat_replication;"

    Replication state and byte lag per replica

  • psql -U postgres -d mydb -c "SELECT pid, relation::regclass, mode, granted, left(query,60) FROM pg_locks l JOIN pg_stat_activity a USING(pid) WHERE relation IS NOT NULL ORDER BY granted;"

    Active locks with blocking/blocked status and query

  • SELECT pid, now()-query_start AS dur, state, query FROM pg_stat_activity WHERE state='active' AND now()-query_start > interval '5 min' ORDER BY dur DESC;

    List active queries running over 5 minutes, longest first

all 29 postgres commands