All tags
postgresql
Narrow down
Other tips31
- Tip
\gexec\gexec runs the SQL that a psql query just generatedTakes every value a query returns and executes it as its own SQL statement.2 Dec 2026 - Tip
FROM pg_settingsPg_settings.pending_restart lists PostgreSQL changes that still need a restartShows which edited settings in the config file are not active yet because the server has to restart.2 Dec 2026 - Tip
FROM pg_hba_file_rulesPg_hba_file_rules shows PostgreSQL login rules and the line that is brokenLists the rules in pg_hba.conf as rows, with an error message for lines that cannot be parsed.2 Dec 2026 - Tip
LOAD 'auto_explain';Auto_explain writes the plan of slow PostgreSQL queries to the logA contrib module that logs the execution plan of any statement slower than a limit you set.2 Dec 2026 - Tip
CREATE EXTENSION pgstattuple;Pgstattuple_approx estimates PostgreSQL table bloat without reading the whole tableReports dead tuples and free space of a table, skipping pages that the visibility map marks clean.2 Dec 2026 - Tip
FROM pg_stat_user_indexesPg_stat_user_indexes idx_scan = 0 points at PostgreSQL indexes nobody usesLists indexes with zero scans since the statistics were last reset, so you can review them for removal.2 Dec 2026 - Tip
EXPLAIN (SETTINGS) SELECT * FROM my_table WHERE id = 42;EXPLAIN (SETTINGS) lists the planner settings that differ from the defaultsAdds a line to the plan with every planner-related setting that has a non-default value.2 Dec 2026 - Tip
appdb=# \errverbose\errverbose shows the full PostgreSQL error after it already happenedRepeats the last server error with its SQLSTATE code, details and source location.30 Nov 2026 - Tip
pg_dump -s -f prod-schema.sql -h db1.example.com appdbpg_dump -s dumps only the PostgreSQL schema so you can diff two serversWrites table, index and function definitions without any rows, ready to compare or keep in git.30 Nov 2026 - Tip
appdb=# \timing on\timing on in psql shows how long each PostgreSQL statement tookPrints the run time of every statement so you can compare a query before and after a change.30 Nov 2026 - Tip
CREATE INDEX CONCURRENTLY orders_customer_idx ON orders (customer_id);CREATE INDEX CONCURRENTLY adds a PostgreSQL index without blocking writesBuilds an index on a live table while inserts and updates keep running.30 Nov 2026 - Tip
\pset null '(null)'\pset null makes NULL visible in psql so it stops looking like an empty PostgreSQL stringPrints a marker for NULL values so you can tell them apart from empty text.30 Nov 2026 - Tip
ALTER ROLE report SET statement_timeout = '30s';ALTER ROLE … SET statement_timeout caps query time for one PostgreSQL userGives one login a maximum query time so its runaway queries stop on their own.30 Nov 2026 - Tip
CREATE TABLE readings (id int, sensor int, taken_at timestamptz, value numeric);Generate_series fills a PostgreSQL table with test rows in one INSERTCreates thousands of realistic test rows with one statement to try an index or a query.30 Nov 2026 - Tip
shared_preload_libraries = 'pg_stat_statements'Pg_stat_statements shows which PostgreSQL queries take the most time overallRanks normalized queries by their total run time so you tune the ones that matter.30 Nov 2026 - Tip
state, wait_event_type, left(query, 60) AS queryPg_blocking_pids shows which PostgreSQL session is blocking your queryLists waiting sessions together with the process IDs that hold the lock they need.30 Nov 2026 - Tip
pg_restore -L appdb.list -d appdb_new appdb.dumppg_restore -L with an edited list skips parts of a PostgreSQL dumpRestores a custom-format dump minus the items you commented out of its table of contents.30 Nov 2026 - Tip
SELECT pid, now() - query_start AS running, left(query, 60)Pg_cancel_backend stops a PostgreSQL query, pg_terminate_backend ends the sessionPicks the gentle or the hard way to stop a runaway query from another session.30 Nov 2026 - Tip
appdb=# \e\e in psql opens your last PostgreSQL query in an editorEdits a long query in your own editor and runs it when you save and quit.30 Nov 2026 - Tip
psql -E -d mydbpsql -E shows the SQL behind \d commands, and noexec only shows itPrints the SQL that psql sends for backslash commands like \dt.28 Nov 2026 - Tip
\gset\gset stores a one-row query result in psql variables you can reuseStores the single row of a query result in psql variables for later statements.28 Nov 2026 - Tip
\sf+ my_function\sf+ prints a PostgreSQL function with line numbers so you can find the failing lineShows the source of a PostgreSQL function with numbered lines, to match an error message.28 Nov 2026 - Tip
pg_restore --clean --if-exists -d appdb appdb.dumppg_restore --clean --if-exists overwrites a database without a wall of errorsDrops existing objects before a restore and skips the errors for objects that were never there.28 Nov 2026 - Tip
pg_restore -j 4 -d appdb appdb.dumppg_restore -j restores a large PostgreSQL dump with several parallel jobsRestores a PostgreSQL archive dump using several concurrent jobs so large restores finish sooner.28 Nov 2026 - Tip
psql -1 -v ON_ERROR_STOP=1 -d appdb -f migrate.sqlpsql -1 with ON_ERROR_STOP makes a SQL script all or nothingRuns a SQL script as one transaction and stops at the first error, rolling everything back.28 Nov 2026 - Tip
\copy (SELECT id, email FROM users WHERE active) TO 'users.csv' WITH (FORMAT csv, HEADER)Psql \copy (query) to csv exports a result as CSV on your own machineWrites a query result to a CSV file on your own computer, without server file permissions.28 Nov 2026 - Tip
psql -X -d appdb -f report.sqlpsql -X skips your ~/.psqlrc so a script behaves the same everywhereStarts psql without reading startup files, so scripts give the same output on every machine.28 Nov 2026 - Tip
SELECT DISTINCT ON (sensor_id) sensor_id, recorded_at, temperatureSELECT DISTINCT ON gives you the newest row per group in PostgreSQLReturns one row per group, such as the latest reading of each sensor, without a subquery.27 Nov 2026 - Tip
\set ON_ERROR_ROLLBACK interactive\set ON_ERROR_ROLLBACK interactive keeps a psql transaction alive after a typoKeeps an open psql transaction usable after one statement fails, instead of aborting all of it.27 Nov 2026 - Tip
postgres=# \conninfo\conninfo in psql shows which database, user and host you are onPrints the details of the current psql connection, so you know where a query is about to run.25 Nov 2026 - Tip
\x auto\x auto lets psql show wide rows one field per lineMakes psql print wide query results one field per line, only when they do not fit.19 Nov 2026
Storage7
- Tip
pg_dump -O -x -f mydb.sql mydbpg_dump -O -x makes a PostgreSQL dump that any user can restoreLeaves ownership and GRANT statements out of a plain SQL dump, so another user can load it.2 Dec 2026 - Tip
pg_restore -f - -t users appdb.dump | lesspg_restore -f turns a PostgreSQL custom-format dump into readable SQLConverts a binary pg_dump archive into a plain SQL script you can read, grep or edit.30 Nov 2026 - Tip
echo 'db1.example.com:5432:*:backup:change-me' >> ~/.pgpassA ~/.pgpass file lets psql and pg_dump log in to PostgreSQL without a promptStores PostgreSQL passwords per host and user in a private file that all client tools read.30 Nov 2026 - Tip
pg_dumpall --globals-only -f globals.sqlpg_dumpall --globals-only saves the PostgreSQL roles that pg_dump leaves outDumps only the roles and tablespaces of a PostgreSQL server, which per-database dumps do not contain.28 Nov 2026 - Tip
pg_dump -Fc --exclude-table-data='app_log*' -f appdb.dump appdbpg_dump --exclude-table-data keeps a big log table's structure but skips its rowsDumps a PostgreSQL database but leaves out the rows of chosen tables while keeping their definitions.28 Nov 2026 - Tip
pg_basebackup -D backup -Ft -z -Ppg_basebackup -Ft -z -P takes a physical backup of a whole PostgreSQL serverCopies the data files of a whole running PostgreSQL server into compressed tar files.28 Nov 2026 - Tip
pg_basebackup -h mydbserver -D /usr/local/pgsql/dataPg_verifybackup checks a pg_basebackup copy against its backup manifestVerifies a PostgreSQL base backup against its manifest for missing, extra or damaged files.28 Nov 2026
Nothing matches.