This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select pg_get_indexdef(format('%I.%I', schemaname, indexname)::regclass) | |
from pg_indexes | |
where schemaname not in ('pg_catalog', 'information_schema') | |
and schemaname not like 'pg_temp%'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION pgstattuple; | |
select | |
relname, | |
oid, | |
relowner, | |
(pgstattuple(oid)).dead_tuple_percent , | |
(pgstattuple(oid)).* | |
from |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION primary_id_sequences_from_all_tables() | |
RETURNS TABLE (table_name TEXT, column_name TEXT, data_type TEXT, max BIGINT, next BIGINT) AS $$ | |
DECLARE | |
rec RECORD; | |
BEGIN | |
FOR rec IN | |
SELECT tc.table_name, kcu.column_name, c.data_type | |
FROM information_schema.table_constraints AS tc | |
JOIN information_schema.key_column_usage AS kcu | |
ON tc.constraint_name = kcu.constraint_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
name, | |
setting | |
from | |
pg_settings | |
where | |
name in ('wal_level', 'track_commit_timestamp', 'max_worker_processes', 'max_replication_slots', 'max_wal_senders ', 'shared_preload_libraries'); | |
SELECT name, | |
setting, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT i.relname "Table Name",indexrelname "Index Name", | |
pg_size_pretty(pg_total_relation_size(relid)) As "Total Size", | |
pg_size_pretty(pg_indexes_size(relid)) as "Total Size of all Indexes", | |
pg_size_pretty(pg_relation_size(relid)) as "Table Size", | |
pg_size_pretty(pg_relation_size(indexrelid)) "Index Size", | |
reltuples::bigint "Estimated table row count" | |
FROM pg_stat_all_indexes i JOIN pg_class c ON i.relid=c.oid | |
WHERE i.relname='table_name'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Taken from https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#PostgreSQL | |
CREATE OR REPLACE FUNCTION lon2tile(lon DOUBLE PRECISION, zoom INTEGER) | |
RETURNS INTEGER AS | |
$BODY$ | |
SELECT FLOOR( (lon + 180) / 360 * (1 << zoom) )::INTEGER; | |
$BODY$ | |
LANGUAGE SQL IMMUTABLE; | |
CREATE OR REPLACE FUNCTION lat2tile(lat double precision, zoom integer) | |
RETURNS integer AS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", | |
"console_title_template": "{{.Folder}}{{if .Root}} :: root{{end}} :: {{.Shell}}", | |
"blocks": [ | |
{ | |
"alignment": "left", | |
"newline": true, | |
"segments": [ | |
{ | |
"foreground": "#ffbebc", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select count(a.id), sum(case when b.id is null then 0 else 1 end) as b_exists, | |
sum(case when b.id is null then 1 else 0 end) as b_does_not_exist | |
from a left join b on a.b_id = b.id; | |
-- Or even better | |
select count(a.id), | |
count(b.id) filter b.id is not null as b_exists, | |
count(b.id) filter b.id is null as b_does_not_exist | |
from a left join b on a.b_id = b.id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$userPath = $env:USERPROFILE | |
$pathExclusions = New-Object System.Collections.ArrayList | |
$processExclusions = New-Object System.Collections.ArrayList | |
$pathExclusions.Add('C:\Windows\Microsoft.NET') > $null | |
$pathExclusions.Add('C:\Windows\assembly') > $null | |
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio') > $null | |
$pathExclusions.Add('C:\ProgramData\Microsoft\VisualStudio\Packages') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\MSBuild') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio 14.0') > $null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- perform a "select pg_stat_reset();" when you want to reset counter statistics | |
with | |
all_tables as | |
( | |
SELECT * | |
FROM ( | |
SELECT 'all'::text as table_name, | |
sum( (coalesce(heap_blks_read,0) + coalesce(idx_blks_read,0) + coalesce(toast_blks_read,0) + coalesce(tidx_blks_read,0)) ) as from_disk, | |
sum( (coalesce(heap_blks_hit,0) + coalesce(idx_blks_hit,0) + coalesce(toast_blks_hit,0) + coalesce(tidx_blks_hit,0)) ) as from_cache | |
FROM pg_statio_all_tables --> change to pg_statio_USER_tables if you want to check only user tables (excluding postgres's own tables) |
NewerOlder