Подключиться к базе данных postgres
Интерактивная сессия psql к базе данных
psql -h localhost -U myuser -d mydb
more postgres
all 29 commands →
Список баз данных
psql -U postgres -c '\l+'
Таблицы в схеме
psql -U myuser -d mydb -c '\dt public.*'
EXPLAIN ANALYZE запроса
psql -U myuser -d mydb -c 'EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT * FROM orders WHERE status = $1;'
Медленные запросы
psql -U postgres -d mydb -c "SELECT round(total_exec_time::numeric,2) ms, calls, round((total_exec_time/calls)::numeric,2) avg_ms, query FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10;"
Активные запросы
psql -U postgres -c "SELECT pid, now()-query_start AS duration, state, left(query,80) FROM pg_stat_activity WHERE state <> 'idle' ORDER BY duration DESC;"