Skip to content

Instantly share code, notes, and snippets.

View areguig's full-sized avatar
🎯
Focusing

Akli Reguig areguig

🎯
Focusing
View GitHub Profile
package io.github.areguig.demo;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
0x91CCC50ed7518630872fFc5dA6d3b060881991f6
@areguig
areguig / dead_rows_sequences_and_indexes.sql
Created March 23, 2017 14:23
Estimated dead rows, initiated sequences and indexes scans on tables.
select relname,(n_dead_tup+n_live_tup) as estimated_total_rows, n_dead_tup as estimated_dead_rows,
seq_scan,idx_scan
from pg_catalog.pg_stat_all_tables
where n_dead_tup > 0
-- and relname = '<TABLE_NAME>'
and schemaname='<SCHEMA_NAME>'
order by n_dead_tup desc;
@areguig
areguig / dead_rows_sequences_and_indexes.sql
Created March 23, 2017 14:23
Estimated dead rows, initiated sequences and indexes scans on tables.
select relname,(n_dead_tup+n_live_tup) as estimated_total_rows, n_dead_tup as estimated_dead_rows,
seq_scan,idx_scan
from pg_catalog.pg_stat_all_tables
where n_dead_tup > 0
-- and relname = '<TABLE_NAME>'
and schemaname='<SCHEMA_NAME>'
order by n_dead_tup desc;
@areguig
areguig / show_indexes_usage.sql
Last active March 23, 2017 14:09
show indexes usage
SELECT relname, 100 * idx_scan / (seq_scan + idx_scan) percent_of_times_index_used,
n_live_tup rows_in_table
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC;
@areguig
areguig / cancel_idle_query.sql
Created March 23, 2017 14:02
Cancel idle query
SELECT pg_terminate_backend(procpid);
@areguig
areguig / cancel_running_query.sql
Created March 23, 2017 13:59
Cancel running query
SELECT pg_cancel_backend(procpid);
@areguig
areguig / show_last_autovacuum.sql
Created March 23, 2017 13:57
show last autovacuum
select relname,last_vacuum, last_autovacuum, last_analyze, last_autoanalyze
from pg_stat_user_tables;
@areguig
areguig / running_queries.sql
Last active March 23, 2017 12:51
Show postgres running queries
SELECT now() - query_start as "runtime",client_addr, waiting, state, query
FROM pg_stat_activity
ORDER BY runtime DESC;